diff --git a/changes/changelog.d/670.enhancement b/changes/changelog.d/670.enhancement new file mode 100644 index 000000000..8da3f97f8 --- /dev/null +++ b/changes/changelog.d/670.enhancement @@ -0,0 +1 @@ +Use proper locale for date-related/duration strings (#670) diff --git a/front/src/App.vue b/front/src/App.vue index 2ce3ba3ed..02383e6cf 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -57,11 +57,10 @@ import _ from '@/lodash' import {mapState} from 'vuex' import { WebSocketBridge } from 'django-channels' import GlobalEvents from '@/components/utils/global-events' - import Sidebar from '@/components/Sidebar' import AppFooter from '@/components/Footer' import ServiceMessages from '@/components/ServiceMessages' - +import moment from 'moment' import locales from './locales' import PlaylistModal from '@/components/playlists/PlaylistModal' import ShortcutsModal from '@/components/ShortcutsModal' @@ -153,14 +152,7 @@ export default { } else { return } - import(`./translations/${candidate}.json`).then((response) =>{ - Vue.$translations[candidate] = response.default[candidate] - }).finally(() => { - // set current language twice, otherwise we seem to have a cache somewhere - // and rendering does not happen - self.$language.current = 'noop' - self.$language.current = candidate - }) + this.$store.commit('ui/currentLanguage', candidate) }, disconnect () { if (!this.bridge) { @@ -191,7 +183,7 @@ export default { bridge.socket.addEventListener('open', function () { console.log('Connected to WebSocket') }) - } + }, }, computed: { ...mapState({ @@ -235,8 +227,35 @@ export default { this.openWebsocket() } }, - '$language.current' (newValue) { - this.$store.commit('ui/currentLanguage', newValue) + '$store.state.ui.currentLanguage': { + immediate: true, + handler(newValue) { + let self = this + import(`./translations/${newValue}.json`).then((response) =>{ + Vue.$translations[newValue] = response.default[newValue] + }).finally(() => { + // set current language twice, otherwise we seem to have a cache somewhere + // and rendering does not happen + self.$language.current = 'noop' + self.$language.current = newValue + }) + if (newValue === 'en_US') { + return self.$store.commit('ui/momentLocale', 'en') + } + let momentLocale = newValue.replace('_', '-').toLowerCase() + import(`moment/locale/${momentLocale}.js`).then(() => { + self.$store.commit('ui/momentLocale', momentLocale) + }).catch(() => { + console.log('No momentjs locale available for', momentLocale) + let shortLocale = momentLocale.split('-')[0] + import(`moment/locale/${shortLocale}.js`).then(() => { + self.$store.commit('ui/momentLocale', shortLocale) + }).catch(() => { + console.log('No momentjs locale available for', shortLocale) + }) + }) + console.log(moment.locales()) + } } } } diff --git a/front/src/components/Footer.vue b/front/src/components/Footer.vue index f62bc548b..2767167e2 100644 --- a/front/src/components/Footer.vue +++ b/front/src/components/Footer.vue @@ -20,7 +20,7 @@
-
@@ -76,14 +76,6 @@ export default { if (confirm) { this.$store.commit("instance/instanceUrl", null) } - }, - updateLanguage(value) { - let self = this - import(`../translations/${value}.json`).then((response) =>{ - Vue.$translations[value] = response.default[value] - }).finally(() => { - self.$language.current = value - }) } }, computed: { diff --git a/front/src/components/common/HumanDate.vue b/front/src/components/common/HumanDate.vue index 9ff8e48bd..eed245ea6 100644 --- a/front/src/components/common/HumanDate.vue +++ b/front/src/components/common/HumanDate.vue @@ -1,5 +1,5 @@