From 395d6d63a4d8dcab8cf3f60985136aef455c5941 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 16 Aug 2005 17:15:55 +0000 Subject: [PATCH] Work in progress. Script that output some basic and incorrect .po files based on our LanguageXX.php files and code in ./includes/ . --- locale/README | 1 + maintenance/lang2po.php | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 locale/README create mode 100644 maintenance/lang2po.php diff --git a/locale/README b/locale/README new file mode 100644 index 0000000000..04374885d5 --- /dev/null +++ b/locale/README @@ -0,0 +1 @@ +This directory is for .po files generated by ./maintenance/lang2po.php diff --git a/maintenance/lang2po.php b/maintenance/lang2po.php new file mode 100644 index 0000000000..a693b6dbff --- /dev/null +++ b/maintenance/lang2po.php @@ -0,0 +1,97 @@ +] [--stdout] + --help: this message. + --lang: a lang code you want to generate a .po for (default: all languages). + +END; +} + + +/** + * generate and write a file in .po format. + * + * @param string $langcode Code of a language it will process. + * @param array &$messages Array containing the various messages. + * @return string Filename where stuff got saved or false. + */ +function generatePo($langcode, &$messages) { + $data = ''; // TODO a .po header ? + + // Generate .po entries + foreach($messages as $identifier => $content) { + $data .= "msgid \"$identifier\"\n"; + + // Double quotes escaped for $content: + $tmp = 'msgstr "'.str_replace('"', '\"', $content)."\""; + // New line should end with "\n not \n + $data .= str_replace("\n", "\"\n\"", $tmp); + $data .= "\n\n"; + } + + // Write the content to a file in locale/XX/messages.po + $dir = LOCALE_OUTPUT_DIR.'/'.$langcode; + if( !is_dir($dir) ) { mkdir( $dir, 0770 ); } + $filename = $dir.'/fromlanguagefile.po'; + + $file = fopen( $filename , 'wb' ); + if( fwrite( $file, $data ) ) { + fclose( $file ); + return $filename; + } else { + fclose( $file ); + return false; + } +} + +$langTool = new languages(); + +// Do all languages +foreach ( $langTool->getList() as $langcode) { + echo "Loading messages for $langcode:\t"; + require_once( 'languages/Language' . $langcode . '.php' ); + $arr = 'wgAllMessages'.$langcode; + if(!@is_array($$arr)) { + echo "NONE FOUND\n"; + } else { + echo "ok\n"; + if( ! generatePo($langcode, $$arr) ) { + echo "ERROR: Failed to wrote file.\n"; + } + } +} + +// Generate a default .po based source tree +echo "Getting 'gettext' default messages from sources\n"; +exec( XGETTEXT_BIN + .' '.XGETTEXT_OPTIONS + .' -o '.$IP.'/locale/wfMsg.po' + .' '.$IP.'/includes/*php' + ); + + +?> -- 2.20.1