Merge lp:~quam-plures-core/quam-plures/bug-538197 into lp:quam-plures/misc
- bug-538197
- Merge into miscfiles
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 |
Related bugs: |
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.
Description of the change
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 :)
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.
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!
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?
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.
Tilman Blumenbach (tblue) wrote : | # |
Okay, I will look at this. Consider this proposal to be "on hold".
Tilman Blumenbach (tblue) wrote : | # |
So this turned into a major overhaul of gettext/xg.php. I tested most of it.
Tilman Blumenbach (tblue) wrote : | # |
Still working on the batch file...
Tilman Blumenbach (tblue) : | # |
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
Preview Diff
1 | === modified file 'gettext/xg.bat' | |||
2 | --- gettext/xg.bat 2010-01-27 18:27:00 +0000 | |||
3 | +++ gettext/xg.bat 2010-03-14 12:54:25 +0000 | |||
4 | @@ -1,19 +1,61 @@ | |||
24 | 1 | @echo off | 1 | @echo off |
25 | 2 | 2 | ||
26 | 3 | echo Generate file list. | 3 | REM xg.bat - Generate POT file. |
27 | 4 | dir /b /s ..\blogs\*.php > files.txt | 4 | REM Invoke this batch file in the application root directory (or the |
28 | 5 | 5 | REM directory where your plugin file resides). | |
29 | 6 | echo Extract strings. | 6 | |
30 | 7 | xgettext -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_ | 7 | REM This batch file requires the sed, xgettext and fart tools to be somewhere |
31 | 8 | 8 | REM in your Path. | |
32 | 9 | echo Correct paths. | 9 | REM sed is available from: |
33 | 10 | xchangecl +d! ..\blogs\locales\messages.pot !D:\www\b2cvs20\blogs\!..\..\..\! | 10 | REM http://gnuwin32.sourceforge.net/packages/sed.htm |
34 | 11 | 11 | REM xgettext is available from: | |
35 | 12 | echo Correct Header. | 12 | REM http://gnuwin32.sourceforge.net/packages/gettext.htm |
36 | 13 | xchangecl +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"! | 13 | REM fart is available from: |
37 | 14 | 14 | REM http://fart-it.sourceforge.net/ | |
38 | 15 | echo Merge with French. | 15 | |
39 | 16 | msgmerge -U --no-wrap ..\blogs\locales\fr_FR\LC_MESSAGES\messages.po ..\blogs\locales\messages.pot | 16 | if /i "%1" equ "CORE" ( |
40 | 17 | 17 | goto MAIN | |
41 | 18 | REM echo Change comments. | 18 | ) else if /i "%1" equ "PLUGIN" ( |
42 | 19 | REM xchangecl +d! -t# ..\blogs\locales\fr_FR\LC_MESSAGES\messages.po !#35#.#32#TRANS:!#35##32#TRANS:! | 19 | goto MAIN |
43 | 20 | ) else ( | ||
44 | 21 | goto USAGE | ||
45 | 22 | ) | ||
46 | 23 | |||
47 | 24 | :MAIN | ||
48 | 25 | REM Generate file list, make paths relative, filter excluded directories | ||
49 | 26 | REM and extract strings: | ||
50 | 27 | dir /s /b *.php | fart -qi - "%CD%" . ^ | ||
51 | 28 | | findstr /r /i /v ^ | ||
52 | 29 | "^\.\\templates\\[^\\]*\\.* ^\.\\plugins\\.* ^\.\\build\\.*" ^ | ||
53 | 30 | | xgettext -f - -o locales\messages.pot --from-code=iso-8859-15 ^ | ||
54 | 31 | --no-wrap --add-comments=TRANS "--copyright-holder=The Quam Plures developers" ^ | ||
55 | 32 | --msgid-bugs-address=http://quamplures.net/ --keyword=T_ ^ | ||
56 | 33 | --keyword=NT_ --keyword=TS_ -F | ||
57 | 34 | |||
58 | 35 | REM Make paths relative: | ||
59 | 36 | sed -i "/^#: /{ s| \.| ..\\..\\..|g; }" locales\messages.pot | ||
60 | 37 | |||
61 | 38 | if /i "%1" equ "CORE" ( | ||
62 | 39 | REM Replace bulk header values with nicer ones. | ||
63 | 40 | REM TODO: Make app name and current year dynamic. Replace app version as in xg.php. | ||
64 | 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/; }" ^ | ||
65 | 42 | locales\messages.pot | ||
66 | 43 | ) | ||
67 | 44 | |||
68 | 45 | REM Delete temporary sed files (bug in gnuwin32 port): | ||
69 | 46 | del sed* | ||
70 | 47 | |||
71 | 48 | exit /b 0 | ||
72 | 49 | |||
73 | 50 | :USAGE | ||
74 | 51 | echo Usage: | ||
75 | 52 | echo ^ %0 ^<CORE^|PLUGIN^> | ||
76 | 53 | echo. | ||
77 | 54 | echo CORE : Work on the core application. | ||
78 | 55 | echo PLUGIN: Work on a plugin. | ||
79 | 56 | echo. | ||
80 | 57 | echo In both modes, you have to invoke this script in the application's | ||
81 | 58 | echo root directory or the directory which contains your plugin's PHP | ||
82 | 59 | echo file, respectively. | ||
83 | 60 | |||
84 | 61 | exit /b 1 | ||
85 | 20 | \ No newline at end of file | 62 | \ No newline at end of file |
86 | 21 | 63 | ||
87 | === modified file 'gettext/xg.php' | |||
88 | --- gettext/xg.php 2010-01-27 18:27:00 +0000 | |||
89 | +++ gettext/xg.php 2010-03-14 12:54:25 +0000 | |||
90 | @@ -4,11 +4,12 @@ | |||
91 | 4 | * Create a new messages.POT file and update specified .po files. | 4 | * Create a new messages.POT file and update specified .po files. |
92 | 5 | * | 5 | * |
93 | 6 | * Uses find, xargs, sed, xgettext and msgmerge tools. | 6 | * Uses find, xargs, sed, xgettext and msgmerge tools. |
94 | 7 | * This only works on UNIXoid systems. | ||
95 | 7 | * | 8 | * |
96 | 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/}. |
97 | 9 | * See also {@link https://launchpad.net/quam-plures}. | 10 | * See also {@link https://launchpad.net/quam-plures}. |
98 | 10 | * | 11 | * |
100 | 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/} |
101 | 12 | * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}. | 13 | * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}. |
102 | 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}. |
103 | 14 | * | 15 | * |
104 | @@ -18,70 +19,81 @@ | |||
105 | 18 | * Daniel HAHLER grants Francois PLANQUE the right to license | 19 | * Daniel HAHLER grants Francois PLANQUE the right to license |
106 | 19 | * Daniel HAHLER's contributions to this file and the b2evolution project | 20 | * Daniel HAHLER's contributions to this file and the b2evolution project |
107 | 20 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). | 21 | * under any OSI approved OSS license (http://www.opensource.org/licenses/). |
109 | 21 | * }} | 22 | * } |
110 | 22 | * | 23 | * |
111 | 23 | * @package internal | 24 | * @package internal |
112 | 24 | * | 25 | * |
114 | 25 | * @todo Add checks for format, headers and domain ("msgfmt -c") | 26 | * @todo Add checks for format, headers and domain ("msgfmt -c"). |
115 | 26 | * | 27 | * |
117 | 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:} |
118 | 28 | * @author blueyed: Daniel HAHLER. | 29 | * @author blueyed: Daniel HAHLER. |
120 | 29 | * | 30 | * @author Tblue: Tilman BLUMENBACH. |
121 | 30 | */ | 31 | */ |
122 | 31 | 32 | ||
137 | 32 | require_once dirname(__FILE__).'/../blogs/conf/_config.php'; | 33 | // Cache script base name: |
138 | 33 | 34 | $my_basename = basename( $argv[0] ); | |
139 | 34 | echo '** gettext helper tool for ', $app_name, ' **', "\n"; | 35 | // Set default application root directory: |
140 | 35 | 36 | $_app_root = dirname( __FILE__ ).'/../../trunk'; | |
127 | 36 | // Check that all external tools are available: | ||
128 | 37 | foreach( array( 'xgettext', 'msgmerge', 'find', 'xargs', 'sed' ) as $testtool ) | ||
129 | 38 | { | ||
130 | 39 | exec( $testtool.' --version', $output, $return ); | ||
131 | 40 | if( $return !== 0 ) | ||
132 | 41 | { | ||
133 | 42 | die( "This script needs the $testtool tool.\n" ); | ||
134 | 43 | } | ||
135 | 44 | } | ||
136 | 45 | |||
141 | 46 | 37 | ||
142 | 47 | function echo_usage() | 38 | function echo_usage() |
143 | 48 | { | 39 | { |
180 | 49 | global $argv, $app_name; | 40 | global $argv, $app_name, $my_basename, $_app_root; |
181 | 50 | 41 | ||
182 | 51 | echo "Usage: \n"; | 42 | echo 'Usage: ', "\n"; |
183 | 52 | echo basename($argv[0])." <CORE|CWD> [extract]\n"; | 43 | echo ' ', $my_basename, ' [-b <app_root>] <CORE|CWD> [extract]', "\n"; |
184 | 53 | echo basename($argv[0])." <CORE|CWD> merge <locale> [locale..]\n"; | 44 | echo ' ', $my_basename, ' [-b <app_root>] <CORE|CWD> merge <locale> [locale..]', "\n"; |
185 | 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"; |
186 | 55 | echo "CORE: work on the core application\n"; | 46 | echo 'CORE: work on the core application.', "\n"; |
187 | 56 | echo "CWD: work on current working directory\n"; | 47 | echo 'CWD : work on current working directory.', "\n"; |
188 | 57 | echo "\n"; | 48 | echo "\n"; |
189 | 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"; |
190 | 59 | echo "\n"; | 50 | echo "\n"; |
191 | 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"; |
192 | 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"; |
193 | 62 | echo "after having updated the messages.POT file, obviously.\n"; | 53 | echo 'after having updated the messages.POT file, obviously.', "\n"; |
194 | 63 | echo "\n"; | 54 | echo "\n"; |
195 | 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"; |
196 | 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"; |
197 | 66 | echo "\n"; | 57 | echo "\n"; |
198 | 67 | echo "E.g.,\n"; | 58 | echo 'E.g.:', "\n"; |
199 | 68 | echo " php -f xg.php CORE\n"; | 59 | echo ' php ', $my_basename, ' CORE', "\n"; |
200 | 69 | echo " php -f xg.php CORE merge de_DE\n"; | 60 | echo ' php ', $my_basename, ' CORE merge de_DE', "\n"; |
201 | 70 | echo " ..edit .po file..\n"; | 61 | echo ' ..edit .po file..', "\n"; |
202 | 71 | echo " php -f xg.php CORE convert de_DE\n"; | 62 | echo ' php ', $my_basename, ' CORE convert de_DE', "\n"; |
203 | 72 | echo "\n"; | 63 | echo "\n"; |
204 | 73 | } | 64 | echo 'This script expects the ', $app_name, ' root directory to be at [', $_app_root, '].', "\n"; |
205 | 74 | 65 | echo 'You can specify an alternative root directory using the -b option, e. g.:', "\n"; | |
206 | 75 | 66 | echo ' php ', $my_basename, ' -b ../blogs CORE', "\n"; | |
207 | 76 | if( ! isset($_SERVER['argc']) || ! isset( $_SERVER['argv'] ) ) | 67 | echo '...but if you are reading this message, the root directory is set correctly.', "\n"; |
208 | 77 | { | 68 | } |
209 | 78 | echo_usage(); | 69 | |
210 | 79 | exit(1); | 70 | |
211 | 80 | } | 71 | // Allow overriding of the application root directory via command line (-b option): |
212 | 81 | 72 | $opts = getopt( 'b:' ); | |
213 | 82 | 73 | if( isset( $opts['b'] ) ) | |
214 | 83 | $argc = $_SERVER['argc']; | 74 | { |
215 | 84 | $argv = $_SERVER['argv']; | 75 | $_app_root = $opts['b']; |
216 | 76 | |||
217 | 77 | // Silently modify $argc and $argv: | ||
218 | 78 | $argc -= 2; | ||
219 | 79 | // This will fail if somebody passes an argument with more than one | ||
220 | 80 | // option, e. g. "-bar". | ||
221 | 81 | array_splice( $argv, array_search( '-b', $argv ), 2 ); | ||
222 | 82 | |||
223 | 83 | //var_dump( $argc, $argv ); | ||
224 | 84 | } | ||
225 | 85 | |||
226 | 86 | if( ! is_dir( $_app_root ) ) | ||
227 | 87 | { | ||
228 | 88 | echo 'Error: Application root directory [', $_app_root, '] does not exist!', "\n"; | ||
229 | 89 | echo 'You can specify an alternative root directory by using the -b option:', "\n"; | ||
230 | 90 | echo ' php ', $my_basename, ' -b /path/to/application/root/directory CORE', "\n"; | ||
231 | 91 | exit( 2 ); | ||
232 | 92 | } | ||
233 | 93 | |||
234 | 94 | require_once $_app_root.'/conf/_config.php'; | ||
235 | 95 | |||
236 | 96 | echo '** gettext helper tool for ', $app_name, ' **', "\n\n"; | ||
237 | 85 | 97 | ||
238 | 86 | if( $argc < 2 ) | 98 | if( $argc < 2 ) |
239 | 87 | { | 99 | { |
240 | @@ -89,65 +101,66 @@ | |||
241 | 89 | exit(1); | 101 | exit(1); |
242 | 90 | } | 102 | } |
243 | 91 | 103 | ||
297 | 92 | if( strtoupper($argv[1]) == 'CORE' ) | 104 | switch( strtoupper($argv[1]) ) |
298 | 93 | { | 105 | { |
299 | 94 | echo "CORE mode..\n"; | 106 | case 'CORE': |
300 | 95 | $mode = 'CORE'; | 107 | echo 'CORE mode..', "\n"; |
301 | 96 | // The blogs directory: | 108 | $mode = 'CORE'; |
302 | 97 | $dir_root = dirname(__FILE__).'/../blogs/'; | 109 | // Our root directory is the application root directory: |
303 | 98 | } | 110 | $dir_root = $_app_root; |
304 | 99 | elseif( strtoupper($argv[1]) == 'CWD' ) | 111 | break; |
305 | 100 | { | 112 | |
306 | 101 | echo "Using current working directory..\n"; | 113 | case 'CWD': |
307 | 102 | $mode = 'CWD'; | 114 | echo 'Using current working directory..', "\n"; |
308 | 103 | $dir_root = getcwd(); | 115 | $mode = 'CWD'; |
309 | 104 | } | 116 | $dir_root = getcwd(); |
310 | 105 | else | 117 | break; |
311 | 106 | { | 118 | |
312 | 107 | echo_usage(); | 119 | default: |
313 | 108 | exit(1); | 120 | echo_usage(); |
314 | 109 | } | 121 | exit(1); |
315 | 110 | 122 | } | |
316 | 111 | if( ! isset($argv[2]) || strtoupper($argv[2]) == 'EXTRACT' ) | 123 | |
317 | 112 | { | 124 | $action = 'extract'; |
318 | 113 | $action = 'extract'; | 125 | if( isset($argv[2]) ) |
319 | 114 | } | 126 | { |
320 | 115 | elseif( isset($argv[2]) && strtoupper($argv[2]) == 'MERGE' ) | 127 | $action = strtolower( $argv[2] ); |
321 | 116 | { | 128 | |
322 | 117 | $action = 'merge'; | 129 | if( ! in_array( $action, array( 'extract', 'merge', 'convert' ) ) ) |
323 | 118 | 130 | { | |
324 | 119 | if( ! isset($argv[3]) ) // the to-get-merged locale | 131 | echo_usage(); |
325 | 120 | { | 132 | exit( 1 ); |
326 | 121 | echo_usage(); | 133 | } |
327 | 122 | exit(1); | 134 | else if( $action == 'convert' || $action == 'merge' ) |
328 | 123 | } | 135 | { |
329 | 124 | 136 | if( ! isset($argv[3]) ) | |
330 | 125 | $locales_to_merge = array_slice( $argv, 3 ); | 137 | { |
331 | 126 | } | 138 | echo_usage(); |
332 | 127 | elseif( isset($argv[2]) && strtoupper($argv[2]) == 'CONVERT' ) | 139 | exit(1); |
333 | 128 | { | 140 | } |
334 | 129 | $action = 'convert'; | 141 | |
335 | 130 | 142 | $_locales = array_slice( $argv, 3 ); | |
336 | 131 | if( ! isset($argv[3]) ) // the to-get-converted locale | 143 | } |
337 | 132 | { | 144 | } |
285 | 133 | echo_usage(); | ||
286 | 134 | exit(1); | ||
287 | 135 | } | ||
288 | 136 | |||
289 | 137 | $locales_to_convert = array_slice( $argv, 3 ); | ||
290 | 138 | } | ||
291 | 139 | else | ||
292 | 140 | { | ||
293 | 141 | echo_usage(); | ||
294 | 142 | die; | ||
295 | 143 | } | ||
296 | 144 | |||
338 | 145 | 145 | ||
339 | 146 | // ---- COMMON CHECKS: ---- | 146 | // ---- COMMON CHECKS: ---- |
340 | 147 | 147 | ||
344 | 148 | if( ! realpath($dir_root) ) | 148 | if( $action != 'convert' ) |
345 | 149 | { | 149 | { |
346 | 150 | die( "Fatal error: The path '$dir_root' was not found!\n" ); | 150 | // Check that all external tools are available: |
347 | 151 | foreach( array( 'xgettext', 'msgmerge', 'find', 'xargs', 'sed' ) as $testtool ) | ||
348 | 152 | { | ||
349 | 153 | exec( $testtool.' --version 2>/dev/null', $output, $return ); | ||
350 | 154 | if( $return == 127 ) | ||
351 | 155 | { // Command not found (return code specified by POSIX): | ||
352 | 156 | die( 'This script needs the '.$testtool.' tool.'."\n" ); | ||
353 | 157 | } | ||
354 | 158 | } | ||
355 | 159 | } | ||
356 | 160 | |||
357 | 161 | if( ! is_dir($dir_root) ) | ||
358 | 162 | { | ||
359 | 163 | die( 'Fatal error: The path ['.$dir_root.'] was not found!'."\n" ); | ||
360 | 151 | } | 164 | } |
361 | 152 | // Normalize path: | 165 | // Normalize path: |
362 | 153 | $dir_root = realpath($dir_root).'/'; | 166 | $dir_root = realpath($dir_root).'/'; |
363 | @@ -158,20 +171,19 @@ | |||
364 | 158 | // The messages.pot (template) file: | 171 | // The messages.pot (template) file: |
365 | 159 | $file_pot = $dir_root.'locales/messages.pot'; | 172 | $file_pot = $dir_root.'locales/messages.pot'; |
366 | 160 | 173 | ||
367 | 161 | |||
368 | 162 | if( $action == 'extract' ) | 174 | if( $action == 'extract' ) |
369 | 163 | { | 175 | { |
370 | 164 | if( ! is_writable($file_pot) ) | 176 | if( ! is_writable($file_pot) ) |
371 | 165 | { | 177 | { |
372 | 166 | if( ! file_exists( $dir_root.'locales' ) ) | 178 | if( ! file_exists( $dir_root.'locales' ) ) |
373 | 167 | { | 179 | { |
375 | 168 | echo "Directory {$dir_root}locales/ does not exist..\n"; | 180 | echo 'Directory [', $dir_root, 'locales/] does not exist..', "\n"; |
376 | 169 | 181 | ||
377 | 170 | if( ! mkdir( $dir_root.'locales' ) ) | 182 | if( ! mkdir( $dir_root.'locales' ) ) |
378 | 171 | { | 183 | { |
380 | 172 | die( "FATAL: could not create directory {$dir_root}locales/\n" ); | 184 | die( 'FATAL: could not create directory ['.$dir_root.'locales/]!'."\n" ); |
381 | 173 | } | 185 | } |
383 | 174 | echo "Created directory.\n"; | 186 | echo 'Created directory.', "\n"; |
384 | 175 | } | 187 | } |
385 | 176 | 188 | ||
386 | 177 | if( ! file_exists( $file_pot ) ) | 189 | if( ! file_exists( $file_pot ) ) |
387 | @@ -182,69 +194,89 @@ | |||
388 | 182 | 194 | ||
389 | 183 | if( ! is_writable($file_pot) ) | 195 | if( ! is_writable($file_pot) ) |
390 | 184 | { | 196 | { |
392 | 185 | die( "FATAL: The file $file_pot is not writable.\n" ); | 197 | die( 'FATAL: The file ['.$file_pot.'] is not writable.'."\n" ); |
393 | 186 | } | 198 | } |
394 | 187 | } | 199 | } |
395 | 188 | 200 | ||
399 | 189 | // The locales dir is our working dir: | 201 | $dir_root_basename = basename($dir_root); |
397 | 190 | # chdir( $dir_root.'locales' ); | ||
398 | 191 | |||
400 | 192 | if( isset($argv[3]) ) | 202 | if( isset($argv[3]) ) |
401 | 193 | { // File(s) specified | 203 | { // File(s) specified |
402 | 204 | echo 'Extracting T_() and NT_() strings from given files below "'; | ||
403 | 205 | echo $dir_root_basename, '" into "', $dir_root_basename, '/locales/messages.pot".. '; | ||
404 | 194 | $cmd = ''; | 206 | $cmd = ''; |
405 | 195 | echo 'Extracting T_() and NT_() strings from given files below "'.basename($dir_root).'" into "'.basename($dir_root).'/locales/messages.pot".. '; | ||
406 | 196 | } | 207 | } |
407 | 197 | else | 208 | else |
408 | 198 | { | 209 | { |
412 | 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 "'; |
413 | 200 | # find *.php files, but not in "build" directory: | 211 | echo $dir_root_basename, '" into "', $dir_root_basename, '/locales/messages.pot".. '; |
414 | 201 | $cmd = 'find '.escapeshellarg($dir_root).' -wholename "*/build/*" -prune -o \( -iname "*.php" -print \) | xargs '; | 212 | |
415 | 213 | // Change working dir (to simplify exlude patterns below): | ||
416 | 214 | chdir( $dir_root ); | ||
417 | 215 | |||
418 | 216 | /* Find *.php files, but exclude: | ||
419 | 217 | * - all directories below templates/ | ||
420 | 218 | * - the plugins/ directory | ||
421 | 219 | * - the build/ directory | ||
422 | 220 | */ | ||
423 | 221 | $cmd = 'find . \\( '; | ||
424 | 222 | $cmd .= '-path \'./templates/*[!/]/*\' -o -path \'./plugins/*\' -o -path \'./build/*\''; | ||
425 | 223 | $cmd .= ' \\) -prune -o \\( -iname \'*.php\' -print0 \\) | xargs -0 '; | ||
426 | 202 | } | 224 | } |
428 | 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'; |
429 | 204 | 226 | ||
430 | 205 | // Append filenames, if specified: | 227 | // Append filenames, if specified: |
431 | 206 | if( isset($argv[3]) ) | 228 | if( isset($argv[3]) ) |
432 | 207 | { | 229 | { |
434 | 208 | for( $i = 3; $i < count($argv); $i++ ) | 230 | $n = count($argv); |
435 | 231 | for( $i = 3; $i < $n; $i++ ) | ||
436 | 209 | { | 232 | { |
437 | 210 | $cmd .= ' '.escapeshellarg($argv[$i]); | 233 | $cmd .= ' '.escapeshellarg($argv[$i]); |
438 | 211 | } | 234 | } |
439 | 212 | } | 235 | } |
440 | 213 | 236 | ||
441 | 237 | //echo 'Command: [', $cmd, ']', "\n"; | ||
442 | 214 | system( $cmd, $return_var ); | 238 | system( $cmd, $return_var ); |
443 | 215 | if( $return_var !== 0 ) | 239 | if( $return_var !== 0 ) |
444 | 216 | { | 240 | { |
446 | 217 | die("Failed!\n"); | 241 | die('Command failed (return code: '.$return_var.')!'."\n"); |
447 | 218 | } | 242 | } |
448 | 219 | echo "[ok]\n"; | 243 | echo "[ok]\n"; |
449 | 220 | 244 | ||
450 | 221 | 245 | ||
451 | 222 | // Replace various things (see comments) | 246 | // Replace various things (see comments) |
453 | 223 | echo 'Automagically search&replace in messages.pot.. '; | 247 | echo 'Automagically search & replace in messages.pot.. '; |
454 | 224 | $data = file_get_contents( $file_pot ); | 248 | $data = file_get_contents( $file_pot ); |
455 | 225 | 249 | ||
456 | 226 | $data = str_replace( "\r", '', $data ); | 250 | $data = str_replace( "\r", '', $data ); |
457 | 227 | // Make paths relative: | 251 | // Make paths relative: |
459 | 228 | $data = preg_replace( '~^#: .*$~me', 'str_replace( \' '.$dir_root.'\', \' ../../../\', \'$0\' )', $data ); | 252 | |
460 | 253 | if( isset( $argv[3] ) ) | ||
461 | 254 | { // File names given | ||
462 | 255 | $rep_path = $dir_root; | ||
463 | 256 | } | ||
464 | 257 | else | ||
465 | 258 | { // Core mode (prepend root path to file names in POT file): | ||
466 | 259 | $rep_path = ''; | ||
467 | 260 | } | ||
468 | 261 | $data = preg_replace( '~^#: .*$~me', 'str_replace( \' '.$rep_path.'\', \' ../../../\', \'$0\' )', $data ); | ||
469 | 229 | 262 | ||
470 | 230 | file_put_contents( $file_pot, $data ); | 263 | file_put_contents( $file_pot, $data ); |
471 | 231 | 264 | ||
472 | 232 | if( $mode == 'CORE' ) | 265 | if( $mode == 'CORE' ) |
473 | 233 | { // Replace header "vars" in first 20 lines: | 266 | { // Replace header "vars" in first 20 lines: |
475 | 234 | system( 'sed -i 1,20"' | 267 | system( 'sed -i "1,20{' |
476 | 235 | .'s/PACKAGE/'.$app_name.'/;' | 268 | .'s/PACKAGE/'.$app_name.'/;' |
477 | 236 | .'s/VERSION/'.$app_version.'/;' | 269 | .'s/VERSION/'.$app_version.'/;' |
478 | 237 | .'s/# SOME DESCRIPTIVE TITLE./# '.$app_name.' - Language file/;' | 270 | .'s/# SOME DESCRIPTIVE TITLE./# '.$app_name.' - Language file/;' |
481 | 238 | .'s/(C) YEAR/(C) 2003-'.date('Y').'/;' | 271 | .'s/(C) YEAR/(C) 2009-'.date('Y').'/;' |
480 | 239 | .'s/YEAR(?!-MO)/'.date('Y').'/;' | ||
482 | 240 | .'s/CHARSET/iso-8859-1/;' | 272 | .'s/CHARSET/iso-8859-1/;' |
484 | 241 | .'" '.escapeshellarg($file_pot) ); | 273 | .'}" '.escapeshellarg($file_pot) ); |
485 | 242 | } | 274 | } |
486 | 243 | else | 275 | else |
487 | 244 | { | 276 | { |
488 | 245 | // TODO: try to detect usage with a plugin and s&r accordingly | 277 | // TODO: try to detect usage with a plugin and s&r accordingly |
489 | 246 | } | 278 | } |
491 | 247 | echo "[ok]\n"; | 279 | echo '[ok]', "\n"; |
492 | 248 | 280 | ||
493 | 249 | exit(0); | 281 | exit(0); |
494 | 250 | } | 282 | } |
495 | @@ -254,11 +286,11 @@ | |||
496 | 254 | { // Merge with existing .po files: | 286 | { // Merge with existing .po files: |
497 | 255 | if( ! @is_readable( $file_pot ) ) | 287 | if( ! @is_readable( $file_pot ) ) |
498 | 256 | { | 288 | { |
500 | 257 | echo "FATAL: $file_pot is not readable!\n"; | 289 | echo 'FATAL: [', $file_pot, '] is not readable!', "\n"; |
501 | 258 | exit(1); | 290 | exit(1); |
502 | 259 | } | 291 | } |
503 | 260 | 292 | ||
505 | 261 | foreach( $locales_to_merge as $l_locale ) | 293 | foreach( $_locales as $l_locale ) |
506 | 262 | { | 294 | { |
507 | 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'; |
508 | 264 | 296 | ||
509 | @@ -266,14 +298,14 @@ | |||
510 | 266 | 298 | ||
511 | 267 | if( ! file_exists( $l_file_po ) ) | 299 | if( ! file_exists( $l_file_po ) ) |
512 | 268 | { | 300 | { |
514 | 269 | echo "PO file $l_file_po not found!\n"; | 301 | echo 'PO file [', $l_file_po, '] not found!', "\n"; |
515 | 270 | continue; | 302 | continue; |
516 | 271 | } | 303 | } |
517 | 272 | 304 | ||
518 | 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) ); |
519 | 274 | # delete old TRANS comments and make automatic ones valid comments: | 306 | # delete old TRANS comments and make automatic ones valid comments: |
520 | 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 ); |
522 | 276 | echo "Written $l_file_po .\n"; | 308 | echo 'Written [', $l_file_po, '].', "\n"; |
523 | 277 | echo "\n"; | 309 | echo "\n"; |
524 | 278 | } | 310 | } |
525 | 279 | 311 | ||
526 | @@ -283,9 +315,9 @@ | |||
527 | 283 | 315 | ||
528 | 284 | if( $action == 'convert' ) | 316 | if( $action == 'convert' ) |
529 | 285 | { // convert messages.PO files to _global.php | 317 | { // convert messages.PO files to _global.php |
531 | 286 | require_once dirname(__FILE__).'/../blogs/inc/locales/_pofile.class.php'; | 318 | require_once $_app_root.'/inc/locales/_pofile.class.php'; |
532 | 287 | 319 | ||
534 | 288 | foreach( $locales_to_convert as $l_locale ) | 320 | foreach( $_locales as $l_locale ) |
535 | 289 | { | 321 | { |
536 | 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'; |
537 | 291 | $global_file_path = $dir_root.'locales/'.$l_locale.'/_global.php'; | 323 | $global_file_path = $dir_root.'locales/'.$l_locale.'/_global.php'; |
538 | @@ -294,7 +326,7 @@ | |||
539 | 294 | 326 | ||
540 | 295 | if( !file_exists( $l_file_po ) ) | 327 | if( !file_exists( $l_file_po ) ) |
541 | 296 | { | 328 | { |
543 | 297 | echo "PO file $l_file_po not found!\n"; | 329 | echo 'PO file [', $l_file_po, '] not found!', "\n"; |
544 | 298 | continue; | 330 | continue; |
545 | 299 | } | 331 | } |
546 | 300 | 332 | ||
547 | @@ -304,63 +336,12 @@ | |||
548 | 304 | 336 | ||
549 | 305 | if( $r !== true ) | 337 | if( $r !== true ) |
550 | 306 | { | 338 | { |
552 | 307 | echo "Error: $r\n"; | 339 | echo 'Error: ', $r, "\n"; |
553 | 308 | continue; | 340 | continue; |
554 | 309 | } | 341 | } |
555 | 310 | 342 | ||
557 | 311 | echo "[ok]\n"; | 343 | echo '[ok]', "\n"; |
558 | 312 | } | 344 | } |
559 | 313 | 345 | ||
560 | 314 | exit(0); | 346 | exit(0); |
561 | 315 | } | 347 | } |
562 | 316 | |||
563 | 317 | |||
564 | 318 | /** | ||
565 | 319 | * From {@link http://de.php.net/manual/en/function.realpath.php#77203} | ||
566 | 320 | */ | ||
567 | 321 | function rel_path($dest, $root = '') | ||
568 | 322 | { | ||
569 | 323 | $root = explode(DIRECTORY_SEPARATOR, $root); | ||
570 | 324 | $dest = explode(DIRECTORY_SEPARATOR, $dest); | ||
571 | 325 | $path = '.'; | ||
572 | 326 | $fix = ''; | ||
573 | 327 | $diff = 0; | ||
574 | 328 | for($i = -1; ++$i < max(($rC = count($root)), ($dC = count($dest)));) | ||
575 | 329 | { | ||
576 | 330 | if(isset($root[$i]) and isset($dest[$i])) | ||
577 | 331 | { | ||
578 | 332 | if($diff) | ||
579 | 333 | { | ||
580 | 334 | $path .= DIRECTORY_SEPARATOR. '..'; | ||
581 | 335 | $fix .= DIRECTORY_SEPARATOR. $dest[$i]; | ||
582 | 336 | continue; | ||
583 | 337 | } | ||
584 | 338 | if($root[$i] != $dest[$i]) | ||
585 | 339 | { | ||
586 | 340 | $diff = 1; | ||
587 | 341 | $path .= DIRECTORY_SEPARATOR. '..'; | ||
588 | 342 | $fix .= DIRECTORY_SEPARATOR. $dest[$i]; | ||
589 | 343 | continue; | ||
590 | 344 | } | ||
591 | 345 | } | ||
592 | 346 | elseif(!isset($root[$i]) and isset($dest[$i])) | ||
593 | 347 | { | ||
594 | 348 | for($j = $i-1; ++$j < $dC;) | ||
595 | 349 | { | ||
596 | 350 | $fix .= DIRECTORY_SEPARATOR. $dest[$j]; | ||
597 | 351 | } | ||
598 | 352 | break; | ||
599 | 353 | } | ||
600 | 354 | elseif(isset($root[$i]) and !isset($dest[$i])) | ||
601 | 355 | { | ||
602 | 356 | for($j = $i-1; ++$j < $rC;) | ||
603 | 357 | { | ||
604 | 358 | $fix = DIRECTORY_SEPARATOR. '..'. $fix; | ||
605 | 359 | } | ||
606 | 360 | break; | ||
607 | 361 | } | ||
608 | 362 | } | ||
609 | 363 | return $path. $fix; | ||
610 | 364 | } | ||
611 | 365 | |||
612 | 366 | ?> |
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.