[IMP] core: void model translation
Before this commit, there is no way to "void" model translations, i.e., discard a translation and let the value fall back on the 'en_US' value. The API of methods write() and update_field_translations() can only overwrite the translations for the specified languages. After this commit, calling update_field_translations() with a falsy value except the empty string discards the corresponding translation value, and let the value of the field in the given language fall back on the 'en_US' value of the field. X-original-commit: 5434fb845c393327db377abf872c448f4860a7d3 Part-of: odoo/odoo#111869
This commit is contained in:
@@ -74,10 +74,10 @@ export class TranslationDialog extends Component {
|
||||
if (!translations[term.lang]) {
|
||||
translations[term.lang] = {};
|
||||
}
|
||||
const source = term.value ? term.value : term.source;
|
||||
translations[term.lang][source] = updatedTermValue;
|
||||
const oldTermValue = term.value ? term.value : term.source;
|
||||
translations[term.lang][oldTermValue] = updatedTermValue || term.source;
|
||||
} else {
|
||||
translations[term.lang] = updatedTermValue;
|
||||
translations[term.lang] = updatedTermValue || false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -319,9 +319,9 @@ QUnit.module("Fields", (hooks) => {
|
||||
if (call_get_field_translations === 1) {
|
||||
return Promise.resolve([
|
||||
[
|
||||
{ lang: "en_US", source: "yop", value: "english value" },
|
||||
{ lang: "fr_BE", source: "yop", value: "valeur français" },
|
||||
{ lang: "es_ES", source: "yop", value: "" },
|
||||
{ lang: "en_US", source: "english value", value: "english value" },
|
||||
{ lang: "fr_BE", source: "english value", value: "valeur français" },
|
||||
{ lang: "es_ES", source: "english value", value: "english value" },
|
||||
],
|
||||
{ translation_type: "char", translation_show_source: false },
|
||||
]);
|
||||
@@ -330,8 +330,8 @@ QUnit.module("Fields", (hooks) => {
|
||||
if (route === "/web/dataset/call_kw/partner/update_field_translations") {
|
||||
assert.deepEqual(
|
||||
args[2],
|
||||
{ en_US: "english value", es_ES: "" },
|
||||
"the new translation value should be written"
|
||||
{ en_US: "english value", es_ES: false },
|
||||
"the new translation value should be written and the value false voids the translation"
|
||||
);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
@@ -401,8 +401,8 @@ QUnit.module("Fields", (hooks) => {
|
||||
);
|
||||
assert.strictEqual(
|
||||
translations[2].value,
|
||||
"",
|
||||
"Spanish translation should be an empty string"
|
||||
"english value",
|
||||
"Spanish translation should fallback to the English translation"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user