Commit b06d1a22 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Translation: Workflow State can have specific translation by portal_type

parent 857e889b
from Products.ERP5Type.Utils import getMessageIdWithContext from Products.ERP5Type.Utils import getTranslatedWorkflowStateWithPortalType
supported_languages = context.Localizer.get_supported_languages() supported_languages = context.Localizer.get_supported_languages()
translated_keys = {} # This dict prevents entering the same key twice translated_keys = {} # This dict prevents entering the same key twice
...@@ -38,11 +38,7 @@ for wf_id, portal_type_list in portal_workflow.getChainDict().items(): ...@@ -38,11 +38,7 @@ for wf_id, portal_type_list in portal_workflow.getChainDict().items():
# translate state title as well # translate state title as well
if state.title != '' : if state.title != '' :
state_var_title = '%s_title' % state_var state_var_title = '%s_title' % state_var
msg_id = getMessageIdWithContext(state.title, 'state', wf.id) translated_message, msg_id = getTranslatedWorkflowStateWithPortalType(context.Localizer, wf.id, lang, portal_type, state.title)
translated_message = context.Localizer.erp5_ui.gettext(msg_id, default='', lang=lang).encode('utf-8')
if translated_message == '':
msg_id = state.title
translated_message = context.Localizer.erp5_ui.gettext(state.title.decode('utf-8'), lang=lang).encode('utf-8')
key = (lang, portal_type, state_var_title, state_id, msg_id) key = (lang, portal_type, state_var_title, state_id, msg_id)
if not translated_keys.has_key(key): if not translated_keys.has_key(key):
translated_keys[key] = None # mark as translated translated_keys[key] = None # mark as translated
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
from Acquisition import aq_base from Acquisition import aq_base
from Products.ERP5Type.PsycoWrapper import psyco from Products.ERP5Type.PsycoWrapper import psyco
from Products.ERP5Type.Utils import getTranslatedWorkflowStateWithPortalType
from Base import Getter as BaseGetter, Setter as BaseSetter from Base import Getter as BaseGetter, Setter as BaseSetter
from warnings import warn from warnings import warn
...@@ -111,14 +112,13 @@ class TranslatedTitleGetter(TitleGetter): ...@@ -111,14 +112,13 @@ class TranslatedTitleGetter(TitleGetter):
wf = portal.portal_workflow.getWorkflowById(wf_id) wf = portal.portal_workflow.getWorkflowById(wf_id)
selected_language = localizer.get_selected_language() selected_language = localizer.get_selected_language()
state_title = wf._getWorkflowStateOf(instance).title state_title = wf._getWorkflowStateOf(instance).title
msg_id = '%s [state in %s]' % (state_title, wf_id) return getTranslatedWorkflowStateWithPortalType(
result = localizer.erp5_ui.gettext(msg_id, localizer,
lang=selected_language, self._key,
default='') selected_language,
if result == '': instance.getPortalType(),
result = localizer.erp5_ui.gettext(state_title, state_title
lang=selected_language) )[0]
return result.encode('utf8')
psyco.bind(__call__) psyco.bind(__call__)
......
...@@ -367,6 +367,22 @@ def int2letter(i): ...@@ -367,6 +367,22 @@ def int2letter(i):
def getMessageIdWithContext(msg_id, context, context_id): def getMessageIdWithContext(msg_id, context, context_id):
return '%s [%s in %s]' % (msg_id, context, context_id) return '%s [%s in %s]' % (msg_id, context, context_id)
def getTranslatedWorkflowStateWithPortalType(localizer, workflow_id, lang,
portal_type, state_title):
for msg_id, default in [
(getMessageIdWithContext(state_title, 'state', portal_type), ''),
(getMessageIdWithContext(state_title, 'state', workflow_id), ''),
(state_title.decode('utf-8'), None),
]:
translated_message = localizer.erp5_ui.gettext(
msg_id,
default=default,
lang=lang
).encode('utf-8')
if translated_message:
return translated_message, msg_id
#Get translation of msg id #Get translation of msg id
def getTranslationStringWithContext(self, msg_id, context, context_id): def getTranslationStringWithContext(self, msg_id, context, context_id):
portal = self.getPortalObject() portal = self.getPortalObject()
......
...@@ -165,6 +165,7 @@ ModuleSecurityInfo('Products.ERP5Type.Utils').declarePublic( ...@@ -165,6 +165,7 @@ ModuleSecurityInfo('Products.ERP5Type.Utils').declarePublic(
'sortValueList', 'convertToUpperCase', 'UpperCase', 'sortValueList', 'convertToUpperCase', 'UpperCase',
'convertToMixedCase', 'cartesianProduct', 'sleep', 'getCommonTimeZoneList', 'convertToMixedCase', 'cartesianProduct', 'sleep', 'getCommonTimeZoneList',
'int2letter', 'getMessageIdWithContext', 'getTranslationStringWithContext', 'int2letter', 'getMessageIdWithContext', 'getTranslationStringWithContext',
'getTranslatedWorkflowStateWithPortalType',
'Email_parseAddressHeader', 'guessEncodingFromText', 'Email_parseAddressHeader', 'guessEncodingFromText',
'isValidTALESExpression') 'isValidTALESExpression')
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import getTranslatedWorkflowStateWithPortalType
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
# Products.DCWorkflowGraph.config does not check the return value of # Products.DCWorkflowGraph.config does not check the return value of
...@@ -107,15 +108,9 @@ def getObjectTitle(obj, REQUEST=None): ...@@ -107,15 +108,9 @@ def getObjectTitle(obj, REQUEST=None):
localizer = obj.Localizer localizer = obj.Localizer
original_title = title original_title = title
for lang in localizer.get_supported_languages(): for lang in localizer.get_supported_languages():
msg_id = '%s [state in %s]' % (title, wf_id) translated_message, msg_id = getTranslatedWorkflowStateWithPortalType(
translated_title = localizer.erp5_ui.gettext( localizer, wf_id, lang, obj.getPortalType(), title
msg_id, )
lang=lang,
# Fallback on non-workflow state translation
default=localizer.erp5_ui.gettext(original_title,
lang=lang,
default=None))
if (translated_title is not None and if (translated_title is not None and
translated_title != original_title): translated_title != original_title):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment