123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- #!/usr/bin/env php
- <?php
- /*
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // Abort if called from a web server
- if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
- }
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR);
- function update_core($dir, $domain)
- {
- $old = getcwd();
- chdir($dir);
- passthru(<<<END
- xgettext \
- --from-code=UTF-8 \
- --default-domain=$domain \
- --output=locale/$domain.pot \
- --language=PHP \
- --add-comments=TRANS \
- --keyword="_m:1,1t" \
- --keyword="_m:1c,2,2t" \
- --keyword="_m:1,2,3t" \
- --keyword="_m:1c,2,3,4t" \
- --keyword="pgettext:1c,2" \
- --keyword="npgettext:1c,2,3" \
- public/index.php \
- actions/*.php \
- classes/*.php \
- lib/*.php \
- scripts/*.php
- END
- );
- chdir($old);
- }
- function do_update_module($dir, $domain)
- {
- $old = getcwd();
- chdir($dir);
- if (!file_exists('locale')) {
- mkdir('locale');
- }
- $files = get_module_sources(".");
- $cmd = <<<END
- xgettext \
- --from-code=UTF-8 \
- --default-domain=$domain \
- --output=locale/$domain.pot \
- --language=PHP \
- --add-comments=TRANS \
- --keyword='' \
- --keyword="_m:1,1t" \
- --keyword="_m:1c,2,2t" \
- --keyword="_m:1,2,3t" \
- --keyword="_m:1c,2,3,4t" \
- END;
- foreach ($files as $file) {
- $cmd .= ' ' . escapeshellarg($file);
- }
- passthru($cmd);
- chdir($old);
- }
- function do_update_plugin($dir, $domain)
- {
- $old = getcwd();
- chdir($dir);
- if (!file_exists('locale')) {
- mkdir('locale');
- }
- $files = get_plugin_sources(".");
- $cmd = <<<END
- xgettext \
- --from-code=UTF-8 \
- --default-domain=$domain \
- --output=locale/$domain.pot \
- --language=PHP \
- --add-comments=TRANS \
- --keyword='' \
- --keyword="_m:1,1t" \
- --keyword="_m:1c,2,2t" \
- --keyword="_m:1,2,3t" \
- --keyword="_m:1c,2,3,4t" \
- END;
- foreach ($files as $file) {
- $cmd .= ' ' . escapeshellarg($file);
- }
- passthru($cmd);
- chdir($old);
- }
- function get_modules($dir)
- {
- $plugins = array();
- $dirs = new DirectoryIterator("$dir/modules");
- foreach ($dirs as $item) {
- if ($item->isDir() && !$item->isDot()) {
- $name = $item->getBasename();
- if (file_exists("$dir/modules/$name/{$name}Module.php")) {
- $plugins[] = $name;
- }
- }
- }
- return $plugins;
- }
- function get_plugins($dir)
- {
- $plugins = array();
- $dirs = new DirectoryIterator("$dir/plugins");
- foreach ($dirs as $item) {
- if ($item->isDir() && !$item->isDot()) {
- $name = $item->getBasename();
- if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
- $plugins[] = $name;
- }
- }
- }
- return $plugins;
- }
- function get_module_sources($dir)
- {
- $files = array();
- $dirs = new RecursiveDirectoryIterator($dir);
- $iter = new RecursiveIteratorIterator($dirs);
- foreach ($iter as $pathname => $item) {
- if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
- $files[] = $pathname;
- }
- }
- return $files;
- }
- function get_plugin_sources($dir)
- {
- $files = array();
- $dirs = new RecursiveDirectoryIterator($dir);
- $iter = new RecursiveIteratorIterator($dirs);
- foreach ($iter as $pathname => $item) {
- if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
- $files[] = $pathname;
- }
- }
- return $files;
- }
- function module_using_gettext($dir)
- {
- $files = get_module_sources($dir);
- foreach ($files as $pathname) {
- // Check if the file is using our _m gettext wrapper
- $code = file_get_contents($pathname);
- if (preg_match('/\b_m\(/', $code)) {
- return true;
- }
- }
- return false;
- }
- function plugin_using_gettext($dir)
- {
- $files = get_plugin_sources($dir);
- foreach ($files as $pathname) {
- // Check if the file is using our _m gettext wrapper
- $code = file_get_contents($pathname);
- if (preg_match('/\b_m\(/', $code)) {
- return true;
- }
- }
- return false;
- }
- function update_module($basedir, $name)
- {
- $dir = "$basedir/modules/$name";
- if (module_using_gettext($dir)) {
- do_update_module($dir, $name);
- return true;
- } else {
- return false;
- }
- }
- function update_plugin($basedir, $name)
- {
- $dir = "$basedir/plugins/$name";
- if (plugin_using_gettext($dir)) {
- do_update_plugin($dir, $name);
- return true;
- } else {
- return false;
- }
- }
- $args = $_SERVER['argv'];
- array_shift($args);
- $all = false;
- $core = false;
- $allmodules = false;
- $modules = array();
- $allplugins = false;
- $plugins = array();
- if (count($args) == 0) {
- $all = true;
- }
- foreach ($args as $arg) {
- if ($arg == '--all') {
- $all = true;
- } elseif ($arg == "--core") {
- $core = true;
- } elseif ($arg == "--modules") {
- $allmodules = true;
- } elseif ($arg == "--plugins") {
- $allplugins = true;
- } elseif (substr($arg, 0, 9) == "--module=") {
- $modules[] = substr($arg, 9);
- } elseif (substr($arg, 0, 9) == "--plugin=") {
- $plugins[] = substr($arg, 9);
- } elseif ($arg == '--help') {
- echo "options: --all --core --plugins --plugin=Foo --modules --module=Foo\n\n";
- exit(0);
- }
- }
- if ($all || $core) {
- echo "core...";
- update_core(INSTALLDIR, 'statusnet');
- echo " ok\n";
- }
- if ($all || $allmodules) {
- $plugins = get_modules(INSTALLDIR);
- }
- if ($all || $allplugins) {
- $plugins = get_plugins(INSTALLDIR);
- }
- if ($modules) {
- foreach ($modules as $module) {
- echo "$module...";
- if (update_module(INSTALLDIR, $plugin)) {
- echo " ok\n";
- } else {
- echo " not localized\n";
- }
- }
- }
- if ($plugins) {
- foreach ($plugins as $plugin) {
- echo "$plugin...";
- if (update_plugin(INSTALLDIR, $plugin)) {
- echo " ok\n";
- } else {
- echo " not localized\n";
- }
- }
- }
|