[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/<string:lang>` 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@4327c062d8)
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) <sad@odoo.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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/<string:lang>', 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}'),
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user