r111918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111917‎ | r111918 | r111919 >
Date:10:08, 20 February 2012
Author:siebrand
Status:ok (Comments)
Tags:
Comment:
Remove obsolete and broken lang2po.php.
Modified paths:
  • /trunk/phase3/maintenance/language/lang2po.php (deleted) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/lang2po.php
@@ -1,166 +0,0 @@
2 -<?php
3 -/**
4 - * Convert Language files to .po files !
5 - *
6 - * Todo:
7 - * - generate .po header
8 - * - fix escaping of \
9 - *
10 - * This program is free software; you can redistribute it and/or modify
11 - * it under the terms of the GNU General Public License as published by
12 - * the Free Software Foundation; either version 2 of the License, or
13 - * (at your option) any later version.
14 - *
15 - * This program is distributed in the hope that it will be useful,
16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 - * GNU General Public License for more details.
19 - *
20 - * You should have received a copy of the GNU General Public License along
21 - * with this program; if not, write to the Free Software Foundation, Inc.,
22 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 - * http://www.gnu.org/copyleft/gpl.html
24 - *
25 - * @ingroup MaintenanceLanguage
26 - */
27 -
28 -/** This is a command line script */
29 -require_once( dirname( __FILE__ ) . '/../Maintenance.php' );
30 -require_once( dirname( __FILE__ ) . '/languages.inc' );
31 -
32 -define( 'ALL_LANGUAGES', true );
33 -define( 'XGETTEXT_BIN', 'xgettext' );
34 -define( 'MSGMERGE_BIN', 'msgmerge' );
35 -
36 -// used to generate the .pot
37 -define( 'XGETTEXT_OPTIONS', '-n --keyword=wfMsg --keyword=wfMsgForContent --keyword=wfMsgHtml --keyword=wfMsgWikiHtml ' );
38 -define( 'MSGMERGE_OPTIONS', ' -v ' );
39 -
40 -define( 'LOCALE_OUTPUT_DIR', $IP . '/locale' );
41 -
42 -class Lang2Po extends Maintenance {
43 - public function __construct() {
44 - parent::__construct();
45 - $this->mDescription = "";
46 - $this->addOption( 'lang', 'a lang code you want to generate a .po for (default: all langs)', false, true );
47 - }
48 -
49 - public function execute() {
50 - // Generate a template .pot based on source tree
51 - $this->output( "Getting 'gettext' default messages from sources:" );
52 - $this->generatePot();
53 - $this->output( "done.\n" );
54 -
55 -
56 - $langTool = new languages();
57 - if ( $this->getOption( 'lang', ALL_LANGUAGES ) === ALL_LANGUAGES ) {
58 - $codes = $langTool->getLanguages();
59 - } else {
60 - $codes = array( $this->getOption( 'lang' ) );
61 - }
62 -
63 - // Do all languages
64 - foreach ( $codes as $langcode ) {
65 - $this->output( "Loading messages for $langcode:\n" );
66 - if ( !$this->generatePo( $langcode, $langTool->getMessages( $langcode ) ) ) {
67 - $this->error( "ERROR: Failed to write file." );
68 - } else {
69 - $this->output( "Applying template:" );
70 - $this->applyPot( $langcode );
71 - }
72 - }
73 - }
74 -
75 - /**
76 - * Return a dummy header for later edition.
77 - *
78 - * @return String: a dummy header
79 - */
80 - private function poHeader() {
81 - return '# SOME DESCRIPTIVE TITLE.
82 -# Copyright (C) 2005 MediaWiki
83 -# This file is distributed under the same license as the MediaWiki package.
84 -# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
85 -#
86 -#, fuzzy
87 -msgid ""
88 -msgstr ""
89 -"Project-Id-Version: PACKAGE VERSION\n"
90 -"Report-Msgid-Bugs-To: bugzilllaaaaa\n"
91 -"POT-Creation-Date: 2005-08-16 20:13+0200\n"
92 -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
93 -"Last-Translator: VARIOUS <nobody>\n"
94 -"Language-Team: LANGUAGE <nobody>\n"
95 -"MIME-Version: 1.0\n"
96 -"Content-Type: text/plain; charset=UTF-8\n"
97 -"Content-Transfer-Encoding: 8bit\n"
98 -';
99 - }
100 -
101 - /**
102 - * generate and write a file in .po format.
103 - *
104 - * @param $langcode String: code of a language it will process.
105 - * @param $messages Array containing the various messages.
106 - * @return string Filename where stuff got saved or false.
107 - */
108 - private function generatePo( $langcode, $messages ) {
109 - $data = $this->poHeader();
110 -
111 - // Generate .po entries
112 - foreach ( $messages['all'] as $identifier => $content ) {
113 - $data .= "msgid \"$identifier\"\n";
114 -
115 - // Escape backslashes
116 - $tmp = str_replace( '\\', '\\\\', $content );
117 - // Escape doublelquotes
118 - $tmp = preg_replace( "/(?<!\\\\)\"/", '\"', $tmp );
119 - // Rewrite multilines to gettext format
120 - $tmp = str_replace( "\n", "\"\n\"", $tmp );
121 -
122 - $data .= 'msgstr "' . $tmp . "\"\n\n";
123 - }
124 -
125 - // Write the content to a file in locale/XX/messages.po
126 - $dir = LOCALE_OUTPUT_DIR . '/' . $langcode;
127 - if ( !is_dir( $dir ) ) { mkdir( $dir, 0770 ); }
128 - $filename = $dir . '/fromlanguagefile.po';
129 -
130 - $file = fopen( $filename , 'wb' );
131 - if ( fwrite( $file, $data ) ) {
132 - fclose( $file );
133 - return $filename;
134 - } else {
135 - fclose( $file );
136 - return false;
137 - }
138 - }
139 -
140 - private function generatePot() {
141 - global $IP;
142 - $curdir = getcwd();
143 - chdir( $IP );
144 - exec( XGETTEXT_BIN
145 - . ' ' . XGETTEXT_OPTIONS
146 - . ' -o ' . LOCALE_OUTPUT_DIR . '/wfMsg.pot'
147 - . ' includes/*php'
148 - );
149 - chdir( $curdir );
150 - }
151 -
152 - private function applyPot( $langcode ) {
153 - $langdir = LOCALE_OUTPUT_DIR . '/' . $langcode;
154 -
155 - $from = $langdir . '/fromlanguagefile.po';
156 - $pot = LOCALE_OUTPUT_DIR . '/wfMsg.pot';
157 - $dest = $langdir . '/messages.po';
158 -
159 - // Merge template and generate file to get final .po
160 - exec( MSGMERGE_BIN . MSGMERGE_OPTIONS . " $from $pot -o $dest " );
161 - // delete no more needed file
162 - // unlink($from);
163 - }
164 -}
165 -
166 -$maintClass = "Lang2Po";
167 -require_once( RUN_MAINTENANCE_IF_MAIN );

Comments

#Comment by Hashar (talk | contribs)   12:09, 20 February 2012

That was an experiment to use rosetta on Launchpad.net. Translatewiki.net replaced that :-D

#Comment by Krinkle (talk | contribs)   11:41, 24 February 2012

Release-notes maybe?

#Comment by Siebrand (talk | contribs)   22:26, 25 February 2012

If you insist, but I think this has been broken for years already, so I doubt anyone would be confused or miss it.

Status & tagging log