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.pot \
39 --add-comments=TRANS \
41 --keyword="_m:1c,2,2t" \
42 --keyword="_m:1,2,3t" \
43 --keyword="_m:1c,2,3,4t" \
44 --keyword="pgettext:1c,2" \
45 --keyword="npgettext:1c,2,3" \
55 function do_update_plugin($dir, $domain)
59 if (!file_exists('locale')) {
62 $files = get_plugin_sources(".");
66 --default-domain=$domain \
67 --output=locale/$domain.pot \
69 --add-comments=TRANS \
72 --keyword="_m:1c,2,2t" \
73 --keyword="_m:1,2,3t" \
74 --keyword="_m:1c,2,3,4t" \
77 foreach ($files as $file) {
78 $cmd .= ' ' . escapeshellarg($file);
84 function do_translatewiki_plugin($basedir, $plugin)
86 $yamldir = "$basedir/locale/TranslateWiki";
87 if (!file_exists($yamldir)) {
90 $outfile = "$yamldir/StatusNet-{$plugin}.yml";
91 $pluginlc = strtolower( $plugin );
95 id: out-statusnet-{$pluginlc}
96 label: StatusNet - {$plugin}
97 namespace: NS_STATUSNET
98 description: "{{int:bw-desc-statusnet-plugin}}"
99 class: FileBasedMessageGroup
100 display: out/statusnet/{$pluginlc}
104 sourcePattern: %GROUPROOT%/statusnet/plugins/{$plugin}/locale/{$plugin}.pot
105 targetPattern: statusnet/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
120 file_put_contents($outfile, $data);
123 function get_plugins($dir)
126 $dirs = new DirectoryIterator("$dir/plugins");
127 foreach ($dirs as $item) {
128 if ($item->isDir() && !$item->isDot()) {
129 $name = $item->getBasename();
130 if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
138 function get_plugin_sources($dir)
142 $dirs = new RecursiveDirectoryIterator($dir);
143 $iter = new RecursiveIteratorIterator($dirs);
144 foreach ($iter as $pathname => $item) {
145 if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
146 $files[] = $pathname;
152 function plugin_using_gettext($dir)
154 $files = get_plugin_sources($dir);
155 foreach ($files as $pathname) {
156 // Check if the file is using our _m gettext wrapper
157 $code = file_get_contents($pathname);
158 if (preg_match('/\b_m\(/', $code)) {
166 function update_plugin($basedir, $name)
168 $dir = "$basedir/plugins/$name";
169 if (plugin_using_gettext($dir)) {
170 do_update_plugin($dir, $name);
171 do_translatewiki_plugin($basedir, $name);
178 $args = $_SERVER['argv'];
185 if (count($args) == 0) {
188 foreach ($args as $arg) {
189 if ($arg == '--all') {
191 } elseif ($arg == "--core") {
193 } elseif ($arg == "--plugins") {
195 } elseif (substr($arg, 0, 9) == "--plugin=") {
196 $plugins[] = substr($arg, 9);
197 } elseif ($arg == '--help') {
198 echo "options: --all --core --plugins --plugin=Foo\n\n";
207 update_core(INSTALLDIR, 'statusnet');
210 if ($all || $allplugins) {
211 $plugins = get_plugins(INSTALLDIR);
214 foreach ($plugins as $plugin) {
216 if (update_plugin(INSTALLDIR, $plugin)) {
219 echo " not localized\n";