Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/102171


Change subject: [WIP] First stab at a script to convert PHP i18n to JSON
......................................................................

[WIP] First stab at a script to convert PHP i18n to JSON

Still needs to preserve authorship data.

Change-Id: I769d5a106bf6214127cee2056cd64c18ca4182c6
---
A maintenance/generateJSONi18n.php
1 file changed, 61 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/71/102171/1

diff --git a/maintenance/generateJSONi18n.php b/maintenance/generateJSONi18n.php
new file mode 100644
index 0000000..9b675b6
--- /dev/null
+++ b/maintenance/generateJSONi18n.php
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * Convert a PHP messages file to a set of JSON messages files.
+ *
+ * Usage:
+ *    php generateJSONi18n.php --phpfile=ExtensionName.i18n.php --jsondir=json
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ */
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Maintenance script to rebuild the localisation cache.
+ *
+ * @ingroup Maintenance
+ */
+class GenerateJSONI18N extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Build JSON messages files from a PHP 
messages file";
+               $this->addOption( 'phpfile', 'PHP file defining a $messages 
array', true, true );
+               $this->addOption( 'jsondir', 'Directory to write JSON files 
to', true, true );
+       }
+
+       public function execute() {
+               $phpfile = $this->getOption( 'phpfile' );
+               $jsondir = $this->getOption( 'jsondir' );
+               include $phpfile;
+               foreach ( $messages as $langcode => $langmsgs ) {
+                       // TODO authorship
+                       $jsonfile = "$jsondir/$langcode.json";
+                       file_put_contents(
+                               $jsonfile,
+                               json_encode( $langmsgs, JSON_PRETTY_PRINT | 
JSON_UNESCAPED_UNICODE )
+                       );
+                       $this->output( "$jsonfile\n" );
+               }
+               $this->output( "All done.\n" );
+       }
+}
+
+$maintClass = "GenerateJSONI18N";
+require_once RUN_MAINTENANCE_IF_MAIN;

-- 
To view, visit https://gerrit.wikimedia.org/r/102171
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I769d5a106bf6214127cee2056cd64c18ca4182c6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to