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 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100755 scripts/update_po_templates.php (limited to 'scripts/update_po_templates.php') 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"; + } + } +} + -- cgit v1.2.3-54-g00ecf