mirror of https://github.com/OCA/web.git
[13.0][MIG]web_translate_dialog
parent
4954513714
commit
f46902d013
|
@ -80,6 +80,7 @@ Contributors
|
|||
* Serpent Consulting Services Pvt. Ltd. <jay.vora@serpentcs.com>
|
||||
* Timon Tschanz <timon.tschanz@camptocamp.ch>
|
||||
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||
* Forma Shah <foram.shah@initos.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"version": "13.0.1.0.0",
|
||||
"category": "Web",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"author": "Camptocamp, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"author": "Camptocamp, Tecnativa, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"application": False,
|
||||
"installable": True,
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# Copyright 2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo import api, models
|
||||
from odoo import models
|
||||
|
||||
|
||||
class BaseModel(models.BaseModel):
|
||||
|
||||
_inherit = "base"
|
||||
|
||||
@api.multi
|
||||
def get_field_translations(self, field_names):
|
||||
"""Get only the existing translations for specified field
|
||||
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
* Serpent Consulting Services Pvt. Ltd. <jay.vora@serpentcs.com>
|
||||
* Timon Tschanz <timon.tschanz@camptocamp.ch>
|
||||
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||
* Foram Shah <foram.shah@initos.com>
|
||||
|
|
|
@ -39,12 +39,9 @@ odoo.define("web_translate_dialog.translate_dialog", function(require) {
|
|||
this.single_field = single_field;
|
||||
this.languages = null;
|
||||
this.languages_loaded = $.Deferred();
|
||||
this.lang_data = new data.DataSetSearch(
|
||||
this,
|
||||
"res.lang",
|
||||
parent.searchView.dataset.get_context(),
|
||||
[["translatable", "=", "1"]]
|
||||
);
|
||||
this.lang_data = new data.DataSetSearch(this, "res.lang", parent.context, [
|
||||
["active", "=", "1"],
|
||||
]);
|
||||
this.lang_data.set_sort(["tr_sequence asc", "id asc"]);
|
||||
this.lang_data.read_slice(["code", "name"]).then(this.on_languages_loaded);
|
||||
},
|
||||
|
@ -206,7 +203,7 @@ odoo.define("web_translate_dialog.translate_dialog", function(require) {
|
|||
kwargs: {
|
||||
field_names: this.translatable_fields,
|
||||
},
|
||||
}).done(function(res) {
|
||||
}).then(function(res) {
|
||||
if (res[self.res_id]) {
|
||||
_.each(res[self.res_id], function(translation, lang) {
|
||||
self.set_fields_values(lang, translation);
|
||||
|
@ -234,7 +231,7 @@ odoo.define("web_translate_dialog.translate_dialog", function(require) {
|
|||
});
|
||||
_.each(translations, function(text, code) {
|
||||
save_mutex.exec(function() {
|
||||
var done = new $.Deferred(); // Holds the mutex
|
||||
var done = new $.Deferred();
|
||||
|
||||
var context = new Context(session.user_context, {lang: code});
|
||||
rpc.query({
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<t t-foreach="widget.translatable_fields" t-as="field_name">
|
||||
<t
|
||||
t-set="field"
|
||||
t-value="widget.view.searchView.fields[field_name]"
|
||||
t-value="widget.view.renderer.state.fields[field_name]"
|
||||
/>
|
||||
<tr t-att-data-field="field_name">
|
||||
<td
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Copyright 2021 InitOS Gmbh
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from . import test_web_translate_dialog
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright 2021 InitOS Gmbh
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestWebTranslateDialog(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestWebTranslateDialog, self).setUp()
|
||||
self.env["res.lang"].load_lang("de_DE")
|
||||
self.partner_title = self.env["res.partner.title"].create({"name": "Doctor"})
|
||||
|
||||
def test_language_translations(self):
|
||||
translation = self.env["ir.translation"].create(
|
||||
{
|
||||
"type": "model",
|
||||
"name": "res.partner.title,name",
|
||||
"lang": "de_DE",
|
||||
"res_id": self.partner_title.id,
|
||||
"src": "Doctor",
|
||||
"value": "Arzt",
|
||||
"state": "translated",
|
||||
}
|
||||
)
|
||||
translation_value = translation.read(["value"])
|
||||
self.assertEqual(translation_value[0]["value"], "Arzt")
|
||||
|
||||
def test_get_field_translations(self):
|
||||
translation_id = self.env["ir.translation"].create(
|
||||
{
|
||||
"type": "model",
|
||||
"name": "res.partner.title,name",
|
||||
"lang": "de_DE",
|
||||
"res_id": self.partner_title.id,
|
||||
"src": "Doctor",
|
||||
"value": "Arzt",
|
||||
"state": "translated",
|
||||
}
|
||||
)
|
||||
results = self.partner_title.get_field_translations(["name"])
|
||||
res = results[translation_id.res_id][translation_id.lang]
|
||||
if res:
|
||||
self.assertEqual(res.get("name"), "Arzt")
|
|
@ -5,10 +5,10 @@
|
|||
<field name="inherit_id" ref="base.res_lang_form" />
|
||||
<field name="model">res.lang</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="translatable" position="after">
|
||||
<field name="active" position="after">
|
||||
<field
|
||||
name="tr_sequence"
|
||||
attrs="{'invisible': [('translatable', '!=', True)]}"
|
||||
attrs="{'invisible': [('active', '!=', True)]}"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
|
|
Loading…
Reference in New Issue