4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Abort if called from a web server
22 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
23 print "This script must be run from the command line\n";
27 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
29 function update_core($dir, $domain)
36 --default-domain=$domain \
37 --output=locale/$domain.po \
40 --keyword="pgettext:1c,2" \
41 --keyword="npgettext:1c,2,3" \
51 function do_update_plugin($dir, $domain)
55 if (!file_exists('locale')) {
58 $files = get_plugin_sources(".");
62 --default-domain=$domain \
63 --output=locale/$domain.po \
67 --keyword="_m:1c,2,2t" \
68 --keyword="_m:1,2,3t" \
69 --keyword="_m:1c,2,3,4t" \
72 foreach ($files as $file) {
73 $cmd .= ' ' . escapeshellarg($file);
79 function do_translatewiki_plugin($basedir, $plugin)
81 $yamldir = "$basedir/locale/TranslateWiki";
82 if (!file_exists($yamldir)) {
85 $outfile = "$yamldir/StatusNet-{$plugin}.yml";
86 $pluginlc = strtolower( $plugin );
90 id: out-statusnet-{$pluginlc}
91 label: StatusNet - {$plugin}
92 description: "{{int:bw-desc-statusnet-plugin-{$pluginlc}}}"
93 namespace: NS_STATUSNET
94 display: out/statusnet/{$pluginlc}
95 class: GettextMessageGroup
99 sourcePattern: %GROUPROOT%/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
100 targetPattern: plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
115 file_put_contents($outfile, $data);
118 function get_plugins($dir)
121 $dirs = new DirectoryIterator("$dir/plugins");
122 foreach ($dirs as $item) {
123 if ($item->isDir() && !$item->isDot()) {
124 $name = $item->getBasename();
125 if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
133 function get_plugin_sources($dir)
137 $dirs = new RecursiveDirectoryIterator($dir);
138 $iter = new RecursiveIteratorIterator($dirs);
139 foreach ($iter as $pathname => $item) {
140 if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
141 $files[] = $pathname;
147 function plugin_using_gettext($dir)
149 $files = get_plugin_sources($dir);
150 foreach ($files as $pathname) {
151 // Check if the file is using our _m gettext wrapper
152 $code = file_get_contents($pathname);
153 if (preg_match('/\b_m\(/', $code)) {
161 function update_plugin($basedir, $name)
163 $dir = "$basedir/plugins/$name";
164 if (plugin_using_gettext($dir)) {
165 do_update_plugin($dir, $name);
166 do_translatewiki_plugin($basedir, $name);
173 $args = $_SERVER['argv'];
180 if (count($args) == 0) {
183 foreach ($args as $arg) {
184 if ($arg == '--all') {
186 } elseif ($arg == "--core") {
188 } elseif ($arg == "--plugins") {
190 } elseif (substr($arg, 0, 9) == "--plugin=") {
191 $plugins[] = substr($arg, 9);
192 } elseif ($arg == '--help') {
193 echo "options: --all --core --plugins --plugin=Foo\n\n";
202 update_core(INSTALLDIR, 'statusnet');
205 if ($all || $allplugins) {
206 $plugins = get_plugins(INSTALLDIR);
209 foreach ($plugins as $plugin) {
211 if (update_plugin(INSTALLDIR, $plugin)) {
214 echo " not localized\n";