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

View file

@ -10,6 +10,10 @@ class TranslationWrapper(AbstractWrapper):
'''The label for a text to translate displays the text of the '''The label for a text to translate displays the text of the
corresponding message in the source translation.''' corresponding message in the source translation.'''
tool = self.tool tool = self.tool
# 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 sourceLanguage = self.o.getProductConfig().sourceLanguage
sourceTranslation = getattr(tool.o, sourceLanguage).appy() sourceTranslation = getattr(tool.o, sourceLanguage).appy()
# p_field is the Computed field. We need to get the name of the # p_field is the Computed field. We need to get the name of the
@ -28,9 +32,9 @@ class TranslationWrapper(AbstractWrapper):
if url.endswith('/ui/edit') or url.endswith('/do'): if url.endswith('/ui/edit') or url.endswith('/do'):
sourceMsg = sourceMsg.replace('<','&lt;').replace('>','&gt;') sourceMsg = sourceMsg.replace('<','&lt;').replace('>','&gt;')
sourceMsg = sourceMsg.replace('\n', '<br/>') sourceMsg = sourceMsg.replace('\n', '<br/>')
return '<div class="translationLabel"><acronym title="%s">' \ return '<div class="translationLabel"><acronym title="%s" ' \
'<img src="ui/help.png"/></acronym>%s</div>' % \ 'style="margin-right: 5px"><img src="ui/help.png"/></acronym>' \
(fieldName, sourceMsg) '%s</div>' % (fieldName, sourceMsg)
def show(self, field): def show(self, field):
'''We show a field (or its label) only if the corresponding source '''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)) '%s-%s.po' % (tool.o.getAppName(), self.id))
poFile = PoFile(fileName) poFile = PoFile(fileName)
for field in self.fields: 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 # Adds the PO message corresponding to this field
msg = field.getValue(self.o) or '' msg = field.getValue(self.o) or ''
for old, new in self.poReplacements: for old, new in self.poReplacements: