Reviewers: ,


Please review this at http://codereview.tryton.org/162003/

Affected files:
  A translate_pycountry.py


Index: translate_pycountry.py
===================================================================
new file mode 100755
--- /dev/null
+++ b/translate_pycountry.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+from optparse import OptionParser
+from proteus import config, Model, Wizard
+import pycountry
+import gettext
+
+def main(options):
+    config.set_trytond(database_name=options.database, user=options.user,
+        password=options.password)
+    Translation = Model.get('ir.translation')
+
+    Country = Model.get('country.country')
+    id2country = dict((c.id, c) for c in Country.find())
+    gnutranslation = gettext.translation('iso3166', pycountry.LOCALES_DIR,
+        languages=[options.lang])
+    for translation in Translation.find([
+                ('lang', '=', options.lang),
+                ('module', '=', 'country'),
+                ('res_id', '>', 0),
+                ('name', '=', 'country.country,name'),
+                ]):
+        country = id2country[translation.res_id]
+        name = gnutranslation.ugettext(country.name)
+        translation.value = name
+        translation.fuzzy = False
+        translation.save()
+
+    Subdivision = Model.get('country.subdivision')
+    id2subdivision = dict((s.id, s) for s in Subdivision.find())
+ gnutranslation = gettext.translation('iso3166_2', pycountry.LOCALES_DIR,
+        languages=[options.lang])
+    for translation in Translation.find([
+                ('lang', '=', options.lang),
+                ('module', '=', 'country'),
+                ('res_id', '>', 0),
+                ('name', '=', 'country.subdivision,name'),
+                ]):
+        subdivision = id2subdivision[translation.res_id]
+        name = gnutranslation.ugettext(subdivision.name)
+        translation.value = name
+        translation.fuzzy = False
+        translation.save()
+
+    Currency = Model.get('currency.currency')
+    id2currency = dict((c.id, c) for c in Currency.find())
+    gnutranslation = gettext.translation('iso4217', pycountry.LOCALES_DIR,
+        languages=[options.lang])
+    for translation in Translation.find([
+                ('lang', '=', options.lang),
+                ('module', '=', 'currency'),
+                ('res_id', '>', 0),
+                ('name', '=', 'currency.currency,name'),
+                ]):
+        currency = id2currency[translation.res_id]
+        name = gnutranslation.ugettext(currency.name)
+        translation.value = name
+        translation.fuzzy = False
+        translation.save()
+
+if __name__ == '__main__':
+    parser = OptionParser()
+    parser.add_option('-d', '--database', dest='database')
+    parser.add_option('-u', '--user', dest='user')
+    parser.add_option('-w', '--password', dest='password')
+    parser.add_option('-l', '--language', dest='lang')
+ parser.set_defaults(user='admin', password='admin', database=None, lang=None)
+
+    options, args = parser.parse_args()
+    if args:
+        parser.error('Wrong arguments')
+    if not options.database:
+        parser.error('You must define a database')
+    if not options.lang:
+        parser.error('You must define a language')
+
+    main(options)


--
[email protected] mailing list

Reply via email to