fix: Add preference to choose browser lang for widget settings page (#5726)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
committed by
GitHub
parent
bcde84b5b5
commit
abe439594e
@@ -18,6 +18,11 @@ const runSDK = ({ baseUrl, websiteToken }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const chatwootSettings = window.chatwootSettings || {};
|
const chatwootSettings = window.chatwootSettings || {};
|
||||||
|
let locale = chatwootSettings.locale || 'en';
|
||||||
|
if (chatwootSettings.useBrowserLanguage) {
|
||||||
|
locale = window.navigator.language.replace('-', '_');
|
||||||
|
}
|
||||||
|
|
||||||
window.$chatwoot = {
|
window.$chatwoot = {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
hasLoaded: false,
|
hasLoaded: false,
|
||||||
@@ -25,7 +30,8 @@ const runSDK = ({ baseUrl, websiteToken }) => {
|
|||||||
isOpen: false,
|
isOpen: false,
|
||||||
position: chatwootSettings.position === 'left' ? 'left' : 'right',
|
position: chatwootSettings.position === 'left' ? 'left' : 'right',
|
||||||
websiteToken,
|
websiteToken,
|
||||||
locale: chatwootSettings.locale,
|
locale,
|
||||||
|
useBrowserLanguage: chatwootSettings.useBrowserLanguage || false,
|
||||||
type: getBubbleView(chatwootSettings.type),
|
type: getBubbleView(chatwootSettings.type),
|
||||||
launcherTitle: chatwootSettings.launcherTitle || '',
|
launcherTitle: chatwootSettings.launcherTitle || '',
|
||||||
showPopoutButton: chatwootSettings.showPopoutButton || false,
|
showPopoutButton: chatwootSettings.showPopoutButton || false,
|
||||||
@@ -58,7 +64,7 @@ const runSDK = ({ baseUrl, websiteToken }) => {
|
|||||||
IFrameHelper.events.popoutChatWindow({
|
IFrameHelper.events.popoutChatWindow({
|
||||||
baseUrl: window.$chatwoot.baseUrl,
|
baseUrl: window.$chatwoot.baseUrl,
|
||||||
websiteToken: window.$chatwoot.websiteToken,
|
websiteToken: window.$chatwoot.websiteToken,
|
||||||
locale: window.$chatwoot.locale,
|
locale,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -134,10 +134,20 @@ export default {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setLocale(locale) {
|
setLocale(localeWithVariation) {
|
||||||
const { enabledLanguages } = window.chatwootWebChannel;
|
const { enabledLanguages } = window.chatwootWebChannel;
|
||||||
if (enabledLanguages.some(lang => lang.iso_639_1_code === locale)) {
|
const localeWithoutVariation = localeWithVariation.split('_')[0];
|
||||||
this.$root.$i18n.locale = locale;
|
const hasLocaleWithoutVariation = enabledLanguages.some(
|
||||||
|
lang => lang.iso_639_1_code === localeWithoutVariation
|
||||||
|
);
|
||||||
|
const hasLocaleWithVariation = enabledLanguages.some(
|
||||||
|
lang => lang.iso_639_1_code === localeWithVariation
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasLocaleWithVariation) {
|
||||||
|
this.$root.$i18n.locale = localeWithVariation;
|
||||||
|
} else if (hasLocaleWithoutVariation) {
|
||||||
|
this.$root.$i18n.locale = localeWithoutVariation;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
registerUnreadEvents() {
|
registerUnreadEvents() {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ window.chatwootSettings = {
|
|||||||
hideMessageBubble: false,
|
hideMessageBubble: false,
|
||||||
position: '<%= @widget_position %>',
|
position: '<%= @widget_position %>',
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
|
useBrowserLanguage: true,
|
||||||
type: '<%= @widget_type %>',
|
type: '<%= @widget_type %>',
|
||||||
showPopoutButton: true,
|
showPopoutButton: true,
|
||||||
widgetStyle: '<%= @widget_style %>',
|
widgetStyle: '<%= @widget_style %>',
|
||||||
|
|||||||
Reference in New Issue
Block a user