i18n: allow export into a po file from command line

bzr revid: christophe@tinyerp.com-20080722073843-16r67df83yz8z0tb
This commit is contained in:
Christophe Simonis 2008-07-22 09:38:43 +02:00
parent 2ccf0092a7
commit 63ceebdf36
4 changed files with 30 additions and 22 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)]: