[IMP] qweb: expose translatable attributes

This commit allows owl users to add any attribute to the list of
translatable attributes.

closes #903
This commit is contained in:
Géry Debongnie
2021-09-20 16:51:20 +02:00
committed by aab-odoo
parent c0a62dfd05
commit 8464a1b04e
4 changed files with 43 additions and 4 deletions
@@ -3943,6 +3943,20 @@ exports[`t-set value priority 1`] = `
}"
`;
exports[`translation support can add additional attributes to the list of translatable attributes 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"test\\"
let h = this.h;
let _1 = 'word';
let _2 = 'mot';
let c3 = [], p3 = {key:3,attrs:{tomato: _1,potato: _2}};
let vn3 = h('div', p3, c3);
c3.push({text: \`text\`});
return vn3;
}"
`;
exports[`translation support can translate node content 1`] = `
"function anonymous(context, extra
) {
+13
View File
@@ -1,4 +1,5 @@
import { QWeb } from "../../src/qweb/index";
import { config } from "../../src/index";
import { nextTick, normalize, renderToDOM, renderToString, trim } from "../helpers";
import { patch } from "../../src/vdom";
@@ -13,6 +14,7 @@ let qweb: QWeb;
beforeEach(() => {
QWeb.TEMPLATES = {};
QWeb.nextId = 1;
qweb = new QWeb();
});
@@ -2211,6 +2213,17 @@ describe("translation support", () => {
);
});
test("can add additional attributes to the list of translatable attributes", () => {
const translations = {
word: "mot",
};
const translateFn = (expr) => translations[expr] || expr;
const qweb = new QWeb({ translateFn });
config.translatableAttributes.push("potato");
qweb.addTemplate("test", `<div tomato="word" potato="word">text</div>`);
expect(renderToString(qweb, "test")).toBe('<div tomato="word" potato="mot">text</div>');
});
test("translation is done on the trimmed text, with extra spaces readded after", () => {
const translations = {
word: "mot",