From bd4a119c0531b5066d66a514a0420cc554fbd141 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 25 Sep 2019 10:06:06 +0200 Subject: [PATCH] Automated cherry pick of #3310 (#3318) * Reset moment local on logout * Update app/selectors/i18n.js Co-Authored-By: Elias Nahum --- app/i18n/index.js | 10 ++-------- app/init/global_event_handler.js | 3 ++- app/init/global_event_handler.test.js | 5 ++++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/i18n/index.js b/app/i18n/index.js index 1fe215879..bafaf7151 100644 --- a/app/i18n/index.js +++ b/app/i18n/index.js @@ -108,12 +108,8 @@ function loadTranslation(locale) { } } -let momentLocale = DEFAULT_LOCALE; - -function setMomentLocale(locale) { - if (momentLocale !== locale) { - momentLocale = moment.locale(locale); - } +export function resetMomentLocale() { + moment.locale(DEFAULT_LOCALE); } export function getTranslations(locale) { @@ -121,8 +117,6 @@ export function getTranslations(locale) { loadTranslation(locale); } - setMomentLocale(locale.toLowerCase()); - return TRANSLATIONS[locale] || TRANSLATIONS[DEFAULT_LOCALE]; } diff --git a/app/init/global_event_handler.js b/app/init/global_event_handler.js index 964351108..9f477ec6e 100644 --- a/app/init/global_event_handler.js +++ b/app/init/global_event_handler.js @@ -18,7 +18,7 @@ import {selectDefaultChannel} from 'app/actions/views/channel'; import {showOverlay} from 'app/actions/navigation'; import {loadConfigAndLicense, setDeepLinkURL, startDataCleanup} from 'app/actions/views/root'; import {NavigationTypes, ViewTypes} from 'app/constants'; -import {getTranslations} from 'app/i18n'; +import {getTranslations, resetMomentLocale} from 'app/i18n'; import mattermostManaged from 'app/mattermost_managed'; import PushNotifications from 'app/push_notifications'; import {getCurrentLocale} from 'app/selectors/i18n'; @@ -145,6 +145,7 @@ class GlobalEventHandler { this.store.dispatch(setServerVersion('')); deleteFileCache(); removeAppCredentials(); + resetMomentLocale(); PushNotifications.clearNotifications(); diff --git a/app/init/global_event_handler.test.js b/app/init/global_event_handler.test.js index 7b22e9f5e..19fcee89a 100644 --- a/app/init/global_event_handler.test.js +++ b/app/init/global_event_handler.test.js @@ -6,6 +6,7 @@ import thunk from 'redux-thunk'; import intitialState from 'app/initial_state'; import PushNotification from 'app/push_notifications'; +import * as I18n from 'app/i18n'; import GlobalEventHandler from './global_event_handler'; @@ -35,11 +36,13 @@ GlobalEventHandler.store = store; // TODO: Add Android test as part of https://mattermost.atlassian.net/browse/MM-17110 describe('GlobalEventHandler', () => { - it('should clear notifications on logout', async () => { + it('should clear notifications and reset moment locale on logout', async () => { const clearNotifications = jest.spyOn(PushNotification, 'clearNotifications'); + const resetMomentLocale = jest.spyOn(I18n, 'resetMomentLocale'); await GlobalEventHandler.onLogout(); expect(clearNotifications).toHaveBeenCalled(); + expect(resetMomentLocale).toHaveBeenCalledWith(); }); it('should call onAppStateChange after configuration', () => {