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', dirname(__DIR__));
28 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
30 function update_core($dir, $domain)
37 --default-domain=$domain \
38 --output=locale/$domain.pot \
40 --add-comments=TRANS \
42 --keyword="_m:1c,2,2t" \
43 --keyword="_m:1,2,3t" \
44 --keyword="_m:1c,2,3,4t" \
45 --keyword="pgettext:1c,2" \
46 --keyword="npgettext:1c,2,3" \
57 function do_update_plugin($dir, $domain)
61 if (!file_exists('locale')) {
64 $files = get_plugin_sources(".");
68 --default-domain=$domain \
69 --output=locale/$domain.pot \
71 --add-comments=TRANS \
74 --keyword="_m:1c,2,2t" \
75 --keyword="_m:1,2,3t" \
76 --keyword="_m:1c,2,3,4t" \
79 foreach ($files as $file) {
80 $cmd .= ' ' . escapeshellarg($file);
86 function get_plugins($dir)
89 $dirs = new DirectoryIterator("$dir/plugins");
90 foreach ($dirs as $item) {
91 if ($item->isDir() && !$item->isDot()) {
92 $name = $item->getBasename();
93 if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
101 function get_plugin_sources($dir)
105 $dirs = new RecursiveDirectoryIterator($dir);
106 $iter = new RecursiveIteratorIterator($dirs);
107 foreach ($iter as $pathname => $item) {
108 if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
109 $files[] = $pathname;
115 function plugin_using_gettext($dir)
117 $files = get_plugin_sources($dir);
118 foreach ($files as $pathname) {
119 // Check if the file is using our _m gettext wrapper
120 $code = file_get_contents($pathname);
121 if (preg_match('/\b_m\(/', $code)) {
129 function update_plugin($basedir, $name)
131 $dir = "$basedir/plugins/$name";
132 if (plugin_using_gettext($dir)) {
133 do_update_plugin($dir, $name);
140 $args = $_SERVER['argv'];
147 if (count($args) == 0) {
150 foreach ($args as $arg) {
151 if ($arg == '--all') {
153 } elseif ($arg == "--core") {
155 } elseif ($arg == "--plugins") {
157 } elseif (substr($arg, 0, 9) == "--plugin=") {
158 $plugins[] = substr($arg, 9);
159 } elseif ($arg == '--help') {
160 echo "options: --all --core --plugins --plugin=Foo\n\n";
167 update_core(INSTALLDIR, 'statusnet');
170 if ($all || $allplugins) {
171 $plugins = get_plugins(INSTALLDIR);
174 foreach ($plugins as $plugin) {
176 if (update_plugin(INSTALLDIR, $plugin)) {
179 echo " not localized\n";