From c88d9fc003ad47309db91b3ae9924ef3005a2eea Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 6 May 2020 12:15:45 +0000 Subject: [PATCH] [IMP] web: remove _lt from env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having _lt in the env doesn't make much sense, as it is useless at run time, and it would incite people to require 'web.env' to use it (at load time). The env should never be directly imported, it is automatically propagated from parents to children. To sum up, in Owl components: - when terms have to be translated at run time (e.g. in a function called when the user clicks on a button), the env is available and env._t must be used - when terms have to be translated at load time (e.g. a JS module defining a component with a translatable static property), one must require 'web.translation' and use function _lt it exports. closes odoo/odoo#50656 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/env.js | 4 ++-- addons/web/static/src/js/fields/basic_fields_owl.js | 4 +--- addons/web/static/tests/helpers/test_env.js | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/env.js b/addons/web/static/src/js/env.js index 41960151493..272a1f77ead 100644 --- a/addons/web/static/src/js/env.js +++ b/addons/web/static/src/js/env.js @@ -3,11 +3,12 @@ odoo.define("web.env", function (require) { const { jsonRpc } = require('web.ajax'); const { device, isDebug } = require("web.config"); - const { _lt, _t, bus, serviceRegistry } = require("web.core"); + const { bus, serviceRegistry } = require("web.core"); const dataManager = require('web.data_manager'); const { blockUI, unblockUI } = require("web.framework"); const rpc = require("web.rpc"); const session = require("web.session"); + const { _t } = require('web.translation'); const utils = require("web.utils"); const qweb = new owl.QWeb({ translateFn: _t }); @@ -131,7 +132,6 @@ odoo.define("web.env", function (require) { // See https://github.com/odoo/owl/blob/master/doc/reference/environment.md#content-of-an-environment // for more information on environments. return { - _lt, _t, bus, dataManager, diff --git a/addons/web/static/src/js/fields/basic_fields_owl.js b/addons/web/static/src/js/fields/basic_fields_owl.js index 8a5915410ee..507f883a85a 100644 --- a/addons/web/static/src/js/fields/basic_fields_owl.js +++ b/addons/web/static/src/js/fields/basic_fields_owl.js @@ -3,9 +3,7 @@ odoo.define('web.basic_fields_owl', function (require) { const AbstractField = require('web.AbstractFieldOwl'); const CustomCheckbox = require('web.CustomCheckbox'); - const core = require('web.core'); - - const _lt = core._lt; + const { _lt } = require('web.translation'); /** diff --git a/addons/web/static/tests/helpers/test_env.js b/addons/web/static/tests/helpers/test_env.js index 68659e366c3..b61024454ed 100644 --- a/addons/web/static/tests/helpers/test_env.js +++ b/addons/web/static/tests/helpers/test_env.js @@ -34,7 +34,6 @@ odoo.define('web.test_env', async function (require) { let testEnv = {}; const defaultEnv = { _t: env._t || Object.assign((s => s), { database }), - _lt: env._lt || Object.assign((s => s), { database }), bus: new Bus(), device: Object.assign({ isMobile: false }, env.device), isDebug: env.isDebug || (() => false),