appy.gen: every field can now define a dict of i18n mappings that will be used for translating their label and/or description and/or help message(s).
This commit is contained in:
parent
fd9dd569db
commit
66a02c453e
4 changed files with 85 additions and 36 deletions
gen/plone25
|
@ -1175,8 +1175,15 @@ class BaseMixin:
|
|||
return res
|
||||
|
||||
def translate(self, label, mapping={}, domain=None, default=None,
|
||||
language=None, format='html'):
|
||||
'''Translates a given p_label into p_domain with p_mapping.'''
|
||||
language=None, format='html', field=None, className=None):
|
||||
'''Translates a given p_label into p_domain with p_mapping.
|
||||
|
||||
If p_field is given, p_label does not correspond to a full label
|
||||
name, but to a label type linked to p_field: "label", "descr"
|
||||
or "help". Indeed, in this case, a specific i18n mapping may be
|
||||
available on the field, so we must merge this mapping into
|
||||
p_mapping. If p_className is not given, we consider p_self being an
|
||||
instance of the class where p_field is defined.'''
|
||||
cfg = self.getProductConfig()
|
||||
if not domain: domain = cfg.PROJECTNAME
|
||||
if domain != cfg.PROJECTNAME:
|
||||
|
@ -1190,6 +1197,19 @@ class BaseMixin:
|
|||
# TranslationService
|
||||
res = label
|
||||
else:
|
||||
# Get the label name, and the field-specific mapping if any.
|
||||
if field:
|
||||
# Maybe we do not have the field itself, but only its name
|
||||
if isinstance(field, basestring):
|
||||
field = self.getAppyType(field, className=className)
|
||||
# Include field-specific mapping if any.
|
||||
fieldMapping = field.mapping[label]
|
||||
if fieldMapping:
|
||||
if callable(fieldMapping):
|
||||
fieldMapping = field.callMethod(self, fieldMapping)
|
||||
mapping.update(fieldMapping)
|
||||
# Get the label
|
||||
label = getattr(field, label+'Id')
|
||||
# We will get the translation from a Translation object.
|
||||
# In what language must we get the translation?
|
||||
if not language: language = self.getUserLanguage()
|
||||
|
|
|
@ -120,9 +120,9 @@
|
|||
maxReached python:(multiplicity[1] != None) and (len(objs) >= multiplicity[1]);
|
||||
showPlusIcon python:not appyType['isBack'] and appyType['add'] and not maxReached and member.has_permission(addPermission, folder) and canWrite;
|
||||
atMostOneRef python: (multiplicity[1] == 1) and (len(objs)<=1);
|
||||
label python: tool.translate(appyType['labelId']);
|
||||
label python: contextObj.translate('label', field=appyType['name']);
|
||||
addConfirmMsg python: tool.translate('%s_addConfirm' % appyType['labelId']);
|
||||
description python: tool.translate(appyType['descrId']);
|
||||
description python: contextObj.translate('descr', field=appyType['name']);
|
||||
navBaseCall python: 'askRefField(\'%s\',\'%s\',\'%s\',\'%s\',**v**)' % (ajaxHookId, contextObj.absolute_url(), fieldName, innerRef)">
|
||||
|
||||
<tal:comment replace="nothing">This macro displays the Reference widget on a "consult" page.
|
||||
|
|
|
@ -186,17 +186,17 @@
|
|||
<tal:label metal:define-macro="label" condition="widget/hasLabel">
|
||||
<label tal:attributes="for widget/name"
|
||||
tal:condition="python: not ((widget['type'] == 'Action') or ((widget['type'] == 'Ref') and (widget['add'])))"
|
||||
tal:content="structure python: contextObj.translate(widget['labelId'])"></label>
|
||||
tal:content="structure python: contextObj.translate('label', field=widget['name'])"></label>
|
||||
</tal:label>
|
||||
|
||||
<tal:comment replace="nothing">Displays a field description.</tal:comment>
|
||||
<tal:description metal:define-macro="description" condition="widget/hasDescr">
|
||||
<span class="discreet" tal:content="structure python: contextObj.translate(widget['descrId'])"></span>
|
||||
<span class="discreet" tal:content="structure python: contextObj.translate('descr', field=widget['name'])"></span>
|
||||
</tal:description>
|
||||
|
||||
<tal:comment replace="nothing">Displays a field help.</tal:comment>
|
||||
<tal:help metal:define-macro="help">
|
||||
<acronym tal:attributes="title python: contextObj.translate(widget['helpId'])">
|
||||
<acronym tal:attributes="title python: contextObj.translate('help', field=widget['name'])">
|
||||
<img tal:attributes="src string: $portal_url/skyn/help.png"/>
|
||||
</acronym>
|
||||
</tal:help>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue