From 10bccf7d57ddd885507b1a8d4ee29b0076c14724 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Feb 2009 12:57:02 +0300 Subject: [PATCH] automatically extract i18n data from .js files --- localized_js.php | 252 ++++++++++++++++++-------------- offline.js | 2 - update-translations.sh | 2 + utils/extract-i18n-js.pl | 15 ++ utils/update-js-translations.sh | 48 ++++++ 5 files changed, 205 insertions(+), 114 deletions(-) create mode 100755 utils/extract-i18n-js.pl create mode 100755 utils/update-js-translations.sh diff --git a/localized_js.php b/localized_js.php index ee230940c..849bab9f1 100644 --- a/localized_js.php +++ b/localized_js.php @@ -9,13 +9,13 @@ function T_js_decl($s1) { if (!$s1) return; - $T_s1 = __($s1); +// $T_s1 = __($s1); - if ($T_s1 != $s1) { +// if ($T_s1 != $s1) { return "T_messages[\"$s1\"] = \"".__($s1)."\";\n"; - } else { - return ""; - } +// } else { +// return ""; +// } } ?> @@ -31,124 +31,152 @@ function __(msg) { } diff --git a/offline.js b/offline.js index 9054ea455..010bbe05e 100644 --- a/offline.js +++ b/offline.js @@ -854,8 +854,6 @@ function update_offline_data(stage) { if (!db || offline_mode || getInitParam("offline_enabled") != "1") return; -// notify_progress("Updating offline data... (" + stage +")", true); - var query = "backend.php?op=rpc&subop=download"; var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles"); diff --git a/update-translations.sh b/update-translations.sh index 0b78958b2..93c4e5d76 100755 --- a/update-translations.sh +++ b/update-translations.sh @@ -25,3 +25,5 @@ for lang in $LANGS; do PO_BASENAME=`echo $lang | sed s/.po//` update_lang $PO_BASENAME done + +./utils/update-js-translations.sh diff --git a/utils/extract-i18n-js.pl b/utils/extract-i18n-js.pl new file mode 100755 index 000000000..d6179fc70 --- /dev/null +++ b/utils/extract-i18n-js.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w +# +use strict; + +while () { + chomp; + + if (/(__|notify_progress|notify|notify_info|notify_error)\(['"](.*?)['"]\)/) { + my $msg = $2; + + $msg =~ s/\"/\\\"/g; + + print "print T_js_decl(\"$msg\");\n"; + } +} diff --git a/utils/update-js-translations.sh b/utils/update-js-translations.sh new file mode 100755 index 000000000..432cf7ece --- /dev/null +++ b/utils/update-js-translations.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +if [ ! -f localized_js.php ]; then + echo "please run this script from tt-rss directory" + exit 1 +fi + +cat >localized_js.php <
+ +var T_messages = new Object(); + +function __(msg) { + if (T_messages[msg]) { + return T_messages[msg]; + } else { + debug('[gettext] not found: ' + msg); + return msg; + } +} + +> localized_js.php + +cat >>localized_js.php <