mDescription = ""; $this->addOption( 'lang', 'a lang code you want to generate a .po for (default: all langs)', false, true ); } public function execute() { // Generate a template .pot based on source tree $this->output( "Getting 'gettext' default messages from sources:" ); $this->generatePot(); $this->output( "done.\n" ); $langTool = new languages(); if ( $this->getOption( 'lang', ALL_LANGUAGES ) === ALL_LANGUAGES ) { $codes = $langTool->getLanguages(); } else { $codes = array( $this->getOption( 'lang' ) ); } // Do all languages foreach ( $codes as $langcode ) { $this->output( "Loading messages for $langcode:\n" ); if ( !$this->generatePo( $langcode, $langTool->getMessages( $langcode ) ) ) { $this->error( "ERROR: Failed to write file." ); } else { $this->output( "Applying template:" ); $this->applyPot( $langcode ); } } } /** * Return a dummy header for later edition. * * @return String: a dummy header */ private function poHeader() { return '# SOME DESCRIPTIVE TITLE. # Copyright (C) 2005 MediaWiki # This file is distributed under the same license as the MediaWiki package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bugzilllaaaaa\n" "POT-Creation-Date: 2005-08-16 20:13+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: VARIOUS \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" '; } /** * generate and write a file in .po format. * * @param $langcode String: code of a language it will process. * @param $messages Array containing the various messages. * @return string Filename where stuff got saved or false. */ private function generatePo( $langcode, $messages ) { $data = $this->poHeader(); // Generate .po entries foreach ( $messages['all'] as $identifier => $content ) { $data .= "msgid \"$identifier\"\n"; // Escape backslashes $tmp = str_replace( '\\', '\\\\', $content ); // Escape doublelquotes $tmp = preg_replace( "/(?