← Back to team overview

openerp-expert-localization team mailing list archive

[Merge] lp:~numerigraphe/openobject-addons/extra-base-translation-copy into lp:openobject-addons/extra-5.0

 

Numérigraphe has proposed merging lp:~numerigraphe/openobject-addons/extra-base-translation-copy into lp:openobject-addons/extra-5.0.

Requested reviews:
  OpenERP Localization Experts (openerp-expert-localization)
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~numerigraphe/openobject-addons/extra-base-translation-copy/+merge/67418

As a workaround for Bug #400256 in v5, this branch adds a wizard to copy all the translations of a language to English.
I would be very pleased to have your opinion on the way this is achieved and the quality of the code.

Rationale: 
This is useful because English is the default language for all objects in
OpenERP, so when users work in any another language they will have to manage
translations to and from the English language.
When they don't, operations such as object copying or renaming will produce
unexpected behaviors because the English names are not updated.
To tackle this in an environment where English is not used by the users,
this module adds a wizard in Administration > Translations to let you copy
all the strings in one language to the English translations.


-- 
https://code.launchpad.net/~numerigraphe/openobject-addons/extra-base-translation-copy/+merge/67418
Your team OpenERP Localization Experts is requested to review the proposed merge of lp:~numerigraphe/openobject-addons/extra-base-translation-copy into lp:openobject-addons/extra-5.0.
=== added directory 'base_translation_copy'
=== added file 'base_translation_copy/__init__.py'
--- base_translation_copy/__init__.py	1970-01-01 00:00:00 +0000
+++ base_translation_copy/__init__.py	2011-07-09 08:12:37 +0000
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution	
+#    This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import wizard

=== added file 'base_translation_copy/__terp__.py'
--- base_translation_copy/__terp__.py	1970-01-01 00:00:00 +0000
+++ base_translation_copy/__terp__.py	2011-07-09 08:12:37 +0000
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+    'name' : 'Copy translations from a language to English',
+    'version' : '0.1',
+    'author' : u'Numérigraphe',
+    'category' : 'Custom',
+    'depends' : [],
+    'description': """\
+This module lets you copy all the translations of a language to English.
+
+This is useful because English is the default language for all objects in
+OpenERP, so when users work in any another language they will have to manage
+translations to and from the English language.
+When they don't, operations such as object copying or renaming will produce
+unexpected behaviors because the English names are not updated.
+To tackle this in an environment where English is not used by the users,
+this module adds a wizard in Administration > Translations to let you copy
+all the strings in one language to the English translations.""",
+    'demo_xml' : [],
+    'init_xml' : [],
+    'update_xml' : ['copy_translations_wizard.xml'],
+    'active': False,
+    'installable': True,
+    'license' : 'GPL-3',
+}
+

=== added file 'base_translation_copy/copy_translations_wizard.xml'
--- base_translation_copy/copy_translations_wizard.xml	1970-01-01 00:00:00 +0000
+++ base_translation_copy/copy_translations_wizard.xml	2011-07-09 08:12:37 +0000
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="wizard_copy_translations_view" model="ir.ui.view">
+            <field name="name">Copy model translations to English</field>
+            <field name="model">wizard.translation.copy</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form col="3" string="Copy translations">
+                    <notebook>
+                        <page string="Copy translations to English">
+                            <group col="2" fill="0" states="choose">
+                                <separator colspan="2" string="Copy translations to English"/>
+                                <field name="lang" width="300"/>
+                                <field invisible="1" name="state"/>
+                            </group>
+                            <group col="1" fill="0" states="done">
+                                <separator string="Copy done."/>
+                            </group>
+                        </page>
+                        <page string="Help">
+                            <label align="0.0" colspan="4" string="This wizard lets you copy all the translations of a language to English."/>
+                            <label align="0.0" colspan="4" string="This is useful because English is the default language for all objects in OpenERP, so when users work in any another language they will have to manage translations to and from the English language."/>
+                            <label align="0.0" colspan="4" string="When they don't, operations such as object copying or renaming will produce unexpected behaviors, because the English names won't be updated."/>
+                            <label align="0.0" colspan="4" string="In such cases, this wizard will let you generate pseudo-English values by copying a language that users actually use."/>
+                        </page>
+                    </notebook>
+
+
+                    <group col="2" colspan="3" fill="0">
+                        <button icon="gtk-cancel" name="act_cancel" special="cancel" states="choose" string="Cancel" type="object"/>
+                        <button icon="gtk-ok" name="act_copy" states="choose" string="Copy translations" type="object"/>
+                        <button icon="gtk-close" name="act_destroy" special="cancel" states="done" string="Close" type="object"/>
+                    </group>
+                </form>
+            </field>
+        </record>
+
+        <record id="action_wizard_copy_translation" model="ir.actions.act_window">
+            <field name="name">Copy a Translation to English</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="res_model">wizard.translation.copy</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="target">new</field>
+        </record>
+        <menuitem action="action_wizard_copy_translation" id="menu_wizard_copy_translations" parent="base.menu_translation"/>
+    </data>
+</openerp>

=== added directory 'base_translation_copy/i18n'
=== added file 'base_translation_copy/i18n/fr_FR.po'
--- base_translation_copy/i18n/fr_FR.po	1970-01-01 00:00:00 +0000
+++ base_translation_copy/i18n/fr_FR.po	2011-07-09 08:12:37 +0000
@@ -0,0 +1,150 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* base_copy_translations
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 5.0.16\n"
+"Report-Msgid-Bugs-To: support@xxxxxxxxxxx\n"
+"POT-Creation-Date: 2011-07-09 07:35:54+0000\n"
+"PO-Revision-Date: 2011-07-09 07:35:54+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: base_copy_translations
+#: constraint:ir.model:0
+msgid "The Object name must start with x_ and not contain any special character !"
+msgstr "Le nom de l'objet doit commencer avec x_ et ne pas contenir de charactères spéciaux !"
+
+#. module: base_copy_translations
+#: model:ir.module.module,description:base_copy_translations.module_meta_information
+msgid "Ce module permet de copier toutes les traductions d'une langue vers l'anglais.\n"
+"\n"
+"Cela s'avère utile car l'anglais est la langue par défaut de tous les objets\n"
+"OpenERP : les utilisateurs qui parlent d'autres langues doivent donc gérer\n"
+"les traductions entre l'anglais et leur langue.\n"
+"Sans cela, les opérations comme la copie d'objet ou le changement de nom\n"
+"produisent des résultats incorrects car les traductions anglaises ne sont pas\n"
+"à jour.\n"
+"Pour faire face à cela dans un environnement où les utilisateurs n'utilisent\n"
+"pas l'anglais, ce module ajoute un assistant dans \n"
+"Administration > Traductions qui permet de copier toutes les chaînes d'une\n"
+"langue vers les traductions en Anglais."
+msgstr "Ce module permet de copier toutes les traductions d'une langue vers l'anglais.\n"
+"\n"
+"Cela s'avère utile car l'anglais est la langue par défaut de tous les objets\n"
+"OpenERP : les utilisateurs qui parlent d'autres langues doivent donc gérer\n"
+"les traductions entre l'anglais et leur langue.\n"
+"Sans cela, les opérations comme la copie d'objet ou le changement de nom\n"
+"produisent des résultats incorrects car les traductions anglaises ne sont pas\n"
+"à jour.\n"
+"Pour faire face à cela dans un environnement où les utilisateurs n'utilisent\n"
+"pas l'anglais, ce module ajoute un assistant dans \n"
+"Administration > Traductions qui permet de copier toutes les chaînes d'une\n"
+"langue vers les traductions en Anglais."
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "This is useful because English is the default language for all objects in OpenERP, so when users work in any another language they will have to manage translations to and from the English language."
+msgstr "Cela s'avère utile car l'anglais est la langue par défaut de tous les objets OpenERP : les utilisateurs qui parlent d'autres langues doivent donc gérer les traductions entre l'anglais et leur langue."
+
+#. module: base_copy_translations
+#: selection:wizard.translation.copy,state:0
+msgid "done"
+msgstr "terminé"
+
+#. module: base_copy_translations
+#: constraint:ir.actions.act_window:0
+msgid "Invalid model name in the action definition."
+msgstr "Invalid model name in the action definition."
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "In such cases, this wizard will let you generate pseudo-English values by copying a language that users actually use."
+msgstr "Dans de tels cas, ce module permet de générer des valeurs pseudo-anglaises en recopiant les traductions de la langue des utilisateurs."
+
+#. module: base_copy_translations
+#: model:ir.actions.act_window,name:base_copy_translations.action_wizard_copy_translation
+#: model:ir.ui.menu,name:base_copy_translations.menu_wizard_copy_translations
+msgid "Copie une Traduction vers l'anglais"
+msgstr "Copie une Traduction vers l'anglais"
+
+#. module: base_copy_translations
+#: field:wizard.translation.copy,state:0
+msgid "unknown"
+msgstr "unknown"
+
+#. module: base_copy_translations
+#: selection:wizard.translation.copy,state:0
+msgid "choose"
+msgstr "choose"
+
+#. module: base_copy_translations
+#: constraint:ir.ui.view:0
+msgid "Invalid XML for View Architecture!"
+msgstr "Invalid XML for View Architecture!"
+
+#. module: base_copy_translations
+#: field:wizard.translation.copy,lang:0
+msgid "Language"
+msgstr "Language"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "This wizard lets you copy all the translations of a language to English."
+msgstr "Cet assistant permet de copier toutes les Traductions d'une langue vers l'anglais."
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Copy translations"
+msgstr "Copier les Traductions"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Copy translations to English"
+msgstr "Copier les Traductions vers l'anglais"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Help"
+msgstr "Aide"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Copy done."
+msgstr "Copie terminée."
+
+#. module: base_copy_translations
+#: model:ir.model,name:base_copy_translations.model_wizard_translation_copy
+msgid "wizard.translation.copy"
+msgstr "wizard.translation.copy"
+
+#. module: base_copy_translations
+#: model:ir.module.module,shortdesc:base_copy_translations.module_meta_information
+msgid "Copier les Traductions d'une langue vers l'anglais"
+msgstr "Copier les Traductions d'une langue vers l'anglais"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "When they don't, operations such as object copying or renaming will produce unexpected behaviors, because the English names won't be updated."
+msgstr "Sans cela, les opérations comme la copie d'objet ou le changement de nom produisent des résultats incorrects car les traductions anglaises ne sont pas à jour."
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Cancel"
+msgstr "Annuler"
+
+#. module: base_copy_translations
+#: view:wizard.translation.copy:0
+msgid "Close"
+msgstr "Fermer"
+
+#. module: base_copy_translations
+#: help:wizard.translation.copy,lang:0
+msgid "All the strings in English will be overwritten with the translations from language."
+msgstr "Toutes les chaînes anglaises seront écrasées et remplacées par les Traductions en cette langue."
+

=== added directory 'base_translation_copy/wizard'
=== added file 'base_translation_copy/wizard/__init__.py'
--- base_translation_copy/wizard/__init__.py	1970-01-01 00:00:00 +0000
+++ base_translation_copy/wizard/__init__.py	2011-07-09 08:12:37 +0000
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution	
+#    This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import wizard_copy_translations
\ No newline at end of file

=== added file 'base_translation_copy/wizard/wizard_copy_translations.py'
--- base_translation_copy/wizard/wizard_copy_translations.py	1970-01-01 00:00:00 +0000
+++ base_translation_copy/wizard/wizard_copy_translations.py	2011-07-09 08:12:37 +0000
@@ -0,0 +1,99 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution	
+#    This module is copyright (C) 2011 Numérigraphe SARL. All Rights Reserved.
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import wizard
+import tools
+import pooler
+import netsvc
+from osv import fields,osv
+from tools.translate import _
+
+class wizard_copy_translations(osv.osv_memory):
+
+    def _get_languages(self, cr, uid, context):
+        lang_obj = pooler.get_pool(cr.dbname).get('res.lang')
+        ids = lang_obj.search(cr, uid, ['&', ('active', '=', True), ('code', '<>', 'en_US'), ('translatable', '=', True),])
+        langs = lang_obj.browse(cr, uid, ids)
+        return [(lang.code, lang.name) for lang in langs]
+    
+    def act_cancel(self, cr, uid, ids, context=None):
+        return {'type':'ir.actions.act_window_close' }
+
+    def act_destroy(self, *args):
+        return {'type':'ir.actions.act_window_close' }
+
+    def act_copy(self, cr, uid, ids, context=None):
+        """
+        Copy the translations from a language to en_US.
+        
+        When object model fields are translatable, only the English version is
+        stored in the database table.
+        The translations into other languages are stored as
+        ir_translation object resources.
+        This method will copy a translation to the English version in every
+        object."""
+        
+        logger = netsvc.Logger()
+        this = self.browse(cr, uid, ids)[0]
+        trans_obj = pooler.get_pool(cr.dbname).get('ir.translation')
+        logger.notifyChannel("wizard_copy_translations",
+            netsvc.LOG_DEBUG,
+            "Copying translations from %s to en_US" % this.lang)
+        # Read all the model translations in the new language
+        trans_ids = trans_obj.search(cr, uid,
+            [('type', '=', 'model'),
+             ('lang', '=', this.lang)], context=None)	
+        translations = trans_obj.browse(cr, uid, trans_ids, context=None)
+        for trans in translations:
+            # Get the object and field name
+            (model, field) = trans.name.split(',', 1)
+            # Read the English version from the object
+            object = pooler.get_pool(cr.dbname).get(model)
+            value = object.read(cr, uid, trans.res_id, fields=[field],
+                context=None)
+            if value and value[field] != trans.value:
+                logger.notifyChannel("wizard_copy_translations",
+                    netsvc.LOG_DEBUG,
+                    "Changing %s in %s id %d from %s to %s" % (
+                        field, model, trans.res_id, value[field], trans.value))
+                # Copy the versions in the new language to the English version
+                # We could pass trans.res_id as a single integer,
+                # but some buggy objects would break
+                object.write(cr, uid, [trans.res_id], {field: trans.value},
+                    context=None)
+        logger.notifyChannel("wizard_copy_translations",
+            netsvc.LOG_DEBUG, "Done")
+        return self.write(cr, uid, ids, {'state':'done'}, context=context)
+
+    _name = "wizard.translation.copy"
+    _columns = {
+            'lang': fields.selection(_get_languages, 'Language', help='All the strings in English will be overwritten with the translations from language.'),
+            'state': fields.selection( ( ('choose','choose'),   # choose language
+                                         ('done','done'),       # Copy done
+                                       ) ),
+            }
+    _defaults = {
+            'state': lambda *a: 'choose'
+                }
+wizard_copy_translations()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+


Follow ups