chore: Refactors widget to use i18n locale for articles (#7958)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Nithin David Thomas
2023-09-21 18:24:03 +05:30
committed by GitHub
parent 48bf8d08e5
commit 018c468303
6 changed files with 3 additions and 29 deletions

View File

@@ -111,7 +111,6 @@ export default {
'setWidgetColor',
'setBubbleVisibility',
'setColorScheme',
'setLocale',
]),
...mapActions('conversation', ['fetchOldConversations', 'setUserLastSeen']),
...mapActions('campaign', [
@@ -153,10 +152,8 @@ export default {
if (hasLocaleWithVariation) {
this.$root.$i18n.locale = localeWithVariation;
this.$store.dispatch('appConfig/setLocale', localeWithVariation);
} else if (hasLocaleWithoutVariation) {
this.$root.$i18n.locale = localeWithoutVariation;
this.$store.dispatch('appConfig/setLocale', localeWithoutVariation);
}
},
registerUnreadEvents() {

View File

@@ -5,7 +5,6 @@ import {
SET_WIDGET_APP_CONFIG,
SET_WIDGET_COLOR,
TOGGLE_WIDGET_OPEN,
SET_WIDGET_LOCALE,
} from '../types';
const state = {
@@ -19,7 +18,6 @@ const state = {
widgetColor: '',
widgetStyle: 'standard',
darkMode: 'light',
locale: 'en',
};
export const getters = {
@@ -31,7 +29,6 @@ export const getters = {
getReferrerHost: $state => $state.referrerHost,
isWidgetStyleFlat: $state => $state.widgetStyle === 'flat',
darkMode: $state => $state.darkMode,
widgetLocale: $state => $state.locale,
};
export const actions = {
@@ -68,9 +65,6 @@ export const actions = {
setBubbleVisibility({ commit }, hideMessageBubble) {
commit(SET_BUBBLE_VISIBILITY, hideMessageBubble);
},
setLocale({ commit }, locale) {
commit(SET_WIDGET_LOCALE, locale);
},
};
export const mutations = {
@@ -97,9 +91,6 @@ export const mutations = {
[SET_COLOR_SCHEME]($state, darkMode) {
$state.darkMode = darkMode;
},
[SET_WIDGET_LOCALE]($state, locale) {
$state.locale = locale || $state.locale;
},
};
export default {

View File

@@ -31,11 +31,4 @@ describe('#actions', () => {
expect(commit.mock.calls).toEqual([['SET_COLOR_SCHEME', 'dark']]);
});
});
describe('#setLocale', () => {
it('creates actions for setting the locale properly', () => {
actions.setLocale({ commit }, 'es_ES');
expect(commit.mock.calls).toEqual([['SET_WIDGET_LOCALE', 'es_ES']]);
});
});
});

View File

@@ -32,12 +32,4 @@ describe('#mutations', () => {
expect(state.darkMode).toEqual('dark');
});
});
describe('#SET_WIDGET_LOCALE', () => {
it('sets widget locale properly', () => {
const state = { locale: 'en' };
mutations.SET_WIDGET_LOCALE(state, 'es_ES');
expect(state.locale).toEqual('es_ES');
});
});
});

View File

@@ -7,4 +7,3 @@ export const UPDATE_CONVERSATION_ATTRIBUTES = 'UPDATE_CONVERSATION_ATTRIBUTES';
export const TOGGLE_WIDGET_OPEN = 'TOGGLE_WIDGET_OPEN';
export const SET_REFERRER_HOST = 'SET_REFERRER_HOST';
export const SET_BUBBLE_VISIBILITY = 'SET_BUBBLE_VISIBILITY';
export const SET_WIDGET_LOCALE = 'SET_WIDGET_LOCALE';

View File

@@ -68,8 +68,10 @@ export default {
unreadMessageCount: 'conversation/getUnreadMessageCount',
popularArticles: 'article/popularArticles',
articleUiFlags: 'article/uiFlags',
widgetLocale: 'appConfig/widgetLocale',
}),
widgetLocale() {
return this.$i18n.locale || 'en';
},
portal() {
return window.chatwootWebChannel.portal;
},