mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[12.0][ADD] base_default_lang_translate
This commit is contained in:
35
base_default_lang_translate/README.rst
Normal file
35
base_default_lang_translate/README.rst
Normal file
@@ -0,0 +1,35 @@
|
||||
**This file is going to be generated by oca-gen-addon-readme.**
|
||||
|
||||
*Manual changes will be overwritten.*
|
||||
|
||||
Please provide content in the ``readme`` directory:
|
||||
|
||||
* **DESCRIPTION.rst** (required)
|
||||
* INSTALL.rst (optional)
|
||||
* CONFIGURE.rst (optional)
|
||||
* **USAGE.rst** (optional, highly recommended)
|
||||
* DEVELOP.rst (optional)
|
||||
* ROADMAP.rst (optional)
|
||||
* HISTORY.rst (optional, recommended)
|
||||
* **CONTRIBUTORS.rst** (optional, highly recommended)
|
||||
* CREDITS.rst (optional)
|
||||
|
||||
Content of this README will also be drawn from the addon manifest,
|
||||
from keys such as name, authors, maintainers, development_status,
|
||||
and license.
|
||||
|
||||
A good, one sentence summary in the manifest is also highly recommended.
|
||||
|
||||
|
||||
Automatic changelog generation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.
|
||||
|
||||
Just put towncrier compatible changelog fragments into `readme/newsfragments`
|
||||
and the changelog file will be automatically generated and updated when a new fragment is added.
|
||||
|
||||
Please refer to `towncrier` documentation to know more.
|
||||
|
||||
NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
|
||||
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
|
||||
3
base_default_lang_translate/__init__.py
Normal file
3
base_default_lang_translate/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from . import models
|
||||
22
base_default_lang_translate/__manifest__.py
Normal file
22
base_default_lang_translate/__manifest__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Default Language Translation",
|
||||
"summary": """
|
||||
This modules allows to select a default language
|
||||
which is used for source terms in translations
|
||||
""",
|
||||
"version": "12.0.1.0.0",
|
||||
"development_status": "Beta",
|
||||
"category": "Uncategorized",
|
||||
"website": "https://github.com/OCA/server-backend",
|
||||
"author": "Le Filament, Mariano Ruiz, Odoo Community Association (OCA)",
|
||||
"maintainers": ["remi-filament"],
|
||||
"license": "AGPL-3",
|
||||
"application": False,
|
||||
"installable": True,
|
||||
"depends": [
|
||||
"base",
|
||||
],
|
||||
"data": [
|
||||
"views/res_lang_views.xml",
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * base_default_lang_translate
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-09-08 08:47+0000\n"
|
||||
"PO-Revision-Date: 2021-09-08 08:47+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_default_lang_translate
|
||||
#: code:addons/base_default_lang_translate/models/res_lang.py:16
|
||||
#, python-format
|
||||
msgid "Another language is already set by default"
|
||||
msgstr ""
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model,name:base_default_lang_translate.model_base
|
||||
msgid "Base"
|
||||
msgstr ""
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model.fields,field_description:base_default_lang_translate.field_res_lang__is_default_lang
|
||||
msgid "Default Language"
|
||||
msgstr ""
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model,name:base_default_lang_translate.model_res_lang
|
||||
msgid "Languages"
|
||||
msgstr ""
|
||||
|
||||
37
base_default_lang_translate/i18n/fr.po
Normal file
37
base_default_lang_translate/i18n/fr.po
Normal file
@@ -0,0 +1,37 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * base_default_lang_translate
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-09-08 08:47+0000\n"
|
||||
"PO-Revision-Date: 2021-09-08 08:47+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_default_lang_translate
|
||||
#: code:addons/base_default_lang_translate/models/res_lang.py:16
|
||||
#, python-format
|
||||
msgid "Another language is already set by default"
|
||||
msgstr "Une autre langue est déjà sélectionnée par défaut"
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model,name:base_default_lang_translate.model_base
|
||||
msgid "Base"
|
||||
msgstr ""
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model.fields,field_description:base_default_lang_translate.field_res_lang__is_default_lang
|
||||
msgid "Default Language"
|
||||
msgstr "Langue par défaut"
|
||||
|
||||
#. module: base_default_lang_translate
|
||||
#: model:ir.model,name:base_default_lang_translate.model_res_lang
|
||||
msgid "Languages"
|
||||
msgstr "Langues"
|
||||
4
base_default_lang_translate/models/__init__.py
Normal file
4
base_default_lang_translate/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from . import base
|
||||
from . import res_lang
|
||||
83
base_default_lang_translate/models/base.py
Normal file
83
base_default_lang_translate/models/base.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# Copyright 2021 Le Filament (https://le-filament.com)
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class Base(models.AbstractModel):
|
||||
_inherit = "base"
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
"""
|
||||
This part of code comes from
|
||||
https://bazaar.launchpad.net/~eoc/openobject-server/
|
||||
+ 6.1-overwrite_changes_translatable_fields/revision/4377
|
||||
|
||||
When the main language in the company is not English, you cannot change
|
||||
the value of a translatable field in the table if you not switch the
|
||||
client interface to 'en_US', because the new value will be written
|
||||
to ir_translation table instead of the table model.
|
||||
|
||||
This complicates usability, and the default language for "model" values
|
||||
hardcoded as 'en_US' should be configurable
|
||||
(see https://bugs.launchpad.net/openobject-server/+bug/400256).
|
||||
|
||||
With this patch, all changes made in selected default language will be
|
||||
written in 'en_US' too (in the table model) if :
|
||||
- vals are modified (it is later checked if vals are on
|
||||
translatable fields)
|
||||
- more than one language is installed
|
||||
- default language is set
|
||||
- current language = default language and not 'en_US'
|
||||
Also, translations in the other languages are changed to to_translate
|
||||
|
||||
"""
|
||||
result = super().write(vals)
|
||||
current_language = self.env.context.get("lang")
|
||||
default_language = (
|
||||
self.env["res.lang"].search(
|
||||
[("is_default_lang", "=", True), ("translatable", "=", True)], limit=1
|
||||
)
|
||||
or False
|
||||
)
|
||||
if (
|
||||
vals
|
||||
and len(self.env["res.lang"].get_installed()) > 1
|
||||
and default_language
|
||||
and current_language == default_language.code
|
||||
and current_language != "en_US"
|
||||
):
|
||||
vals_en = {}
|
||||
for field in vals:
|
||||
if field in self._fields and self._fields[field].translate:
|
||||
vals_en[field] = vals[field]
|
||||
self._update_trans_status(
|
||||
self._name, field, omit_langs=[default_language.code]
|
||||
)
|
||||
if vals_en:
|
||||
super().with_context(lang="en_US").write(vals_en)
|
||||
return result
|
||||
|
||||
def _update_trans_status(
|
||||
self, model, field, omit_langs=None, status="to_translate"
|
||||
):
|
||||
"""
|
||||
This function updates translations for this model / field / record (self)
|
||||
for all langs except omit_langs
|
||||
setting the state to status
|
||||
"""
|
||||
langs = [code for code, _ in self.env["res.lang"].get_installed()]
|
||||
Translation = self.env["ir.translation"]
|
||||
translations = Translation.search(
|
||||
[
|
||||
("type", "in", ("model", "model_terms")),
|
||||
("name", "=", "%s,%s" % (model, field)),
|
||||
("res_id", "=", self.id),
|
||||
("lang", "in", langs),
|
||||
("lang", "not in", omit_langs),
|
||||
]
|
||||
)
|
||||
for translation in translations:
|
||||
translation.state = status
|
||||
16
base_default_lang_translate/models/res_lang.py
Normal file
16
base_default_lang_translate/models/res_lang.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Copyright 2021 Le Filament (https://le-filament.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResLang(models.Model):
|
||||
_inherit = "res.lang"
|
||||
|
||||
is_default_lang = fields.Boolean("Default Language", default=False)
|
||||
|
||||
@api.constrains("is_default_lang")
|
||||
def _check_default(self):
|
||||
if self.search_count([("is_default_lang", "=", True)]) > 1:
|
||||
raise ValidationError(_("Another language is already set by default"))
|
||||
9
base_default_lang_translate/readme/CONFIGURE.rst
Normal file
9
base_default_lang_translate/readme/CONFIGURE.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
To configure this module, you need to:
|
||||
|
||||
#. Go to Settings > Translations > Languages
|
||||
#. Select the language you want to use as default (enter form view)
|
||||
#. Edit, tick "By default", Save
|
||||
|
||||
Note: only one language can be set as default.
|
||||
Should you want to change your default language, you would have to first untick previous one.
|
||||
2
base_default_lang_translate/readme/CONTRIBUTORS.rst
Normal file
2
base_default_lang_translate/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
* Rémi - Le Filament (https://le-filament.com)
|
||||
* Mariano Ruiz <https://launchpad.net/~marianoruiz>
|
||||
7
base_default_lang_translate/readme/DESCRIPTION.rst
Normal file
7
base_default_lang_translate/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
This modules allows to select a default language which is used for source terms in translations.
|
||||
Any update done with this default_language will be taken as source in translations
|
||||
and written in object directly.
|
||||
Also when updating a translatable term, all existing translations (but default language) will be set to to_translate
|
||||
|
||||
This module is useless in case your main language is en_US or in case you have only 1 language installed
|
||||
(in thoses cases, Odoo performs correctly).
|
||||
4
base_default_lang_translate/readme/USAGE.rst
Normal file
4
base_default_lang_translate/readme/USAGE.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to any model with translatable fields (e.g. product, survey, etc.)
|
||||
#. Update a translatable field and Save, source term and object field in database will be set with your new value
|
||||
BIN
base_default_lang_translate/static/description/icon.png
Normal file
BIN
base_default_lang_translate/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
79
base_default_lang_translate/static/description/icon.svg
Normal file
79
base_default_lang_translate/static/description/icon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 45 KiB |
28
base_default_lang_translate/views/res_lang_views.xml
Normal file
28
base_default_lang_translate/views/res_lang_views.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="res_lang_default_form" model="ir.ui.view">
|
||||
<field name="name">res.lang.default.form</field>
|
||||
<field name="model">res.lang</field>
|
||||
<field name="inherit_id" ref="base.res_lang_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="translatable" position="after">
|
||||
<field name="is_default_lang" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="res_lang_default_tree" model="ir.ui.view">
|
||||
<field name="name">res.lang.default.tree</field>
|
||||
<field name="model">res.lang</field>
|
||||
<field name="inherit_id" ref="base.res_lang_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="translatable" position="after">
|
||||
<field name="is_default_lang" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user