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 \
69 foreach ($files as $file) {
70 $cmd .= ' ' . escapeshellarg($file);
76 function do_translatewiki_plugin($basedir, $plugin)
78 $yamldir = "$basedir/locale/TranslateWiki";
79 if (!file_exists($yamldir)) {
82 $outfile = "$yamldir/StatusNet-{$plugin}.yml";
83 $pluginlc = strtolower( $plugin );
87 id: out-statusnet-{$pluginlc}
88 label: StatusNet - {$plugin}
89 description: "{{int:bw-desc-statusnet-plugin-{$pluginlc}}}"
90 namespace: NS_STATUSNET
91 display: out/statusnet/{$pluginlc}
92 class: GettextMessageGroup
96 sourcePattern: %GROUPROOT%/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
97 targetPattern: plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
112 file_put_contents($outfile, $data);
115 function get_plugins($dir)
118 $dirs = new DirectoryIterator("$dir/plugins");
119 foreach ($dirs as $item) {
120 if ($item->isDir() && !$item->isDot()) {
121 $name = $item->getBasename();
122 if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
130 function get_plugin_sources($dir)
134 $dirs = new RecursiveDirectoryIterator($dir);
135 $iter = new RecursiveIteratorIterator($dirs);
136 foreach ($iter as $pathname => $item) {
137 if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
138 $files[] = $pathname;
144 function plugin_using_gettext($dir)
146 $files = get_plugin_sources($dir);
147 foreach ($files as $pathname) {
148 // Check if the file is using our _m gettext wrapper
149 $code = file_get_contents($pathname);
150 if (preg_match('/\b_m\(/', $code)) {
158 function update_plugin($basedir, $name)
160 $dir = "$basedir/plugins/$name";
161 if (plugin_using_gettext($dir)) {
162 do_update_plugin($dir, $name);
163 do_translatewiki_plugin($basedir, $name);
170 $args = $_SERVER['argv'];
177 if (count($args) == 0) {
180 foreach ($args as $arg) {
181 if ($arg == '--all') {
183 } elseif ($arg == "--core") {
185 } elseif ($arg == "--plugins") {
187 } elseif (substr($arg, 0, 9) == "--plugin=") {
188 $plugins[] = substr($arg, 9);
196 update_core(INSTALLDIR, 'statusnet');
199 if ($all || $allplugins) {
200 $plugins = get_plugins(INSTALLDIR);
203 foreach ($plugins as $plugin) {
205 if (update_plugin(INSTALLDIR, $plugin)) {
208 echo " not localized\n";