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";
86 id: out-statusnet-{$plugin}
87 label: StatusNet - {$plugin}
88 description: "{{int:bw-desc-statusnet-plugin-{$plugin}}}"
89 namespace: NS_STATUSNET
90 display: out/statusnet/{$plugin}
91 class: GettextMessageGroup
95 sourcePattern: %GROUPROOT%/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
96 targetPattern: {$plugin}.po
111 file_put_contents($outfile, $data);
114 function get_plugins($dir)
117 $dirs = new DirectoryIterator("$dir/plugins");
118 foreach ($dirs as $item) {
119 if ($item->isDir() && !$item->isDot()) {
120 $name = $item->getBasename();
121 if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
129 function get_plugin_sources($dir)
133 $dirs = new RecursiveDirectoryIterator($dir);
134 $iter = new RecursiveIteratorIterator($dirs);
135 foreach ($iter as $pathname => $item) {
136 if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
137 $files[] = $pathname;
143 function plugin_using_gettext($dir)
145 $files = get_plugin_sources($dir);
146 foreach ($files as $pathname) {
147 // Check if the file is using our _m gettext wrapper
148 $code = file_get_contents($pathname);
149 if (preg_match('/\b_m\(/', $code)) {
157 function update_plugin($basedir, $name)
159 $dir = "$basedir/plugins/$name";
160 if (plugin_using_gettext($dir)) {
161 do_update_plugin($dir, $name);
162 do_translatewiki_plugin($basedir, $name);
169 $args = $_SERVER['argv'];
176 if (count($args) == 0) {
179 foreach ($args as $arg) {
180 if ($arg == '--all') {
182 } elseif ($arg == "--core") {
184 } elseif ($arg == "--plugins") {
186 } elseif (substr($arg, 0, 9) == "--plugin=") {
187 $plugins[] = substr($arg, 9);
195 update_core(INSTALLDIR, 'statusnet');
198 if ($all || $allplugins) {
199 $plugins = get_plugins(INSTALLDIR);
202 foreach ($plugins as $plugin) {
204 if (update_plugin(INSTALLDIR, $plugin)) {
207 echo " not localized\n";