Added a fallback mechanism for Appy translations. Bugfix while reindexing multivalued Strings.
This commit is contained in:
parent
ead9f7c2de
commit
e5cef2b8a4
|
@ -1178,11 +1178,16 @@ class String(Type):
|
||||||
(res.startswith('\n') or res.startswith('\r\n')): res = ' ' + res
|
(res.startswith('\n') or res.startswith('\r\n')): res = ' ' + res
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
emptyStringTuple = ('',)
|
||||||
def getIndexValue(self, obj, forSearch=False):
|
def getIndexValue(self, obj, forSearch=False):
|
||||||
'''For indexing purposes, we return only strings, not unicodes.'''
|
'''For indexing purposes, we return only strings, not unicodes.'''
|
||||||
res = Type.getIndexValue(self, obj, forSearch)
|
res = Type.getIndexValue(self, obj, forSearch)
|
||||||
if isinstance(res, unicode):
|
if isinstance(res, unicode):
|
||||||
res = res.encode('utf-8')
|
res = res.encode('utf-8')
|
||||||
|
# Ugly portal_catalog: if I give an empty tuple as index value,
|
||||||
|
# portal_catalog keeps the previous value! If I give him a tuple
|
||||||
|
# containing an empty string, it is ok.
|
||||||
|
if isinstance(res, tuple) and not res: res = self.emptyStringTuple
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def getPossibleValues(self,obj,withTranslations=False,withBlankValue=False):
|
def getPossibleValues(self,obj,withTranslations=False,withBlankValue=False):
|
||||||
|
|
|
@ -501,7 +501,7 @@ class PloneInstaller:
|
||||||
self.manageIndexes()
|
self.manageIndexes()
|
||||||
self.manageLanguages()
|
self.manageLanguages()
|
||||||
self.finalizeInstallation()
|
self.finalizeInstallation()
|
||||||
self.appyTool.log("Installation of %s done." % self.productName)
|
self.appyTool.log("Installation done.")
|
||||||
|
|
||||||
def uninstallTool(self):
|
def uninstallTool(self):
|
||||||
site = self.ploneSite
|
site = self.ploneSite
|
||||||
|
|
|
@ -393,8 +393,7 @@ class ToolMixin(BaseMixin):
|
||||||
if not self.translationMapping['portal_path']:
|
if not self.translationMapping['portal_path']:
|
||||||
self.translationMapping['portal_path'] = \
|
self.translationMapping['portal_path'] = \
|
||||||
self.portal_url.getPortalPath()
|
self.portal_url.getPortalPath()
|
||||||
appName = self.getProductConfig().PROJECTNAME
|
return self.translate(label, mapping=self.translationMapping)
|
||||||
return self.utranslate(label, self.translationMapping, domain=appName)
|
|
||||||
|
|
||||||
def getPublishedObject(self):
|
def getPublishedObject(self):
|
||||||
'''Gets the currently published object, if its meta_class is among
|
'''Gets the currently published object, if its meta_class is among
|
||||||
|
|
|
@ -1044,6 +1044,20 @@ class BaseMixin:
|
||||||
params = ''
|
params = ''
|
||||||
return '%s%s' % (base, params)
|
return '%s%s' % (base, params)
|
||||||
|
|
||||||
|
def getLanguage(self):
|
||||||
|
'''Gets the language (code) of the current user.'''
|
||||||
|
# Try first the "LANGUAGE" key from the request
|
||||||
|
res = self.REQUEST.get('LANGUAGE', None)
|
||||||
|
if res: return res
|
||||||
|
# Try then the HTTP_ACCEPT_LANGUAGE key from the request, which stores
|
||||||
|
# language preferences as defined in the user's browser. Several
|
||||||
|
# languages can be listed, from most to less wanted.
|
||||||
|
res = self.REQUEST.get('HTTP_ACCEPT_LANGUAGE', None)
|
||||||
|
if not res: return 'en'
|
||||||
|
if ',' in res: res = res[:res.find(',')]
|
||||||
|
if '-' in res: res = res[:res.find('-')]
|
||||||
|
return res
|
||||||
|
|
||||||
def translate(self, label, mapping={}, domain=None, default=None,
|
def translate(self, label, mapping={}, domain=None, default=None,
|
||||||
language=None):
|
language=None):
|
||||||
'''Translates a given p_label into p_domain with p_mapping.'''
|
'''Translates a given p_label into p_domain with p_mapping.'''
|
||||||
|
@ -1062,14 +1076,21 @@ class BaseMixin:
|
||||||
else:
|
else:
|
||||||
# We will get the translation from a Translation object.
|
# We will get the translation from a Translation object.
|
||||||
# In what language must we get the translation?
|
# In what language must we get the translation?
|
||||||
if not language: language = self.REQUEST['LANGUAGE']
|
if not language: language = self.getLanguage()
|
||||||
tool = self.getTool()
|
tool = self.getTool()
|
||||||
translation = getattr(self.getTool(), language).appy()
|
try:
|
||||||
|
translation = getattr(tool, language).appy()
|
||||||
|
except AttributeError:
|
||||||
|
# We have no translation for this language. Fallback to 'en'.
|
||||||
|
translation = getattr(tool, 'en').appy()
|
||||||
res = getattr(translation, label, '')
|
res = getattr(translation, label, '')
|
||||||
|
if not res:
|
||||||
|
# Fallback to 'en'.
|
||||||
|
translation = getattr(tool, 'en').appy()
|
||||||
|
res = getattr(translation, label, '')
|
||||||
# Perform replacements if needed
|
# Perform replacements if needed
|
||||||
for name, repl in mapping.iteritems():
|
for name, repl in mapping.iteritems():
|
||||||
res = res.replace('${%s}' % name, repl)
|
res = res.replace('${%s}' % name, repl)
|
||||||
# At present, there is no fallback machanism.
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def getPageLayout(self, layoutType):
|
def getPageLayout(self, layoutType):
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
<td tal:define="titleIsClickable python: member.has_role('Manager') and rootClasses">
|
<td tal:define="titleIsClickable python: member.has_role('Manager') and rootClasses">
|
||||||
<a tal:condition="titleIsClickable"
|
<a tal:condition="titleIsClickable"
|
||||||
tal:attributes="href python:'%s?type_name=%s' % (queryUrl, ','.join(rootClasses))"
|
tal:attributes="href python:'%s?type_name=%s' % (queryUrl, ','.join(rootClasses))"
|
||||||
tal:content="python: tool.translate(appName)"></a>
|
tal:content="structure python: tool.translate(appName)"></a>
|
||||||
<span tal:condition="not: titleIsClickable"
|
<span tal:condition="not: titleIsClickable"
|
||||||
tal:replace="python: tool.translate(appName)"/>
|
tal:replace="structure python: tool.translate(appName)"/>
|
||||||
</td>
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<img style="cursor:pointer"
|
<img style="cursor:pointer"
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
<td>
|
<td>
|
||||||
<a tal:attributes="href python: '%s?type_name=%s' % (queryUrl, rootClass);
|
<a tal:attributes="href python: '%s?type_name=%s' % (queryUrl, rootClass);
|
||||||
class python:test(not currentSearch and (currentType==rootClass), 'portletCurrent', '')"
|
class python:test(not currentSearch and (currentType==rootClass), 'portletCurrent', '')"
|
||||||
tal:content="python: tool.translate(rootClass + '_plural')"></a>
|
tal:content="structure python: tool.translate(rootClass + '_plural')"></a>
|
||||||
</td>
|
</td>
|
||||||
<td align="right"
|
<td align="right"
|
||||||
tal:define="addPermission python: '%s: Add %s' % (appName, rootClass);
|
tal:define="addPermission python: '%s: Add %s' % (appName, rootClass);
|
||||||
|
@ -151,7 +151,7 @@
|
||||||
<table tal:condition="displayLink" cellpadding="0" cellspacing="0" width="100%">
|
<table tal:condition="displayLink" cellpadding="0" cellspacing="0" width="100%">
|
||||||
<tr tal:define="pageName python: phase['pages'][0]">
|
<tr tal:define="pageName python: phase['pages'][0]">
|
||||||
<td><a tal:attributes="href python: contextObj.getUrl(page=pageName)"
|
<td><a tal:attributes="href python: contextObj.getUrl(page=pageName)"
|
||||||
tal:content="python: tool.translate(label)"></a>
|
tal:content="structure python: tool.translate(label)"></a>
|
||||||
</td>
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<img title="Edit" i18n:domain="plone" i18n:attributes="title" style="cursor:pointer"
|
<img title="Edit" i18n:domain="plone" i18n:attributes="title" style="cursor:pointer"
|
||||||
|
@ -162,7 +162,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<tal:comment replace="nothing">Several pages in the phase</tal:comment>
|
<tal:comment replace="nothing">Several pages in the phase</tal:comment>
|
||||||
<span tal:condition="not: displayLink" tal:replace="python: tool.translate(label)"/>
|
<span tal:condition="not: displayLink" tal:replace="structure python: tool.translate(label)"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="portletMenu">
|
<div class="portletMenu">
|
||||||
<table cellpadding="0" cellspacing="0" width="100%"
|
<table cellpadding="0" cellspacing="0" width="100%"
|
||||||
|
|
Loading…
Reference in a new issue