mirror of
https://github.com/mmjee/Piped-Material.git
synced 2024-12-06 19:26:36 +01:00
Internationalization upgrades (PR 13)
commit 56e4933c639ff32ea18470ae1534fa4d06b448e3 Author: root <root@git.maharshi.ninja> Date: Tue Jan 4 11:09:22 2022 +0530 Also format dates commit 01d379537b2e41819e2093b33dfd2a026bcb7281 Author: root <root@git.maharshi.ninja> Date: Sun Jan 2 13:48:36 2022 +0530 Another Bengali translation update commit 53063d4265f85db7be14135ffaa095647f233841 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 11:41:44 2022 +0530 Standardize to BCP47 and adjust commit 1b48f79cce411f8d18cf9e5059916b1c50719cd5 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 11:17:28 2022 +0530 Localized number formatting + Bengali translations update commit 6b3e30db37338334f03d98b92d124741446fb470 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 10:41:27 2022 +0530 Fix fontloading commit 5b08962971f8edb5030bc5ba79972bbb209b3d31 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 10:38:29 2022 +0530 Even more standardization commit bc6a4dfb335647472ea091b302b627f475bed879 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 10:25:29 2022 +0530 Rename as per BCP-47 and standardize commit 106f84fa0486d19504fd244aaab41f9cd4a8a513 Author: root <root@git.maharshi.ninja> Date: Sat Jan 1 10:13:32 2022 +0530 i18n on steroids
This commit is contained in:
+37
-16
@@ -1,6 +1,8 @@
|
||||
import Vue from 'vue'
|
||||
import VueI18n from 'vue-i18n'
|
||||
import TimeAgo from 'javascript-time-ago'
|
||||
|
||||
import store from '@/store'
|
||||
import ENTranslations from '@/translations/en.json'
|
||||
|
||||
Vue.use(VueI18n)
|
||||
@@ -15,6 +17,10 @@ export const i18n = new VueI18n({
|
||||
messages
|
||||
})
|
||||
|
||||
const TIME_AGO_EXCEPTIONS = {
|
||||
'bn-Beng': 'bn'
|
||||
}
|
||||
|
||||
async function syncStylesPerLanguage (locale) {
|
||||
switch (locale) {
|
||||
// All the latin languages
|
||||
@@ -25,43 +31,43 @@ async function syncStylesPerLanguage (locale) {
|
||||
case 'lt':
|
||||
case 'ml':
|
||||
case 'tr':
|
||||
case 'bn_latn':
|
||||
case 'bn-Latn':
|
||||
// Don't need to import fonts because Latin fonts are always loaded
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('latin')
|
||||
break
|
||||
// Bengali script
|
||||
case 'bn_beng':
|
||||
// Bengali script
|
||||
case 'bn-Beng':
|
||||
await import('@fontsource/hind-siliguri/bengali.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('bengali')
|
||||
break
|
||||
// Other languages
|
||||
// NOTE: if you are a native speaker & want to see a different font, just email me or join the channel
|
||||
case 'zh_Hant':
|
||||
// Other languages
|
||||
// NOTE: if you are a native speaker & want to see a different font, just email me or join the channel
|
||||
case 'zh-Hant':
|
||||
await import('@fontsource/noto-sans-tc/chinese-traditional.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('traditional-chinese')
|
||||
break
|
||||
case 'zh_Hans':
|
||||
case 'zh-Hans':
|
||||
await import('@fontsource/noto-sans-sc/chinese-simplified.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('simplified-chinese')
|
||||
break
|
||||
case 'jp':
|
||||
case 'ja':
|
||||
await import('@fontsource/noto-sans-jp/japanese.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('japanese')
|
||||
break
|
||||
case 'kr':
|
||||
case 'ko':
|
||||
await import('@fontsource/noto-sans-kr/korean.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('korean')
|
||||
break
|
||||
case 'cyrl':
|
||||
case 'ru':
|
||||
await import('@fontsource/nunito-sans/cyrillic.css')
|
||||
document.body.classList.remove(...document.body.classList)
|
||||
document.body.classList.add('cyrillic')
|
||||
document.body.classList.add('russian')
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -71,7 +77,7 @@ export async function loadLocale (locale) {
|
||||
return
|
||||
}
|
||||
// load locale messages with dynamic import
|
||||
const messages = await import(/* webpackChunkName: "locale-[request]" */ `@/translations/${locale}.json`)
|
||||
const messages = await import(/* webpackChunkName: "translations-[request]" */ `@/translations/${locale}.json`)
|
||||
|
||||
// set locale and locale message
|
||||
i18n.setLocaleMessage(locale, messages.default)
|
||||
@@ -79,9 +85,24 @@ export async function loadLocale (locale) {
|
||||
return Vue.nextTick()
|
||||
}
|
||||
|
||||
async function loadFormatting (locale) {
|
||||
const tal = TIME_AGO_EXCEPTIONS[locale] || locale
|
||||
const data = await import(/* webpackChunkName: "timeago-[request]" */ `javascript-time-ago/locale/${tal}.json`)
|
||||
TimeAgo.addLocale(data)
|
||||
const timeAgo = new TimeAgo(locale)
|
||||
|
||||
store.commit('i18n/updateState', {
|
||||
intlLocale: locale,
|
||||
timeAgo
|
||||
})
|
||||
}
|
||||
|
||||
export async function changeLocale (lang) {
|
||||
await loadLocale(lang)
|
||||
await syncStylesPerLanguage(lang)
|
||||
await Promise.all([
|
||||
loadLocale(lang),
|
||||
syncStylesPerLanguage(lang),
|
||||
loadFormatting(lang)
|
||||
])
|
||||
i18n.locale = lang
|
||||
window.localStorage.setItem('LOCALE', lang)
|
||||
}
|
||||
@@ -92,7 +113,7 @@ function initializeLocalLocale () {
|
||||
// Default language
|
||||
lang = 'en'
|
||||
}
|
||||
changeLocale(lang).catch(e => console.error(e))
|
||||
return changeLocale(lang)
|
||||
}
|
||||
|
||||
initializeLocalLocale()
|
||||
export const i18nInitialized = initializeLocalLocale()
|
||||
|
||||
Reference in New Issue
Block a user