diff options
-rw-r--r-- | examples/6_Maths_matchingAnglesAndShapes/js/es.po | 96 | ||||
-rw-r--r-- | examples/6_Maths_matchingAnglesAndShapes/js/messages.pot | 95 | ||||
-rwxr-xr-x | examples/6_Maths_matchingAnglesAndShapes/js/mo2js.py | 74 | ||||
-rw-r--r-- | js/jquery.i18n.js | 2 |
4 files changed, 266 insertions, 1 deletions
diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/es.po b/examples/6_Maths_matchingAnglesAndShapes/js/es.po new file mode 100644 index 0000000..095f897 --- /dev/null +++ b/examples/6_Maths_matchingAnglesAndShapes/js/es.po @@ -0,0 +1,96 @@ +# -*- code: UTF-8 -*- +# Spanish translations for PACKAGE package +# Traducciones al espa~nol para el paquete PACKAGE. +# Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Peter Gijsels <peter.gijsels@gmail.com>, 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-02-28 14:43+0100\n" +"PO-Revision-Date: 2010-02-28 14:58+0100\n" +"Last-Translator: Peter Gijsels <peter.gijsels@gmail.com>\n" +"Language-Team: Spanish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: lesson.js:61 +msgid "Acute-Angle" +msgstr "Ángulo-agudo" + +#: lesson.js:61 +msgid "Right-Angle" +msgstr "Ángulo-recto" + +#: lesson.js:61 +msgid "Obtuse-Angle" +msgstr "Ángulo-obtuso" + +#: lesson.js:61 +msgid "Triangle" +msgstr "Triángulo" + +#: lesson.js:61 +msgid "Square" +msgstr "Cuadrado" + +#: lesson.js:61 +msgid "Rhombus" +msgstr "Rombo" + +#: lesson.js:61 +msgid "Rectangle" +msgstr "Rectángulo" + +#: lesson.js:61 +msgid "Parallelogram" +msgstr "Paralelogramo" + +#: lesson.js:61 +msgid "Pentagon" +msgstr "Pentágono" + +#: lesson.js:61 +msgid "Hexagon" +msgstr "Hexágono" + +#: lesson.js:61 +msgid "Septagon" +msgstr "Heptágono" + +#: lesson.js:61 +msgid "Octagon" +msgstr "Octágono" + +#: lesson.js:68 +msgid "Maths: Matching Angles with Shapes" +msgstr "Matemáticas: reunir angulos y formas" + +#: lesson.js:100 lesson.js:122 +#, python-format +msgid "" +"You have completed the game in <span class=\"specialText\">%d</span> clicks " +"within <span class=\"specialText\">%d</span> hour," +msgid_plural "" +"You have completed the game in <span class=\"specialText\">%d</span> clicks " +"within <span class=\"specialText\">%d</span> hours," +msgstr[0] "Has acabado el juego en <span class=\"specialText\">%d</span> clics en <span class=\"specialText\">%d</span> hora," +msgstr[1] "Has acabado el juego en <span class=\"specialText\">%d</span> clics en <span class=\"specialText\">%d</span> horas," + +#: lesson.js:104 lesson.js:126 +#, python-format +msgid "<span class=\"specialText\">%d</span> minute and " +msgid_plural "<span class=\"specialText\">%d</span> minutes and " +msgstr[0] "<span class=\"specialText\">%d</span> minuto y " +msgstr[1] "<span class=\"specialText\">%d</span> minutos y " + +#: lesson.js:108 lesson.js:130 +#, python-format +msgid "<span class=\"specialText\">%d</span> second." +msgid_plural "<span class=\"specialText\">%d</span> seconds." +msgstr[0] "<span class=\"specialText\">%d</span> segundo." +msgstr[1] "<span class=\"specialText\">%d</span> segundos." diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/messages.pot b/examples/6_Maths_matchingAnglesAndShapes/js/messages.pot new file mode 100644 index 0000000..8333a97 --- /dev/null +++ b/examples/6_Maths_matchingAnglesAndShapes/js/messages.pot @@ -0,0 +1,95 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-02-28 14:43+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: lesson.js:61 +msgid "Acute-Angle" +msgstr "" + +#: lesson.js:61 +msgid "Right-Angle" +msgstr "" + +#: lesson.js:61 +msgid "Obtuse-Angle" +msgstr "" + +#: lesson.js:61 +msgid "Triangle" +msgstr "" + +#: lesson.js:61 +msgid "Square" +msgstr "" + +#: lesson.js:61 +msgid "Rhombus" +msgstr "" + +#: lesson.js:61 +msgid "Rectangle" +msgstr "" + +#: lesson.js:61 +msgid "Parallelogram" +msgstr "" + +#: lesson.js:61 +msgid "Pentagon" +msgstr "" + +#: lesson.js:61 +msgid "Hexagon" +msgstr "" + +#: lesson.js:61 +msgid "Septagon" +msgstr "" + +#: lesson.js:61 +msgid "Octagon" +msgstr "" + +#: lesson.js:68 +msgid "Maths: Matching Angles with Shapes" +msgstr "" + +#: lesson.js:100 lesson.js:122 +#, python-format +msgid "" +"You have completed the game in <span class=\"specialText\">%d</span> clicks " +"within <span class=\"specialText\">%d</span> hour," +msgid_plural "" +"You have completed the game in <span class=\"specialText\">%d</span> clicks " +"within <span class=\"specialText\">%d</span> hours," +msgstr[0] "" +msgstr[1] "" + +#: lesson.js:104 lesson.js:126 +#, python-format +msgid "<span class=\"specialText\">%d</span> minute and " +msgid_plural "<span class=\"specialText\">%d</span> minutes and " +msgstr[0] "" +msgstr[1] "" + +#: lesson.js:108 lesson.js:130 +#, python-format +msgid "<span class=\"specialText\">%d</span> second." +msgid_plural "<span class=\"specialText\">%d</span> seconds." +msgstr[0] "" +msgstr[1] "" diff --git a/examples/6_Maths_matchingAnglesAndShapes/js/mo2js.py b/examples/6_Maths_matchingAnglesAndShapes/js/mo2js.py new file mode 100755 index 0000000..b093202 --- /dev/null +++ b/examples/6_Maths_matchingAnglesAndShapes/js/mo2js.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python + +import codecs +import gettext +import json + +# To deal with keys that occur in more than one place and have a +# different translation, gettext uses contexts and the +# pgettext(context, msg) call. This would fit well with what we +# are trying to do. +# gettext uses a hack: the context and msg are concatenated into +# one string with an unprintable character between them, '\004'. +# A lot of gettext tools can then be oblivious to contexts. +# +# The problem however is that xgettext (to extract the strings) +# doesn't support pgettext when used with --language=Python. +# +# Two possibilities: +# 1. we roll our own xgettext for javascript (starting from e.g. the +# jslint parser). The code below should be adapted to recognise +# the '\004' character and extract the context. +# 2. we abandon using contexts and combine the context and msg into +# one string. e.g. '$.ui.kFooter.Play Again' + +# Other remarks: +# 1. If there is no context specified, we should not use 'default' +# as context, because that context might already be used. +# We should restructure the $.i18n.<lang> dict, e.g.: +# $.i18n.<lang> = +# { strings = { 'key': 'val', ...}, +# contextualized_strings = { context1 = { 'key' : 'val', ...}, +# context2 = { 'key' : 'val', ...}}}; +# 2. We should rename messages.<lang>.json to messages.<lang>.js +# 3. In lesson.html we should refer to messages.js, which is a link to +# one of the messages.<lang>.js + +def gettext_json(fp, indent = False): + import gettext + import json + try: + tr = gettext.GNUTranslations(fp) + keys = tr._catalog.keys() + keys.sort() + ret = {} + for k in keys: + v = tr._catalog[k] + if type(k) is tuple: + # plural: k = (key, n) + if k[0] not in ret: + ret[k[0]] = [] + ret[k[0]].append(v) + else: + ret[k] = v + return json.dumps(ret, ensure_ascii = False, indent = indent) + except IOError: + return None + +def usage(argv0): + print 'Usage:' + print '\t' + argv0 + ' language mo-file js-file' + +if __name__ == '__main__': + import sys + if len(sys.argv) != 4: + usage(sys.argv[0]) + sys.exit(1) + [lang, mo, js] = sys.argv[1:] + f = codecs.open(js, encoding='utf-8', mode='w+') + lang = sys.argv[1] + f.write('$.i18n.%s = {};\n' % lang); + f.write('$.i18n.%s.strings =\n' % lang); + f.write(gettext_json(open(mo, 'r'), True)) + f.write(';\n'); + f.write('$.i18n.setLocale(\'%s\');\n' % lang); diff --git a/js/jquery.i18n.js b/js/jquery.i18n.js index 4eb303f..a50e612 100644 --- a/js/jquery.i18n.js +++ b/js/jquery.i18n.js @@ -13,7 +13,7 @@ if (!$.i18n[lang] || !$.i18n[lang].strings){ return string; } - return this.i18n[lang].strings['default'][string]||string; + return $.i18n[lang].strings['default'][string]||string; }; $.i18n.cgettext = function(context, string, locale){ |