diff options
| author | Christophe Simonis <christophe@tinyerp.com> | 2008-07-22 09:38:43 +0200 |
|---|---|---|
| committer | Christophe Simonis <christophe@tinyerp.com> | 2008-07-22 09:38:43 +0200 |
| commit | 63ceebdf364bc1e08a580dc994c7d18f708fc619 (patch) | |
| tree | 86fad8e491d0054dd6f753fe4f8d06d0f717d0ce | |
| parent | 2ccf0092a7e78b766a03475feedc12ca6c6dc21a (diff) | |
i18n: allow export into a po file from command line
bzr revid: christophe@tinyerp.com-20080722073843-16r67df83yz8z0tb
| -rw-r--r-- | bin/addons/base/module/wizard/wizard_export_lang.py | 18 | ||||
| -rwxr-xr-x | bin/tinyerp-server.py | 11 | ||||
| -rw-r--r-- | bin/tools/config.py | 6 | ||||
| -rw-r--r-- | bin/tools/translate.py | 17 |
4 files changed, 30 insertions, 22 deletions
diff --git a/bin/addons/base/module/wizard/wizard_export_lang.py b/bin/addons/base/module/wizard/wizard_export_lang.py index 9571f7267cd..3f7fa8f99df 100644 --- a/bin/addons/base/module/wizard/wizard_export_lang.py +++ b/bin/addons/base/module/wizard/wizard_export_lang.py @@ -125,25 +125,15 @@ class wizard_export_lang(osv.osv_memory): this = self.browse(cr, uid, ids)[0] mods = map(lambda m: m.name, this.modules) mods.sort() - file=tools.trans_generate(this.lang, mods, dbname=cr.dbname) buf=StringIO.StringIO() - + + tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname) + if this.format == 'csv': this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.") - writer=csv.writer(buf, 'UNIX') - for row in file: - writer.writerow(row) elif this.format == 'po': this.advice = _("Save this document to a .po file and edit it with a specific software or a text editor. The file encoding is UTF-8.") - file.pop(0) - writer = tools.TinyPoFile(buf) - writer.write_infos(mods) - for module, type, name, res_id, src, trad in file: - writer.write(module, type, name, res_id, src, trad) - else: - raise osv_except(_('Bad file format')) - - del file + out=base64.encodestring(buf.getvalue()) buf.close() return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice}, context=context) diff --git a/bin/tinyerp-server.py b/bin/tinyerp-server.py index 8bdeec75bc6..c022188ff72 100755 --- a/bin/tinyerp-server.py +++ b/bin/tinyerp-server.py @@ -184,11 +184,12 @@ if tools.config["translate_out"]: import csv logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for language %s to %s' % (tools.config["language"], tools.config["translate_out"])) - trans=tools.trans_generate(tools.config["language"], tools.config["translate_modules"]) - writer=csv.writer(file(tools.config["translate_out"], "w"), 'UNIX') - for row in trans: - writer.writerow(row) - del trans + + fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower() + buf = file(tools.config["translate_out"], "w") + tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat) + buf.close() + logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully') sys.exit(0) diff --git a/bin/tools/config.py b/bin/tools/config.py index 1948d725b36..51a5b49699f 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -115,11 +115,11 @@ class configmanager(object): group = optparse.OptionGroup(parser, "Internationalisation options", "Use these options to translate Tiny ERP to another language." - "See i18n section of the user manual. Option '-l' is mandatory.") + "See i18n section of the user manual. Options '-l' and '-d' are mandatory.") group.add_option('-l', "--language", dest="language", help="specify the language of the translation file. Use it with --i18n-export and --i18n-import") - group.add_option("--i18n-export", dest="translate_out", help="export all sentences to be translated to a CSV file and exit") - group.add_option("--i18n-import", dest="translate_in", help="import a CSV file with translations and exit") + group.add_option("--i18n-export", dest="translate_out", help="export all sentences to be translated to a CSV or a PO file and exit") + group.add_option("--i18n-import", dest="translate_in", help="import a CSV or a PO file with translations and exit") group.add_option("--modules", dest="translate_modules", help="specify modules to export. Use in combination with --i18n-export") group.add_option("--addons-path", dest="addons_path", help="specify an alternative addons path.") parser.add_option_group(group) diff --git a/bin/tools/translate.py b/bin/tools/translate.py index 71748e5060d..123d673d238 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -169,6 +169,23 @@ class TinyPoFile(object): # Methods to export the translation file +def trans_export(lang, modules, buffer, format, dbname=None): + trans = trans_generate(lang, modules, dbname) + if format == 'csv': + writer=csv.writer(buffer, 'UNIX') + for row in trans: + writer.writerow(row) + elif format == 'po': + trans.pop(0) + writer = tools.TinyPoFile(buffer) + writer.write_infos(modules) + for module, type, name, res_id, src, trad in trans: + writer.write(module, type, name, res_id, src, trad) + else: + raise Exception(_('Bad file format')) + del trans + + def trans_parse_xsl(de): res = [] for n in [i for i in de.childNodes if (i.nodeType == i.ELEMENT_NODE)]: |
