i18n: allow export into a po file from command line
bzr revid: christophe@tinyerp.com-20080722073843-16r67df83yz8z0tb
This commit is contained in:
parent
2ccf0092a7
commit
63ceebdf36
|
@ -125,25 +125,15 @@ class wizard_export_lang(osv.osv_memory):
|
||||||
this = self.browse(cr, uid, ids)[0]
|
this = self.browse(cr, uid, ids)[0]
|
||||||
mods = map(lambda m: m.name, this.modules)
|
mods = map(lambda m: m.name, this.modules)
|
||||||
mods.sort()
|
mods.sort()
|
||||||
file=tools.trans_generate(this.lang, mods, dbname=cr.dbname)
|
|
||||||
buf=StringIO.StringIO()
|
buf=StringIO.StringIO()
|
||||||
|
|
||||||
|
tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname)
|
||||||
|
|
||||||
if this.format == 'csv':
|
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.")
|
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':
|
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.")
|
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())
|
out=base64.encodestring(buf.getvalue())
|
||||||
buf.close()
|
buf.close()
|
||||||
return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice}, context=context)
|
return self.write(cr, uid, ids, {'state':'get', 'data':out, 'advice':this.advice}, context=context)
|
||||||
|
|
|
@ -184,11 +184,12 @@ if tools.config["translate_out"]:
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for language %s to %s' % (tools.config["language"], tools.config["translate_out"]))
|
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')
|
fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
|
||||||
for row in trans:
|
buf = file(tools.config["translate_out"], "w")
|
||||||
writer.writerow(row)
|
tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
|
||||||
del trans
|
buf.close()
|
||||||
|
|
||||||
logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
|
logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
|
@ -115,11 +115,11 @@ class configmanager(object):
|
||||||
|
|
||||||
group = optparse.OptionGroup(parser, "Internationalisation options",
|
group = optparse.OptionGroup(parser, "Internationalisation options",
|
||||||
"Use these options to translate Tiny ERP to another language."
|
"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('-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-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 file with translations 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("--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.")
|
group.add_option("--addons-path", dest="addons_path", help="specify an alternative addons path.")
|
||||||
parser.add_option_group(group)
|
parser.add_option_group(group)
|
||||||
|
|
|
@ -169,6 +169,23 @@ class TinyPoFile(object):
|
||||||
|
|
||||||
# Methods to export the translation file
|
# 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):
|
def trans_parse_xsl(de):
|
||||||
res = []
|
res = []
|
||||||
for n in [i for i in de.childNodes if (i.nodeType == i.ELEMENT_NODE)]:
|
for n in [i for i in de.childNodes if (i.nodeType == i.ELEMENT_NODE)]:
|
||||||
|
|
Loading…
Reference in New Issue