Merge lp:~quam-plures-core/quam-plures/bug-538197 into lp:quam-plures/misc

Proposed by Tilman Blumenbach
Status: Merged
Merged at revision: not available
Proposed branch: lp:~quam-plures-core/quam-plures/bug-538197
Merge into: lp:quam-plures/misc
Diff against target: 612 lines (+235/-212)
2 files modified
gettext/xg.bat (+61/-19)
gettext/xg.php (+174/-193)
To merge this branch: bzr merge lp:~quam-plures-core/quam-plures/bug-538197
Reviewer Review Type Date Requested Status
EdB Approve
Tilman Blumenbach (community) Abstain
Review via email: mp+21276@code.launchpad.net

Commit message

Merged bug-538197.

To post a comment you must log in.
Revision history for this message
EdB (edb) wrote :

Not sure how I could test this so I won't, but wanted to mention that I will be taking care of the_pofile.class.php file in the main package.

Correct me if I'm wrong, but this is how one would extract the actual strings (if one did not want to use a .bat file)? pofile.class.php seems to create the _global.php file for each locale, and it still writes "if evo_main_whatever is undefined" plus a few other uncool bits.

Revision history for this message
EdB (edb) wrote :

Oh and I couldn't merge this if I wanted to but I say it's cool so someone should merge it. At least I think I can't merge it... I know I can say it is okay because see how I just did :)

review: Approve
Revision history for this message
Tilman Blumenbach (tblue) wrote :

> Correct me if I'm wrong, but this is how one would extract the actual strings (if one did not want to use a .bat file)?
Yes.

> pofile.class.php seems to create the _global.php file for each locale, and it still writes "if evo_main_whatever is undefined" plus a few other uncool bits.
Hmm, looks like it uses QP_MAIN_INIT already.

Revision history for this message
EdB (edb) wrote :

Yeah I type then think is the thing. The Turkish translation had it so I wondered where it came from. It came from getting Turkish from evoland :)

The change I made to _pofile is to very simply add a @package line for happy autodocs ... which I now realize I forgot to add to the files prior to pushing the restored localizations. Sheesh!

Revision history for this message
EdB (edb) wrote :

hmmm... maybe I could merge this but I'm not going to try. Got one thing done today I didn't know how to do, so I don't want to push my luck. Yabs?

Revision history for this message
EdB (edb) wrote :

I thought of a problem with this but it might not be depending on exactly how you got it working. The files in the /templates/ folder are "core" and therefore need to be translated with everything else. The folders (the actual templates) are the ones that "core translation" should be not doing. So for my method "remove plugins folder, remove all the folders in the templates folder, do the batch file thing". For this smart method it means a smarter smart line to exclude folders in a folder.

Revision history for this message
Tilman Blumenbach (tblue) wrote :

Okay, I will look at this. Consider this proposal to be "on hold".

Revision history for this message
Tilman Blumenbach (tblue) wrote :

So this turned into a major overhaul of gettext/xg.php. I tested most of it.

review: Needs Resubmitting
Revision history for this message
Tilman Blumenbach (tblue) wrote :

Still working on the batch file...

Revision history for this message
Tilman Blumenbach (tblue) :
review: Abstain
Revision history for this message
Tilman Blumenbach (tblue) wrote :

Batch files are very limited, but the new batch file at least does more than the previous one. I think I'm done.

14. By Tilman Blumenbach

Added plugin and core mode to xg.bat

Revision history for this message
EdB (edb) wrote :

If Yabs doesn't merge this I'll see if I can. Not sure if I have perms or not, but if so I can probably figure out how to get it done. Would be better if Yabs took care of it though.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'gettext/xg.bat'
--- gettext/xg.bat 2010-01-27 18:27:00 +0000
+++ gettext/xg.bat 2010-03-14 12:54:25 +0000
@@ -1,19 +1,61 @@
1@echo off1@echo off
22
3echo Generate file list.3REM xg.bat - Generate POT file.
4dir /b /s ..\blogs\*.php > files.txt4REM Invoke this batch file in the application root directory (or the
55REM directory where your plugin file resides).
6echo Extract strings.6
7xgettext -D ../blogs/ -f files.txt --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --output=..\blogs\locales\messages.pot --keyword=T_ --keyword=NT_ --keyword=TS_7REM This batch file requires the sed, xgettext and fart tools to be somewhere
88REM in your Path.
9echo Correct paths.9REM sed is available from:
10xchangecl +d! ..\blogs\locales\messages.pot !D:\www\b2cvs20\blogs\!..\..\..\!10REM http://gnuwin32.sourceforge.net/packages/sed.htm
1111REM xgettext is available from:
12echo Correct Header.12REM http://gnuwin32.sourceforge.net/packages/gettext.htm
13xchangecl +d! -t# ..\blogs\locales\messages.pot !#35##32#SOME#32#DESCRIPTIVE#32#TITLE.!#35##32#b2evolution#32#-#32#Language#32#file!#35##32#This#32#file#32#is#32#distributed#32#under#32#the#32#same#32#license#32#as#32#the#32#PACKAGE#32#package.!#35##32#This#32#file#32#is#32#distributed#32#under#32#the#32#same#32#license#32#as#32#the#32#b2evolution#32#package.!"Content-Type:#32#text/plain;#32#charset=CHARSET\n"!"Content-Type:#32#text/plain;#32#charset=iso-8859-1\n"!13REM fart is available from:
1414REM http://fart-it.sourceforge.net/
15echo Merge with French.15
16msgmerge -U --no-wrap ..\blogs\locales\fr_FR\LC_MESSAGES\messages.po ..\blogs\locales\messages.pot16if /i "%1" equ "CORE" (
1717 goto MAIN
18REM echo Change comments.18) else if /i "%1" equ "PLUGIN" (
19REM xchangecl +d! -t# ..\blogs\locales\fr_FR\LC_MESSAGES\messages.po !#35#.#32#TRANS:!#35##32#TRANS:!19 goto MAIN
20) else (
21 goto USAGE
22)
23
24:MAIN
25 REM Generate file list, make paths relative, filter excluded directories
26 REM and extract strings:
27 dir /s /b *.php | fart -qi - "%CD%" . ^
28 | findstr /r /i /v ^
29 "^\.\\templates\\[^\\]*\\.* ^\.\\plugins\\.* ^\.\\build\\.*" ^
30 | xgettext -f - -o locales\messages.pot --from-code=iso-8859-15 ^
31 --no-wrap --add-comments=TRANS "--copyright-holder=The Quam Plures developers" ^
32 --msgid-bugs-address=http://quamplures.net/ --keyword=T_ ^
33 --keyword=NT_ --keyword=TS_ -F
34
35 REM Make paths relative:
36 sed -i "/^#: /{ s| \.| ..\\..\\..|g; }" locales\messages.pot
37
38 if /i "%1" equ "CORE" (
39 REM Replace bulk header values with nicer ones.
40 REM TODO: Make app name and current year dynamic. Replace app version as in xg.php.
41 sed -i "1,20{ s/PACKAGE/Quam Plures/; s/# SOME DESCRIPTIVE TITLE./# Quam Plures - Language file/; s/(C) YEAR/(C) 2009-2010/; s/CHARSET/iso-8859-1/; }" ^
42 locales\messages.pot
43 )
44
45 REM Delete temporary sed files (bug in gnuwin32 port):
46 del sed*
47
48 exit /b 0
49
50:USAGE
51 echo Usage:
52 echo ^ %0 ^<CORE^|PLUGIN^>
53 echo.
54 echo CORE : Work on the core application.
55 echo PLUGIN: Work on a plugin.
56 echo.
57 echo In both modes, you have to invoke this script in the application's
58 echo root directory or the directory which contains your plugin's PHP
59 echo file, respectively.
60
61 exit /b 1
20\ No newline at end of file62\ No newline at end of file
2163
=== modified file 'gettext/xg.php'
--- gettext/xg.php 2010-01-27 18:27:00 +0000
+++ gettext/xg.php 2010-03-14 12:54:25 +0000
@@ -4,11 +4,12 @@
4 * Create a new messages.POT file and update specified .po files.4 * Create a new messages.POT file and update specified .po files.
5 *5 *
6 * Uses find, xargs, sed, xgettext and msgmerge tools.6 * Uses find, xargs, sed, xgettext and msgmerge tools.
7 * This only works on UNIXoid systems.
7 *8 *
8 * This file is part of the Quam Plures project - {@link http://quamplures.net/}.9 * This file is part of the Quam Plures project - {@link http://quamplures.net/}.
9 * See also {@link https://launchpad.net/quam-plures}.10 * See also {@link https://launchpad.net/quam-plures}.
10 *11 *
11 * @copyright (c) 2009 by the Quam Plures developers - {@link http://quamplures.net/}12 * @copyright (c) 2009-2010 by the Quam Plures developers - {@link http://quamplures.net/}
12 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.13 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.
13 * Parts of this file are copyright (c)2004 by Daniel HAHLER - {@link http://thequod.de/contact}.14 * Parts of this file are copyright (c)2004 by Daniel HAHLER - {@link http://thequod.de/contact}.
14 *15 *
@@ -18,70 +19,81 @@
18 * Daniel HAHLER grants Francois PLANQUE the right to license19 * Daniel HAHLER grants Francois PLANQUE the right to license
19 * Daniel HAHLER's contributions to this file and the b2evolution project20 * Daniel HAHLER's contributions to this file and the b2evolution project
20 * under any OSI approved OSS license (http://www.opensource.org/licenses/).21 * under any OSI approved OSS license (http://www.opensource.org/licenses/).
21 * }}22 * }
22 *23 *
23 * @package internal24 * @package internal
24 *25 *
25 * @todo Add checks for format, headers and domain ("msgfmt -c")26 * @todo Add checks for format, headers and domain ("msgfmt -c").
26 *27 *
27 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}28 * {@internal Below is a list of authors who have contributed to design/coding of this file:}
28 * @author blueyed: Daniel HAHLER.29 * @author blueyed: Daniel HAHLER.
29 *30 * @author Tblue: Tilman BLUMENBACH.
30 */31 */
3132
32require_once dirname(__FILE__).'/../blogs/conf/_config.php';33// Cache script base name:
3334$my_basename = basename( $argv[0] );
34echo '** gettext helper tool for ', $app_name, ' **', "\n";35// Set default application root directory:
3536$_app_root = dirname( __FILE__ ).'/../../trunk';
36// Check that all external tools are available:
37foreach( array( 'xgettext', 'msgmerge', 'find', 'xargs', 'sed' ) as $testtool )
38{
39 exec( $testtool.' --version', $output, $return );
40 if( $return !== 0 )
41 {
42 die( "This script needs the $testtool tool.\n" );
43 }
44}
45
4637
47function echo_usage()38function echo_usage()
48{39{
49 global $argv, $app_name;40 global $argv, $app_name, $my_basename, $_app_root;
5041
51 echo "Usage: \n";42 echo 'Usage: ', "\n";
52 echo basename($argv[0])." <CORE|CWD> [extract]\n";43 echo ' ', $my_basename, ' [-b <app_root>] <CORE|CWD> [extract]', "\n";
53 echo basename($argv[0])." <CORE|CWD> merge <locale> [locale..]\n";44 echo ' ', $my_basename, ' [-b <app_root>] <CORE|CWD> merge <locale> [locale..]', "\n";
54 echo basename($argv[0])." <CORE|CWD> convert <locale> [locale..]\n";45 echo ' ', $my_basename, ' [-b <app_root>] <CORE|CWD> convert <locale> [locale..]', "\n\n";
55 echo "CORE: work on the core application\n";46 echo 'CORE: work on the core application.', "\n";
56 echo "CWD: work on current working directory\n";47 echo 'CWD : work on current working directory.', "\n";
57 echo "\n";48 echo "\n";
58 echo "By default, to translatable strings get extracted into locales/messages.POT.\n";49 echo 'By default, the translatable strings get extracted into locales/messages.POT.', "\n";
59 echo "\n";50 echo "\n";
60 echo "By adding 'merge <locale>' to the command line arguments, you'll merge\n";51 echo 'By adding \'merge <locale>\' to the command line arguments, you\'ll merge', "\n";
61 echo "the locale's messages.PO file with the messages.POT file. This is useful\n";52 echo 'the locale\'s messages.PO file with the messages.POT file. This is useful', "\n";
62 echo "after having updated the messages.POT file, obviously.\n";53 echo 'after having updated the messages.POT file, obviously.', "\n";
63 echo "\n";54 echo "\n";
64 echo "By adding 'convert <locale>' to the command line arguments, you'll convert\n";55 echo 'By adding \'convert <locale>\' to the command line arguments, you\'ll convert', "\n";
65 echo 'the locale\'s messages.PO file to _global.php, which ', $app_name, " uses.\n";56 echo 'the locale\'s messages.PO file to _global.php, which ', $app_name, ' uses.', "\n";
66 echo "\n";57 echo "\n";
67 echo "E.g.,\n";58 echo 'E.g.:', "\n";
68 echo " php -f xg.php CORE\n";59 echo ' php ', $my_basename, ' CORE', "\n";
69 echo " php -f xg.php CORE merge de_DE\n";60 echo ' php ', $my_basename, ' CORE merge de_DE', "\n";
70 echo " ..edit .po file..\n";61 echo ' ..edit .po file..', "\n";
71 echo " php -f xg.php CORE convert de_DE\n";62 echo ' php ', $my_basename, ' CORE convert de_DE', "\n";
72 echo "\n";63 echo "\n";
73}64 echo 'This script expects the ', $app_name, ' root directory to be at [', $_app_root, '].', "\n";
7465 echo 'You can specify an alternative root directory using the -b option, e. g.:', "\n";
7566 echo ' php ', $my_basename, ' -b ../blogs CORE', "\n";
76if( ! isset($_SERVER['argc']) || ! isset( $_SERVER['argv'] ) )67 echo '...but if you are reading this message, the root directory is set correctly.', "\n";
77{68}
78 echo_usage();69
79 exit(1);70
80}71// Allow overriding of the application root directory via command line (-b option):
8172$opts = getopt( 'b:' );
8273if( isset( $opts['b'] ) )
83$argc = $_SERVER['argc'];74{
84$argv = $_SERVER['argv'];75 $_app_root = $opts['b'];
76
77 // Silently modify $argc and $argv:
78 $argc -= 2;
79 // This will fail if somebody passes an argument with more than one
80 // option, e. g. "-bar".
81 array_splice( $argv, array_search( '-b', $argv ), 2 );
82
83 //var_dump( $argc, $argv );
84}
85
86if( ! is_dir( $_app_root ) )
87{
88 echo 'Error: Application root directory [', $_app_root, '] does not exist!', "\n";
89 echo 'You can specify an alternative root directory by using the -b option:', "\n";
90 echo ' php ', $my_basename, ' -b /path/to/application/root/directory CORE', "\n";
91 exit( 2 );
92}
93
94require_once $_app_root.'/conf/_config.php';
95
96echo '** gettext helper tool for ', $app_name, ' **', "\n\n";
8597
86if( $argc < 2 )98if( $argc < 2 )
87{99{
@@ -89,65 +101,66 @@
89 exit(1);101 exit(1);
90}102}
91103
92if( strtoupper($argv[1]) == 'CORE' )104switch( strtoupper($argv[1]) )
93{105{
94 echo "CORE mode..\n";106 case 'CORE':
95 $mode = 'CORE';107 echo 'CORE mode..', "\n";
96 // The blogs directory:108 $mode = 'CORE';
97 $dir_root = dirname(__FILE__).'/../blogs/';109 // Our root directory is the application root directory:
98}110 $dir_root = $_app_root;
99elseif( strtoupper($argv[1]) == 'CWD' )111 break;
100{112
101 echo "Using current working directory..\n";113 case 'CWD':
102 $mode = 'CWD';114 echo 'Using current working directory..', "\n";
103 $dir_root = getcwd();115 $mode = 'CWD';
104}116 $dir_root = getcwd();
105else117 break;
106{118
107 echo_usage();119 default:
108 exit(1);120 echo_usage();
109}121 exit(1);
110122}
111if( ! isset($argv[2]) || strtoupper($argv[2]) == 'EXTRACT' )123
112{124$action = 'extract';
113 $action = 'extract';125if( isset($argv[2]) )
114}126{
115elseif( isset($argv[2]) && strtoupper($argv[2]) == 'MERGE' )127 $action = strtolower( $argv[2] );
116{128
117 $action = 'merge';129 if( ! in_array( $action, array( 'extract', 'merge', 'convert' ) ) )
118130 {
119 if( ! isset($argv[3]) ) // the to-get-merged locale131 echo_usage();
120 {132 exit( 1 );
121 echo_usage();133 }
122 exit(1);134 else if( $action == 'convert' || $action == 'merge' )
123 }135 {
124136 if( ! isset($argv[3]) )
125 $locales_to_merge = array_slice( $argv, 3 );137 {
126}138 echo_usage();
127elseif( isset($argv[2]) && strtoupper($argv[2]) == 'CONVERT' )139 exit(1);
128{140 }
129 $action = 'convert';141
130142 $_locales = array_slice( $argv, 3 );
131 if( ! isset($argv[3]) ) // the to-get-converted locale143 }
132 {144}
133 echo_usage();
134 exit(1);
135 }
136
137 $locales_to_convert = array_slice( $argv, 3 );
138}
139else
140{
141 echo_usage();
142 die;
143}
144
145145
146// ---- COMMON CHECKS: ----146// ---- COMMON CHECKS: ----
147147
148if( ! realpath($dir_root) )148if( $action != 'convert' )
149{149{
150 die( "Fatal error: The path '$dir_root' was not found!\n" );150 // Check that all external tools are available:
151 foreach( array( 'xgettext', 'msgmerge', 'find', 'xargs', 'sed' ) as $testtool )
152 {
153 exec( $testtool.' --version 2>/dev/null', $output, $return );
154 if( $return == 127 )
155 { // Command not found (return code specified by POSIX):
156 die( 'This script needs the '.$testtool.' tool.'."\n" );
157 }
158 }
159}
160
161if( ! is_dir($dir_root) )
162{
163 die( 'Fatal error: The path ['.$dir_root.'] was not found!'."\n" );
151}164}
152// Normalize path:165// Normalize path:
153$dir_root = realpath($dir_root).'/';166$dir_root = realpath($dir_root).'/';
@@ -158,20 +171,19 @@
158// The messages.pot (template) file:171// The messages.pot (template) file:
159$file_pot = $dir_root.'locales/messages.pot';172$file_pot = $dir_root.'locales/messages.pot';
160173
161
162if( $action == 'extract' )174if( $action == 'extract' )
163{175{
164 if( ! is_writable($file_pot) )176 if( ! is_writable($file_pot) )
165 {177 {
166 if( ! file_exists( $dir_root.'locales' ) )178 if( ! file_exists( $dir_root.'locales' ) )
167 {179 {
168 echo "Directory {$dir_root}locales/ does not exist..\n";180 echo 'Directory [', $dir_root, 'locales/] does not exist..', "\n";
169181
170 if( ! mkdir( $dir_root.'locales' ) )182 if( ! mkdir( $dir_root.'locales' ) )
171 {183 {
172 die( "FATAL: could not create directory {$dir_root}locales/\n" );184 die( 'FATAL: could not create directory ['.$dir_root.'locales/]!'."\n" );
173 }185 }
174 echo "Created directory.\n";186 echo 'Created directory.', "\n";
175 }187 }
176188
177 if( ! file_exists( $file_pot ) )189 if( ! file_exists( $file_pot ) )
@@ -182,69 +194,89 @@
182194
183 if( ! is_writable($file_pot) )195 if( ! is_writable($file_pot) )
184 {196 {
185 die( "FATAL: The file $file_pot is not writable.\n" );197 die( 'FATAL: The file ['.$file_pot.'] is not writable.'."\n" );
186 }198 }
187 }199 }
188200
189 // The locales dir is our working dir:201 $dir_root_basename = basename($dir_root);
190# chdir( $dir_root.'locales' );
191
192 if( isset($argv[3]) )202 if( isset($argv[3]) )
193 { // File(s) specified203 { // File(s) specified
204 echo 'Extracting T_() and NT_() strings from given files below "';
205 echo $dir_root_basename, '" into "', $dir_root_basename, '/locales/messages.pot".. ';
194 $cmd = '';206 $cmd = '';
195 echo 'Extracting T_() and NT_() strings from given files below "'.basename($dir_root).'" into "'.basename($dir_root).'/locales/messages.pot".. ';
196 }207 }
197 else208 else
198 {209 {
199 echo 'Extracting T_() and NT_() strings from all .php files below "'.basename($dir_root).'" into "'.basename($dir_root).'/locales/messages.pot".. ';210 echo 'Extracting T_() and NT_() strings from all .php files below "';
200 # find *.php files, but not in "build" directory:211 echo $dir_root_basename, '" into "', $dir_root_basename, '/locales/messages.pot".. ';
201 $cmd = 'find '.escapeshellarg($dir_root).' -wholename "*/build/*" -prune -o \( -iname "*.php" -print \) | xargs ';212
213 // Change working dir (to simplify exlude patterns below):
214 chdir( $dir_root );
215
216 /* Find *.php files, but exclude:
217 * - all directories below templates/
218 * - the plugins/ directory
219 * - the build/ directory
220 */
221 $cmd = 'find . \\( ';
222 $cmd .= '-path \'./templates/*[!/]/*\' -o -path \'./plugins/*\' -o -path \'./build/*\'';
223 $cmd .= ' \\) -prune -o \\( -iname \'*.php\' -print0 \\) | xargs -0 ';
202 }224 }
203 $cmd .= 'xgettext -o '.escapeshellarg($file_pot).' --from-code=iso-8859-15 --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --keyword=T_ --keyword=NT_ --keyword=TS_ -F';225 $cmd .= 'xgettext -o '.escapeshellarg($file_pot).' --from-code=iso-8859-15 --no-wrap --add-comments=TRANS --copyright-holder="The Quam Plures developers" --msgid-bugs-address=http://quamplures.net/ --keyword=T_ --keyword=NT_ --keyword=TS_ -F';
204226
205 // Append filenames, if specified:227 // Append filenames, if specified:
206 if( isset($argv[3]) )228 if( isset($argv[3]) )
207 {229 {
208 for( $i = 3; $i < count($argv); $i++ )230 $n = count($argv);
231 for( $i = 3; $i < $n; $i++ )
209 {232 {
210 $cmd .= ' '.escapeshellarg($argv[$i]);233 $cmd .= ' '.escapeshellarg($argv[$i]);
211 }234 }
212 }235 }
213236
237 //echo 'Command: [', $cmd, ']', "\n";
214 system( $cmd, $return_var );238 system( $cmd, $return_var );
215 if( $return_var !== 0 )239 if( $return_var !== 0 )
216 {240 {
217 die("Failed!\n");241 die('Command failed (return code: '.$return_var.')!'."\n");
218 }242 }
219 echo "[ok]\n";243 echo "[ok]\n";
220244
221245
222 // Replace various things (see comments)246 // Replace various things (see comments)
223 echo 'Automagically search&replace in messages.pot.. ';247 echo 'Automagically search & replace in messages.pot.. ';
224 $data = file_get_contents( $file_pot );248 $data = file_get_contents( $file_pot );
225249
226 $data = str_replace( "\r", '', $data );250 $data = str_replace( "\r", '', $data );
227 // Make paths relative:251 // Make paths relative:
228 $data = preg_replace( '~^#: .*$~me', 'str_replace( \' '.$dir_root.'\', \' ../../../\', \'$0\' )', $data );252
253 if( isset( $argv[3] ) )
254 { // File names given
255 $rep_path = $dir_root;
256 }
257 else
258 { // Core mode (prepend root path to file names in POT file):
259 $rep_path = '';
260 }
261 $data = preg_replace( '~^#: .*$~me', 'str_replace( \' '.$rep_path.'\', \' ../../../\', \'$0\' )', $data );
229262
230 file_put_contents( $file_pot, $data );263 file_put_contents( $file_pot, $data );
231264
232 if( $mode == 'CORE' )265 if( $mode == 'CORE' )
233 { // Replace header "vars" in first 20 lines:266 { // Replace header "vars" in first 20 lines:
234 system( 'sed -i 1,20"'267 system( 'sed -i "1,20{'
235 .'s/PACKAGE/'.$app_name.'/;'268 .'s/PACKAGE/'.$app_name.'/;'
236 .'s/VERSION/'.$app_version.'/;'269 .'s/VERSION/'.$app_version.'/;'
237 .'s/# SOME DESCRIPTIVE TITLE./# '.$app_name.' - Language file/;'270 .'s/# SOME DESCRIPTIVE TITLE./# '.$app_name.' - Language file/;'
238 .'s/(C) YEAR/(C) 2003-'.date('Y').'/;'271 .'s/(C) YEAR/(C) 2009-'.date('Y').'/;'
239 .'s/YEAR(?!-MO)/'.date('Y').'/;'
240 .'s/CHARSET/iso-8859-1/;'272 .'s/CHARSET/iso-8859-1/;'
241 .'" '.escapeshellarg($file_pot) );273 .'}" '.escapeshellarg($file_pot) );
242 }274 }
243 else275 else
244 {276 {
245 // TODO: try to detect usage with a plugin and s&r accordingly277 // TODO: try to detect usage with a plugin and s&r accordingly
246 }278 }
247 echo "[ok]\n";279 echo '[ok]', "\n";
248280
249 exit(0);281 exit(0);
250}282}
@@ -254,11 +286,11 @@
254{ // Merge with existing .po files:286{ // Merge with existing .po files:
255 if( ! @is_readable( $file_pot ) )287 if( ! @is_readable( $file_pot ) )
256 {288 {
257 echo "FATAL: $file_pot is not readable!\n";289 echo 'FATAL: [', $file_pot, '] is not readable!', "\n";
258 exit(1);290 exit(1);
259 }291 }
260292
261 foreach( $locales_to_merge as $l_locale )293 foreach( $_locales as $l_locale )
262 {294 {
263 $l_file_po = $dir_root.'locales/'.$l_locale.'/LC_MESSAGES/messages.po';295 $l_file_po = $dir_root.'locales/'.$l_locale.'/LC_MESSAGES/messages.po';
264296
@@ -266,14 +298,14 @@
266298
267 if( ! file_exists( $l_file_po ) )299 if( ! file_exists( $l_file_po ) )
268 {300 {
269 echo "PO file $l_file_po not found!\n";301 echo 'PO file [', $l_file_po, '] not found!', "\n";
270 continue;302 continue;
271 }303 }
272304
273 system( 'msgmerge -U -F --no-wrap '.escapeshellarg($l_file_po).' '.escapeshellarg($file_pot) );305 system( 'msgmerge -U -F --no-wrap '.escapeshellarg($l_file_po).' '.escapeshellarg($file_pot) );
274 # delete old TRANS comments and make automatic ones valid comments:306 # delete old TRANS comments and make automatic ones valid comments:
275 system( 'sed -i -r "/^#\\s+TRANS:/d; s/^#\\. TRANS:/# TRANS:/;" '.$l_file_po );307 system( 'sed -i -r "/^#\\s+TRANS:/d; s/^#\\. TRANS:/# TRANS:/;" '.$l_file_po );
276 echo "Written $l_file_po .\n";308 echo 'Written [', $l_file_po, '].', "\n";
277 echo "\n";309 echo "\n";
278 }310 }
279311
@@ -283,9 +315,9 @@
283315
284if( $action == 'convert' )316if( $action == 'convert' )
285{ // convert messages.PO files to _global.php317{ // convert messages.PO files to _global.php
286 require_once dirname(__FILE__).'/../blogs/inc/locales/_pofile.class.php';318 require_once $_app_root.'/inc/locales/_pofile.class.php';
287319
288 foreach( $locales_to_convert as $l_locale )320 foreach( $_locales as $l_locale )
289 {321 {
290 $l_file_po = $dir_root.'locales/'.$l_locale.'/LC_MESSAGES/messages.po';322 $l_file_po = $dir_root.'locales/'.$l_locale.'/LC_MESSAGES/messages.po';
291 $global_file_path = $dir_root.'locales/'.$l_locale.'/_global.php';323 $global_file_path = $dir_root.'locales/'.$l_locale.'/_global.php';
@@ -294,7 +326,7 @@
294326
295 if( !file_exists( $l_file_po ) )327 if( !file_exists( $l_file_po ) )
296 {328 {
297 echo "PO file $l_file_po not found!\n";329 echo 'PO file [', $l_file_po, '] not found!', "\n";
298 continue;330 continue;
299 }331 }
300332
@@ -304,63 +336,12 @@
304336
305 if( $r !== true )337 if( $r !== true )
306 {338 {
307 echo "Error: $r\n";339 echo 'Error: ', $r, "\n";
308 continue;340 continue;
309 }341 }
310342
311 echo "[ok]\n";343 echo '[ok]', "\n";
312 }344 }
313345
314 exit(0);346 exit(0);
315}347}
316
317
318/**
319 * From {@link http://de.php.net/manual/en/function.realpath.php#77203}
320 */
321function rel_path($dest, $root = '')
322{
323 $root = explode(DIRECTORY_SEPARATOR, $root);
324 $dest = explode(DIRECTORY_SEPARATOR, $dest);
325 $path = '.';
326 $fix = '';
327 $diff = 0;
328 for($i = -1; ++$i < max(($rC = count($root)), ($dC = count($dest)));)
329 {
330 if(isset($root[$i]) and isset($dest[$i]))
331 {
332 if($diff)
333 {
334 $path .= DIRECTORY_SEPARATOR. '..';
335 $fix .= DIRECTORY_SEPARATOR. $dest[$i];
336 continue;
337 }
338 if($root[$i] != $dest[$i])
339 {
340 $diff = 1;
341 $path .= DIRECTORY_SEPARATOR. '..';
342 $fix .= DIRECTORY_SEPARATOR. $dest[$i];
343 continue;
344 }
345 }
346 elseif(!isset($root[$i]) and isset($dest[$i]))
347 {
348 for($j = $i-1; ++$j < $dC;)
349 {
350 $fix .= DIRECTORY_SEPARATOR. $dest[$j];
351 }
352 break;
353 }
354 elseif(isset($root[$i]) and !isset($dest[$i]))
355 {
356 for($j = $i-1; ++$j < $rC;)
357 {
358 $fix = DIRECTORY_SEPARATOR. '..'. $fix;
359 }
360 break;
361 }
362 }
363 return $path. $fix;
364}
365
366?>

Subscribers

People subscribed via source and target branches

to all changes: