From 6633a1102f6f9264d2da9a394945e4a49a23efd7 Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Mon, 11 Dec 2023 11:19:13 +0100 Subject: [PATCH] [FIX] web, survey: fix js 'translation error' for databases upgraded to 17.0 When a user connects to its database that has been freshly upgraded to 17.0 database, he gets the following JS crash: ``` TypeError: can't access property "defineLocale", moment is undefined @http://www.odoo.test/web/webclient/locale/fr_FR:13:10 @http://www.odoo.test/web/webclient/locale/fr_FR:9:4 @http://www.odoo.test/web/webclient/locale/fr_FR:10:2 ``` Before 17.0, the `/web/webclient/locale/` route was used to get the appropriate `momentjs` locale and was cached for a duration of 1 week. So when connecting to the upgraded database we will get the cached file, but as `momentjs` has been removed (see odoo/odoo@4327c062d820) it will crash. Now as `luxon` is using browser's `Intl` to get the translations, we can safely remove the call to that endpoint (it will always return an empty file anyway) closes odoo/odoo#145733 Signed-off-by: Samuel Degueldre (sad) --- addons/survey/static/src/js/survey_result.js | 11 +-------- addons/web/controllers/webclient.py | 23 +------------------ .../src/legacy/js/public/public_root.js | 14 +---------- 3 files changed, 3 insertions(+), 45 deletions(-) diff --git a/addons/survey/static/src/js/survey_result.js b/addons/survey/static/src/js/survey_result.js index e6a8905c209..c70280c727e 100644 --- a/addons/survey/static/src/js/survey_result.js +++ b/addons/survey/static/src/js/survey_result.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { _t } from "@web/core/l10n/translation"; -import { loadBundle, loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; import { SurveyImageZoomer } from "@survey/js/survey_image_zoomer"; import publicWidget from "@web/legacy/js/public/public_widget"; @@ -482,15 +482,6 @@ publicWidget.registry.SurveyResultWidget = publicWidget.Widget.extend({ // Widget //-------------------------------------------------------------------------- - /** - * @override - */ - willStart: function () { - var url = '/web/webclient/locale/' + (document.documentElement.getAttribute('lang') || 'en_US').replace('-', '_'); - var localeReady = loadJS(url); - return Promise.all([this._super.apply(this, arguments), localeReady]); - }, - /** * @override */ diff --git a/addons/web/controllers/webclient.py b/addons/web/controllers/webclient.py index a2fdfe10492..a1b29354cb0 100644 --- a/addons/web/controllers/webclient.py +++ b/addons/web/controllers/webclient.py @@ -29,32 +29,11 @@ def CONTENT_MAXAGE(): return http.STATIC_CACHE_LONG -MOMENTJS_LANG_CODES_MAP = { - "sr_RS": "sr_cyrl", - "sr@latin": "sr" -} - - class WebClient(http.Controller): + # FIXME: to be removed in master, deprecated since momentjs removal in commit 4327c062d820 @http.route('/web/webclient/locale/', type='http', auth="none") def load_locale(self, lang): - lang = MOMENTJS_LANG_CODES_MAP.get(lang, lang) - magic_file_finding = [lang.replace("_", '-').lower(), lang.split('_')[0]] - for code in magic_file_finding: - try: - return http.Response( - werkzeug.wsgi.wrap_file( - request.httprequest.environ, - file_open(f'web/static/lib/moment/locale/{code}.js', 'rb') - ), - content_type='application/javascript; charset=utf-8', - headers=[('Cache-Control', f'max-age={http.STATIC_CACHE}')], - direct_passthrough=True, - ) - except IOError: - _logger.debug("No moment locale for code %s", code) - return request.make_response("", headers=[ ('Content-Type', 'application/javascript'), ('Cache-Control', f'max-age={http.STATIC_CACHE}'), diff --git a/addons/web/static/src/legacy/js/public/public_root.js b/addons/web/static/src/legacy/js/public/public_root.js index a87c2d1a98e..86793f50a8c 100644 --- a/addons/web/static/src/legacy/js/public/public_root.js +++ b/addons/web/static/src/legacy/js/public/public_root.js @@ -8,7 +8,7 @@ import { registry } from '@web/core/registry'; import lazyloader from "@web/legacy/js/public/lazyloader"; import { makeEnv, startServices } from "@web/env"; -import { loadJS, templates } from '@web/core/assets'; +import { templates } from '@web/core/assets'; import { MainComponentsContainer } from "@web/core/main_components_container"; import { browser } from '@web/core/browser/browser'; import { _t } from "@web/core/l10n/translation"; @@ -24,8 +24,6 @@ function getLang() { return (html.getAttribute('lang') || 'en_US').replace('-', '_'); } const lang = cookie.get('frontend_lang') || getLang(); // FIXME the cookie value should maybe be in the ctx? -// momentjs don't have config for en_US, so avoid useless RPC -var localeDef = lang !== 'en_US' ? loadJS('/web/webclient/locale/' + lang.replace('-', '_')) : Promise.resolve(); /** @@ -55,16 +53,6 @@ export const PublicRoot = publicWidget.RootWidget.extend({ this.env = env; this.publicWidgets = []; }, - /** - * @override - */ - willStart: function () { - // TODO would be even greater to wait for localeDef only when necessary - return Promise.all([ - this._super.apply(this, arguments), - localeDef - ]); - }, /** * @override */