[gen] One can now specify a different source language for every translation.

This commit is contained in:
Gaetan Delannay 2013-01-09 10:46:14 +01:00
parent 6ee3d6ded9
commit f091b25c98
2 changed files with 16 additions and 9 deletions

View file

@ -183,12 +183,13 @@ class Group(ModelClass):
# The Translation class --------------------------------------------------------
class Translation(ModelClass):
_appy_attributes = ['po', 'title']
_appy_attributes = ['po', 'title', 'sourceLanguage']
# All methods defined below are fake. Real versions are in the wrapper.
actionsPage = gen.Page('actions')
def getPoFile(self): pass
po = gen.Action(action=getPoFile, page=gen.Page('actions', show='view'),
result='filetmp')
title = gen.String(show=False, indexed=True)
po = gen.Action(action=getPoFile, page=actionsPage, result='filetmp')
sourceLanguage = gen.String(page=actionsPage, width=4)
title = gen.String(show=False, indexed=True, page=actionsPage)
def label(self): pass
def show(self, name): pass

View file

@ -10,7 +10,11 @@ class TranslationWrapper(AbstractWrapper):
'''The label for a text to translate displays the text of the
corresponding message in the source translation.'''
tool = self.tool
sourceLanguage = self.o.getProductConfig().sourceLanguage
# Get the source language: either defined on the translation itself,
# either from the config object.
sourceLanguage = self.sourceLanguage
if not sourceLanguage:
sourceLanguage = self.o.getProductConfig().sourceLanguage
sourceTranslation = getattr(tool.o, sourceLanguage).appy()
# p_field is the Computed field. We need to get the name of the
# corresponding field holding the translation message.
@ -28,9 +32,9 @@ class TranslationWrapper(AbstractWrapper):
if url.endswith('/ui/edit') or url.endswith('/do'):
sourceMsg = sourceMsg.replace('<','&lt;').replace('>','&gt;')
sourceMsg = sourceMsg.replace('\n', '<br/>')
return '<div class="translationLabel"><acronym title="%s">' \
'<img src="ui/help.png"/></acronym>%s</div>' % \
(fieldName, sourceMsg)
return '<div class="translationLabel"><acronym title="%s" ' \
'style="margin-right: 5px"><img src="ui/help.png"/></acronym>' \
'%s</div>' % (fieldName, sourceMsg)
def show(self, field):
'''We show a field (or its label) only if the corresponding source
@ -54,7 +58,9 @@ class TranslationWrapper(AbstractWrapper):
'%s-%s.po' % (tool.o.getAppName(), self.id))
poFile = PoFile(fileName)
for field in self.fields:
if (field.name == 'title') or (field.type != 'String'): continue
# Ignore labels and appy-specific fields in page 'actions'.
if (field.page.name == 'actions') or (field.type != 'String'):
continue
# Adds the PO message corresponding to this field
msg = field.getValue(self.o) or ''
for old, new in self.poReplacements: