From 7f106d21c4a761a51dc2ed1abc17d8832f0844b4 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Wed, 11 Sep 2019 12:30:31 +0200
Subject: [PATCH] Ensure selected locale is not reset to browser default when
 refreshing app

---
 changes/changelog.d/locale.bugfix | 1 +
 front/src/App.vue                 | 4 +++-
 front/src/store/index.js          | 2 +-
 front/src/store/ui.js             | 2 ++
 4 files changed, 7 insertions(+), 2 deletions(-)
 create mode 100644 changes/changelog.d/locale.bugfix

diff --git a/changes/changelog.d/locale.bugfix b/changes/changelog.d/locale.bugfix
new file mode 100644
index 0000000000..5feeaa4c1a
--- /dev/null
+++ b/changes/changelog.d/locale.bugfix
@@ -0,0 +1 @@
+Ensure selected locale is not reset to browser default when refreshing app
diff --git a/front/src/App.vue b/front/src/App.vue
index ad64cb0b54..0895962994 100644
--- a/front/src/App.vue
+++ b/front/src/App.vue
@@ -71,7 +71,9 @@ export default {
   created () {
     this.openWebsocket()
     let self = this
-    this.autodetectLanguage()
+    if (!this.$store.state.ui.selectedLanguage) {
+      this.autodetectLanguage()
+    }
     setInterval(() => {
       // used to redraw ago dates every minute
       self.$store.commit('ui/computeLastDate')
diff --git a/front/src/store/index.js b/front/src/store/index.js
index 126368e23e..d94a0bcc77 100644
--- a/front/src/store/index.js
+++ b/front/src/store/index.js
@@ -40,7 +40,7 @@ export default new Vuex.Store({
     }),
     createPersistedState({
       key: 'ui',
-      paths: ['ui.currentLanguage', 'ui.momentLocale', 'ui.theme']
+      paths: ['ui.currentLanguage', 'ui.selectedLanguage', 'ui.momentLocale', 'ui.theme']
     }),
     createPersistedState({
       key: 'radios',
diff --git a/front/src/store/ui.js b/front/src/store/ui.js
index b708634657..fccbf93486 100644
--- a/front/src/store/ui.js
+++ b/front/src/store/ui.js
@@ -5,6 +5,7 @@ export default {
   namespaced: true,
   state: {
     currentLanguage: 'en_US',
+    selectedLanguage: false,
     momentLocale: 'en',
     lastDate: new Date(),
     maxMessages: 100,
@@ -33,6 +34,7 @@ export default {
     },
     currentLanguage: (state, value) => {
       state.currentLanguage = value
+      state.selectedLanguage = true
     },
     momentLocale: (state, value) => {
       state.momentLocale = value
-- 
GitLab