Commit 0fcc1321 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support user-defined languages.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30765 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4e815660
...@@ -4427,6 +4427,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4427,6 +4427,9 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
path = posixpath.join(lang, catalog) path = posixpath.join(lang, catalog)
mc = localizer._getOb(catalog) mc = localizer._getOb(catalog)
self._objects[path] = mc.manage_export(lang) self._objects[path] = mc.manage_export(lang)
if lang not in self._objects:
name = localizer.get_language_name(lang)
self._objects[lang] = name
def preinstall(self, context, installed_bt, **kw): def preinstall(self, context, installed_bt, **kw):
modified_object_list = {} modified_object_list = {}
...@@ -4453,28 +4456,49 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4453,28 +4456,49 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
for path, po in self._objects.items(): for key in sorted(self._objects.keys()):
if update_dict.has_key(path) or force: if update_dict.has_key(key) or force:
if not force: if not force:
action = update_dict[path] action = update_dict[key]
if action == 'nothing': if action == 'nothing':
continue continue
path = path.split('/') path = key.split('/')
if len(path) == 2: if len(path) == 1:
lang = path[0]
catalog = None
elif len(path) == 2:
lang = path[0] lang = path[0]
catalog = path[1] catalog = path[1]
else: else:
lang = path[-3] lang = path[-3]
catalog = path[-2] catalog = path[-2]
if lang not in localizer.get_languages():
localizer.manage_addLanguage(lang) if catalog is None:
mc = localizer._getOb(catalog) name = self._objects[key]
if lang not in mc.get_languages(): for lang_dict in localizer.get_all_languages():
mc.manage_addLanguage(lang) if lang_dict['code'] == lang:
mc.manage_import(lang, po) # When the Localizer has the language as a user-defined
# language, make sure that the name is updated.
old_name = localizer.get_user_defined_language_name(lang)
if old_name is not None and old_name != name:
localizer._del_user_defined_language(lang)
localizer._add_user_defined_language(name, lang)
break
else:
# if the Localizer does not know the language code, it must be
# defined as a user-defined language.
localizer._add_user_defined_language(name, lang)
else:
po = self._objects[key]
if lang not in localizer.get_languages():
localizer.manage_addLanguage(lang)
mc = localizer._getOb(catalog)
if lang not in mc.get_languages():
mc.manage_addLanguage(lang)
mc.manage_import(lang, po)
else: else:
BaseTemplateItem.install(self, context, trashbin, **kw) BaseTemplateItem.install(self, context, trashbin, **kw)
for lang, catalogs in self._archive.items(): for lang, catalogs in self._archive.iteritems():
if lang not in localizer.get_languages(): if lang not in localizer.get_languages():
localizer.manage_addLanguage(lang) localizer.manage_addLanguage(lang)
for catalog, po in catalogs.items(): for catalog, po in catalogs.items():
...@@ -4484,22 +4508,35 @@ class MessageTranslationTemplateItem(BaseTemplateItem): ...@@ -4484,22 +4508,35 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
mc.manage_import(lang, po) mc.manage_import(lang, po)
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0: if len(self._objects) == 0:
return return
root_path = os.path.join(bta.path, self.__class__.__name__) root_path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=root_path) bta.addFolder(name=root_path)
for key in self._objects.keys(): for key, obj in self._objects.iteritems():
obj = self._objects[key]
path = os.path.join(root_path, key) path = os.path.join(root_path, key)
bta.addFolder(name=path) bta.addFolder(name=path)
f = open(path+os.sep+'translation.po', 'wb') if '/' in key:
f.write(str(obj)) bta.addObject(obj, os.path.join(path, 'translation'), ext='.po')
f.close() else:
xml_data = ['<language>']
xml_data.append(' <code>%s</code>' % (escape(key), ))
xml_data.append(' <name>%s</name>' % (escape(obj), ))
xml_data.append('</language>')
bta.addObject('\n'.join(xml_data), os.path.join(path, 'language'))
def _importFile(self, file_name, file): def _importFile(self, file_name, file):
if posixpath.split(file_name)[1] == 'translation.po': name = posixpath.split(file_name)[1]
if name == 'translation.po':
text = file.read() text = file.read()
self._objects[file_name[:-3]] = text self._objects[file_name[:-3]] = text
elif name == 'language.xml':
xml = parse(file)
language_element = xml.getElementsByTagName('language')[0]
name_element = language_element.getElementsByTagName('name')[0]
name = str(name_element.childNodes[0].data)
code_element = language_element.getElementsByTagName('code')[0]
code = str(code_element.childNodes[0].data)
self._objects[code] = name
class LocalRolesTemplateItem(BaseTemplateItem): class LocalRolesTemplateItem(BaseTemplateItem):
......
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