55 $phpfile = $this->getArg( 0 );
56 $jsondir = $this->getArg( 1 );
57 $extension = $this->getOption(
'extension' );
58 $convertSupplementaryI18nFiles = $this->hasOption(
'supplementary' );
62 $this->fatalError(
"The phpfile is already specified, conflicts with --extension." );
64 $phpfile =
"$IP/extensions/$extension/$extension.i18n.php";
68 $this->error(
"I'm here for an argument!" );
69 $this->maybeHelp(
true );
73 if ( $convertSupplementaryI18nFiles ) {
74 if ( is_readable( $phpfile ) ) {
80 $this->error(
"Warning: no primary i18n file was found." );
82 $this->output(
"Searching for supplementary i18n files...\n" );
83 $dir_iterator =
new RecursiveDirectoryIterator( dirname( $phpfile ) );
84 $iterator =
new RecursiveIteratorIterator(
85 $dir_iterator, RecursiveIteratorIterator::LEAVES_ONLY );
87 foreach ( $iterator as
$path => $fileObject ) {
88 if ( fnmatch(
"*.i18n.php", $fileObject->getFilename() ) ) {
89 $this->output(
"Converting $path.\n" );
103 $jsondir = dirname( $phpfile ) .
"/i18n";
105 if ( !is_dir( $jsondir ) ) {
106 $this->output(
"Creating directory $jsondir.\n" );
109 $this->fatalError(
"Could not create directory $jsondir" );
113 if ( !is_readable( $phpfile ) ) {
114 $this->fatalError(
"Error reading $phpfile" );
118 $phpfileContents = file_get_contents( $phpfile );
121 if ( !isset( $messages ) ) {
122 $this->fatalError(
"PHP file $phpfile does not define \$messages array" );
126 $this->fatalError(
"PHP file $phpfile contains an empty \$messages array. " .
127 "Maybe it was already converted?" );
130 if ( !isset( $messages[
'en'] ) || !is_array( $messages[
'en'] ) ) {
131 $this->fatalError(
"PHP file $phpfile does not set language codes" );
134 foreach ( $messages as $langcode => $langmsgs ) {
136 "\$messages['$langcode'] =",
140 $langmsgs = array_merge(
141 [
'@metadata' => [
'authors' => $authors ] ],
145 $jsonfile =
"$jsondir/$langcode.json";
148 FormatJson::encode( $langmsgs,
"\t", FormatJson::ALL_OK ) .
"\n"
151 $this->fatalError(
"FAILED to write $jsonfile" );
153 $this->output(
"$jsonfile\n" );
157 "All done. To complete the conversion, please do the following:\n" .
158 "* Add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" .
159 "* Remove \$wgExtensionMessagesFiles['YourExtension']\n" .
160 "* Delete the old PHP message file\n" .
161 "This script no longer generates backward compatibility shims! If you need\n" .
162 "compatibility with MediaWiki 1.22 and older, use the MediaWiki 1.23 version\n" .
163 "of this script instead, or create a shim manually.\n"