Use async/await moment loading
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
c484ce4529
commit
9763d3f756
|
@ -130,33 +130,31 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
async mounted() {
|
||||
// Load the locale
|
||||
// convert format like en_GB to en-gb for `moment.js`
|
||||
let locale = getLocale().replace('_', '-').toLowerCase()
|
||||
|
||||
// default load e.g. fr-fr
|
||||
console.debug('Importing locale', locale)
|
||||
import('moment/locale/' + locale)
|
||||
.then(e => {
|
||||
// force locale change to update
|
||||
// the component once done loading
|
||||
this.locale = locale
|
||||
})
|
||||
.catch(e => {
|
||||
try {
|
||||
// default load e.g. fr-fr
|
||||
await import('moment/locale/' + locale)
|
||||
this.locale = locale
|
||||
} catch (e) {
|
||||
try {
|
||||
// failure: fallback to fr
|
||||
locale = locale.split('-')[0]
|
||||
console.debug('Fallback to locale', locale)
|
||||
import('moment/locale/' + locale)
|
||||
.then(e => {
|
||||
this.locale = locale
|
||||
})
|
||||
.catch(e => {
|
||||
console.debug('Fallback to locale', 'en')
|
||||
// failure, fallback to english
|
||||
this.locale = 'en'
|
||||
})
|
||||
})
|
||||
await import('moment/locale/' + locale)
|
||||
} catch (e) {
|
||||
// failure, fallback to english
|
||||
console.debug('Fallback to locale', 'en')
|
||||
locale = 'en'
|
||||
}
|
||||
} finally {
|
||||
// force locale change to update
|
||||
// the component once done loading
|
||||
this.locale = locale
|
||||
console.debug('Locale used', locale)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
Loading…
Reference in New Issue