Commit 8b39f62c authored by Jérome Perrin's avatar Jérome Perrin

fix Base_TranslateString for use with Localizer,

added a version of the script that respects naming conventions


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5323 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f07d9747
...@@ -66,34 +66,11 @@ ...@@ -66,34 +66,11 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>def translate(domain, msgid, mapping=None, context=None, target_language=None, default=None):\n <value> <string>context.log(\'Base_TranslateString (%s)\' % msg,\n
localizer = context.Localizer\n \'Base_TranslateString breaks naming convention and will be removed, \'\\\n
msg_catalog_binding = { "ui" : "erp5_ui"\n \'please use Base_translateString instead\')\n
, "content": "erp5_content"\n
}\n
localizer_cat_id = None\n
if domain in msg_catalog_binding.keys():\n
localizer_cat_id = msg_catalog_binding[domain]\n
else:\n
localizer_cat_id = domain\n
if localizer_cat_id not in localizer.objectIds():\n
return msgid\n
localizer_cat = localizer[localizer_cat_id]\n
if default == None:\n
default = []\n
return localizer_cat.gettext( message = msgid\n
, lang = target_language\n
, default = default\n
)\n
\n \n
return translate(catalog, msg, **kw).encode(encoding)\n return context.Base_translateString(msg, catalog=catalog, encoding=encoding, **kw)\n
\n
#from Products.CMFCore.utils import getToolByName\n
#translation_service = getToolByName(context, \'translation_service\', None)\n
#if translation_service is not None :\n
# return translation_service.translate(catalog, msg, **kw).encode(encoding)\n
#else :\n
# return msg\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -144,9 +121,8 @@ return translate(catalog, msg, **kw).encode(encoding)\n ...@@ -144,9 +121,8 @@ return translate(catalog, msg, **kw).encode(encoding)\n
<string>catalog</string> <string>catalog</string>
<string>encoding</string> <string>encoding</string>
<string>kw</string> <string>kw</string>
<string>None</string>
<string>translate</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string>
<string>_apply_</string> <string>_apply_</string>
</tuple> </tuple>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value> <string encoding="base64">O/INCg==</string> </value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.CMFCore.utils import getToolByName\n
translation_service = getToolByName(context, \'Localizer\', None)\n
if translation_service is not None :\n
return translation_service.translate(catalog, msg, **kw).encode(encoding)\n
else :\n
return msg\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_skins/erp5_core/Base_translateString</string> </value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>msg, catalog="ui", encoding=\'utf8\', **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>msg</string>
<string>catalog</string>
<string>encoding</string>
<string>kw</string>
<string>Products.CMFCore.utils</string>
<string>getToolByName</string>
<string>context</string>
<string>None</string>
<string>translation_service</string>
<string>_getattr_</string>
<string>_apply_</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<string>ui</string>
<string>utf8</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_translateString</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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