summaryrefslogtreecommitdiff
path: root/addons/website_event_track
diff options
context:
space:
mode:
authorPierre Paridans <app@odoo.com>2020-09-24 12:50:33 +0000
committerPierre Paridans <app@odoo.com>2020-10-02 12:21:18 +0000
commit20eddda77d0ed6f2bb9b61d8ae4194e960ccc4ff (patch)
treecd65c81fd14ef6801d4aac9c6e9fbea211495264 /addons/website_event_track
parenta014a6c9e3baced22b158d6d8b4199bdae7562b9 (diff)
[FIX] website_event_track: properly match custom lang in url
In multilanguage website, URLs are automatically prefixed with the language (beside the default language) but only the default language-slug were supported (e.g. "en", "en_US"...). This commit supports also customized language-slug, which can actually be any string, for the ServiceWorker's scope.
Diffstat (limited to 'addons/website_event_track')
-rw-r--r--addons/website_event_track/static/src/js/website_event_pwa_widget.js29
1 files changed, 9 insertions, 20 deletions
diff --git a/addons/website_event_track/static/src/js/website_event_pwa_widget.js b/addons/website_event_track/static/src/js/website_event_pwa_widget.js
index 7953c9c132b..09a3f635417 100644
--- a/addons/website_event_track/static/src/js/website_event_pwa_widget.js
+++ b/addons/website_event_track/static/src/js/website_event_pwa_widget.js
@@ -80,31 +80,20 @@ odoo.define("website_event_track.website_event_pwa_widget", function (require) {
//--------------------------------------------------------------------------
/**
- * Returns the website's language from the URL
- *
- * Note: this method performs a matching against both the simple (eg. "en") and complete (eg. "en_US")
- * language formatting in the url. This is required as the cookie always returns the complete
- * form but the URL can use both, depending on the language (eg. "en_US" => "en" but "en_UK" => "en_UK").
- * @private
- * @return {String}
- */
- _getLangPrefix: function () {
- var lang = utils.get_cookie("frontend_lang");
- var path = window.location.pathname;
- var matches = path.match(new RegExp("^\/?(" + lang + "|" + lang.slice(0, 2) + ")\/"));
- if (lang && matches && matches[1]) {
- return "/" + matches[1];
- }
- return "";
- },
-
- /**
* Returns the PWA's scope
+ *
+ * Note: this method performs a matching to handle URLs with the language prefix.
+ * Typically this prefix is in the form of "en" or "en_US" but it can also be
+ * any string using the customization options in the Website's settings.
* @private
* @returns {String}
*/
_getScope: function () {
- return this._getLangPrefix() + "/event";
+ var matches = window.location.pathname.match(/^(\/(?:event|[^/]+\/event))\/?/);
+ if (matches && matches[1]) {
+ return matches[1];
+ }
+ return "/event";
},
/**