3 * Convert Language files to .po files !
6 * - generate .po header
10 /** This is a command line script */
11 require_once('commandLine.inc');
12 require_once('languages.inc');
14 define('ALL_LANGUAGES', true);
15 define('XGETTEXT_BIN', 'xgettext');
16 define('MSGINIT_BIN', 'msginit');
17 define('XGETTEXT_OPTIONS', '-n --keyword=wfMsg ');
19 define('LOCALE_OUTPUT_DIR', $IP.'/locale');
22 if( isset($options['help']) ) { usage(); die(); }
23 // default output is WikiText
24 if( !isset($options['lang']) ) { $options['lang'] = ALL_LANGUAGES
; }
28 Usage: php lang2po.php [--help] [--lang=<langcode>] [--stdout]
30 --lang: a lang code you want to generate a .po for (default: all languages).
37 * Return a dummy header for later edition.
38 * @return string A dummy header
42 '# SOME DESCRIPTIVE TITLE.
43 # Copyright (C) 2005 MediaWiki
44 # This file is distributed under the same license as the MediaWiki package.
45 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
50 "Project-Id-Version: PACKAGE VERSION\n"
51 "Report-Msgid-Bugs-To: bugzilllaaaaa\n"
52 "POT-Creation-Date: 2005-08-16 20:13+0200\n"
53 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
54 "Last-Translator: VARIOUS <nobody>\n"
55 "Language-Team: LANGUAGE <nobody>\n"
57 "Content-Type: text/plain; charset=UTF-8\n"
58 "Content-Transfer-Encoding: 8bit\n"
63 * generate and write a file in .po format.
65 * @param string $langcode Code of a language it will process.
66 * @param array &$messages Array containing the various messages.
67 * @return string Filename where stuff got saved or false.
69 function generatePo($langcode, &$messages) {
72 // Generate .po entries
73 foreach($messages as $identifier => $content) {
74 $data .= "msgid \"$identifier\"\n";
77 $tmp = str_replace('\\', '\\\\', $content);
78 // Escape doublelquotes
79 $tmp = preg_replace( "/(?<!\\\\)\"/", '\"', $tmp);
80 // Rewrite multilines to gettext format
81 $tmp = str_replace("\n", "\"\n\"", $tmp);
83 $data .= 'msgstr "'. $tmp . "\"\n\n";
86 // Write the content to a file in locale/XX/messages.po
87 $dir = LOCALE_OUTPUT_DIR
.'/'.$langcode;
88 if( !is_dir($dir) ) { mkdir( $dir, 0770 ); }
89 $filename = $dir.'/fromlanguagefile.po';
91 $file = fopen( $filename , 'wb' );
92 if( fwrite( $file, $data ) ) {
102 // Generate a template .pot based on source tree
103 echo "Getting 'gettext' default messages from sources\n";
105 .' '.XGETTEXT_OPTIONS
106 .' -o '.$IP.'/locale/wfMsg.pot'
107 .' '.$IP.'/includes/*php'
111 $langTool = new languages();
114 foreach ( $langTool->getList() as $langcode) {
115 echo "Loading messages for $langcode:\t";
116 require_once( 'languages/Language' . $langcode . '.php' );
117 $arr = 'wgAllMessages'.$langcode;
118 if(!@is_array
($
$arr)) {
122 if( ! generatePo($langcode, $
$arr) ) {
123 echo "ERROR: Failed to wrote file.\n";