mediawiki-extensions-Visual.../bin/buildi18n-php.php
Roan Kattouw 789d187ce5 Add JSON->PHP conversion script for i18n
Apparently the .i18n.php shim is causing problems in both production
and beta labs, so for now we'll just generate the .i18n.php file
from the JSON files.

The first half of the conversion script is identical to the shim.

Change-Id: Id606584197d7efcff6fff29ea22cd35dd744b55e
2013-12-12 13:48:05 -08:00

46 lines
1.3 KiB
PHP

<?php
$messages = array();
array_map( function ( $dir ) use ( &$messages ) {
$files = glob( __DIR__ . "/../$dir/*.json" );
foreach ( $files as $file ) {
$langcode = substr( basename( $file ), 0, -5 );
$data = json_decode( file_get_contents( $file ), /* $assoc = */ true );
unset( $data['@metadata'] );
$messages[$langcode] = isset( $messages[$langcode] ) ?
array_merge( $messages[$langcode], $data ) :
$data;
}
}, array(
'modules/oojs-ui/i18n',
'modules/ve/i18n',
'modules/ve-mw/i18n',
'modules/ve-wmf/i18n'
) );
$output = <<<END
<?php
/**
* DO NOT EDIT THIS FILE
*
* This file is GENERATED from the JSON blobs in the i18n directories, where the actual i18n
* messages live.
*
* DO NOT EDIT THIS FILE
*
* Instead, make your changes in modules/.../i18n/en.json and qqq.json, then run
* php bin/buildi18n-php.php to rebuild this file.
*
* NO SERIOUSLY, DO NOT DIRECTLY EDIT THIS FILE, EVER
* @file
*/
\$messages = array();
END;
$firstcodes = array( 'en', 'qqq' );
$langcodes = array_merge( $firstcodes, array_diff( array_keys( $messages ), $firstcodes ) );
foreach ( $langcodes as $langcode ) {
$output .= "\n\$messages['$langcode'] = " . var_export( $messages[$langcode], true ) . ";\n";
}
file_put_contents( __DIR__ . '/../VisualEditor.i18n.php', $output );