From 4b5e977a7b1c390555d880d3dc7f8b8c6744646c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 8 Dec 2009 12:17:11 -0800 Subject: New _m() gettext wrapper with smart detection of plugin domains. Plugin base class registers your gettext files if present at initialization. update_pot.sh replaced with update_po_templates.php which can do core, plugins, or all (default). Top-level Makefile added to build .mo files for plugins as well as core. As described on list: http://lists.status.net/pipermail/statusnet-dev/2009-December/002869.html --- scripts/update_po_templates.php | 211 ++++++++++++++++++++++++++++++++++++++++ scripts/update_pot.sh | 13 --- 2 files changed, 211 insertions(+), 13 deletions(-) create mode 100755 scripts/update_po_templates.php delete mode 100755 scripts/update_pot.sh (limited to 'scripts') diff --git a/scripts/update_po_templates.php b/scripts/update_po_templates.php new file mode 100755 index 000000000..83bff6d80 --- /dev/null +++ b/scripts/update_po_templates.php @@ -0,0 +1,211 @@ +#!/usr/bin/env php +. + */ + +// 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', realpath(dirname(__FILE__) . '/..')); + +function update_core($dir, $domain) +{ + $old = getcwd(); + chdir($dir); + passthru(<<isDir() && !$item->isDot()) { + $name = $item->getBasename(); + if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) { + $plugins[] = $name; + } + } + } + return $plugins; +} + +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 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_plugin($basedir, $name) +{ + $dir = "$basedir/plugins/$name"; + if (plugin_using_gettext($dir)) { + do_update_plugin($dir, $name); + do_translatewiki_plugin($basedir, $name); + return true; + } else { + return false; + } +} + +$args = $_SERVER['argv']; +array_shift($args); + +$all = false; +$core = false; +$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 == "--plugins") { + $allplugins = true; + } elseif (substr($arg, 0, 9) == "--plugin=") { + $plugins[] = substr($arg, 9); + } +} + + + +if ($all || $core) { + echo "core..."; + update_core(INSTALLDIR, 'statusnet'); + echo " ok\n"; +} +if ($all || $allplugins) { + $plugins = get_plugins(INSTALLDIR); +} +if ($plugins) { + foreach ($plugins as $plugin) { + echo "$plugin..."; + if (update_plugin(INSTALLDIR, $plugin)) { + echo " ok\n"; + } else { + echo " not localized\n"; + } + } +} + diff --git a/scripts/update_pot.sh b/scripts/update_pot.sh deleted file mode 100755 index de53fe7c9..000000000 --- a/scripts/update_pot.sh +++ /dev/null @@ -1,13 +0,0 @@ -cd `dirname $0` -cd .. -xgettext \ - --from-code=UTF-8 \ - --default-domain=statusnet \ - --output=locale/statusnet.po \ - --language=PHP \ - --keyword="pgettext:1c,2" \ - --keyword="npgettext:1c,2,3" \ - actions/*.php \ - classes/*.php \ - lib/*.php \ - scripts/*.php -- cgit v1.2.3-54-g00ecf