Merge branch '670-momentjs-translation' into 'master'
Fix #670: Use proper locale for date-related/duration strings See merge request funkwhale/funkwhale!560
This commit is contained in:
commit
e4954f8bd5
|
@ -0,0 +1 @@
|
||||||
|
Use proper locale for date-related/duration strings (#670)
|
|
@ -57,11 +57,10 @@ import _ from '@/lodash'
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
import { WebSocketBridge } from 'django-channels'
|
import { WebSocketBridge } from 'django-channels'
|
||||||
import GlobalEvents from '@/components/utils/global-events'
|
import GlobalEvents from '@/components/utils/global-events'
|
||||||
|
|
||||||
import Sidebar from '@/components/Sidebar'
|
import Sidebar from '@/components/Sidebar'
|
||||||
import AppFooter from '@/components/Footer'
|
import AppFooter from '@/components/Footer'
|
||||||
import ServiceMessages from '@/components/ServiceMessages'
|
import ServiceMessages from '@/components/ServiceMessages'
|
||||||
|
import moment from 'moment'
|
||||||
import locales from './locales'
|
import locales from './locales'
|
||||||
import PlaylistModal from '@/components/playlists/PlaylistModal'
|
import PlaylistModal from '@/components/playlists/PlaylistModal'
|
||||||
import ShortcutsModal from '@/components/ShortcutsModal'
|
import ShortcutsModal from '@/components/ShortcutsModal'
|
||||||
|
@ -153,14 +152,7 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
import(`./translations/${candidate}.json`).then((response) =>{
|
this.$store.commit('ui/currentLanguage', candidate)
|
||||||
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
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
disconnect () {
|
disconnect () {
|
||||||
if (!this.bridge) {
|
if (!this.bridge) {
|
||||||
|
@ -191,7 +183,7 @@ export default {
|
||||||
bridge.socket.addEventListener('open', function () {
|
bridge.socket.addEventListener('open', function () {
|
||||||
console.log('Connected to WebSocket')
|
console.log('Connected to WebSocket')
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
|
@ -235,8 +227,35 @@ export default {
|
||||||
this.openWebsocket()
|
this.openWebsocket()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'$language.current' (newValue) {
|
'$store.state.ui.currentLanguage': {
|
||||||
this.$store.commit('ui/currentLanguage', newValue)
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<div class="ui form">
|
<div class="ui form">
|
||||||
<div class="ui field">
|
<div class="ui field">
|
||||||
<label><translate>Change language</translate></label>
|
<label><translate>Change language</translate></label>
|
||||||
<select class="ui dropdown" :value="$language.current" @change="updateLanguage($event.target.value)">
|
<select class="ui dropdown" :value="$language.current" @change="$store.commit('ui/currentLanguage', $event.target.value)">
|
||||||
<option v-for="(language, key) in $language.available" :key="key" :value="key">{{ language }}</option>
|
<option v-for="(language, key) in $language.available" :key="key" :value="key">{{ language }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -76,14 +76,6 @@ export default {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
this.$store.commit("instance/instanceUrl", null)
|
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: {
|
computed: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<time :datetime="date" :title="date | moment">{{ realDate | ago }}</time>
|
<time :datetime="date" :title="date | moment">{{ realDate | ago($store.state.ui.momentLocale) }}</time>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
|
|
|
@ -13,8 +13,10 @@ export function truncate (str, max, ellipsis) {
|
||||||
|
|
||||||
Vue.filter('truncate', truncate)
|
Vue.filter('truncate', truncate)
|
||||||
|
|
||||||
export function ago (date) {
|
export function ago (date, locale) {
|
||||||
|
locale = locale || 'en'
|
||||||
const m = moment(date)
|
const m = moment(date)
|
||||||
|
m.locale(locale)
|
||||||
return m.fromNow()
|
return m.fromNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default new Vuex.Store({
|
||||||
}),
|
}),
|
||||||
createPersistedState({
|
createPersistedState({
|
||||||
key: 'ui',
|
key: 'ui',
|
||||||
paths: ['ui.currentLanguage']
|
paths: ['ui.currentLanguage', 'ui.momentLocale']
|
||||||
}),
|
}),
|
||||||
createPersistedState({
|
createPersistedState({
|
||||||
key: 'radios',
|
key: 'radios',
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import moment from 'moment'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
currentLanguage: 'en_US',
|
currentLanguage: 'en_US',
|
||||||
|
momentLocale: 'en',
|
||||||
lastDate: new Date(),
|
lastDate: new Date(),
|
||||||
maxMessages: 100,
|
maxMessages: 100,
|
||||||
messageDisplayDuration: 10000,
|
messageDisplayDuration: 10000,
|
||||||
|
@ -26,6 +28,10 @@ export default {
|
||||||
currentLanguage: (state, value) => {
|
currentLanguage: (state, value) => {
|
||||||
state.currentLanguage = value
|
state.currentLanguage = value
|
||||||
},
|
},
|
||||||
|
momentLocale: (state, value) => {
|
||||||
|
state.momentLocale = value
|
||||||
|
moment.locale(value)
|
||||||
|
},
|
||||||
computeLastDate: (state) => {
|
computeLastDate: (state) => {
|
||||||
state.lastDate = new Date()
|
state.lastDate = new Date()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue