mirror of
https://codeberg.org/Hyperpipe/Hyperpipe
synced 2025-06-28 05:08:00 +02:00
Changes:
- Closes #9 - Removed dependency on vue-i18n - Localization Changes
This commit is contained in:
parent
44db54737b
commit
fcc3d455c6
18 changed files with 143 additions and 270 deletions
|
@ -1,6 +1,19 @@
|
|||
import { reactive } from 'vue';
|
||||
import { reactive, ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import en from '@/locales/en.json';
|
||||
|
||||
export const SUPPORTED_LOCALES = [
|
||||
{
|
||||
code: 'en',
|
||||
name: 'English',
|
||||
},
|
||||
{
|
||||
code: 'fr',
|
||||
name: 'French',
|
||||
},
|
||||
];
|
||||
|
||||
export const useNav = defineStore('nav', () => {
|
||||
const state = reactive({
|
||||
search: '',
|
||||
|
@ -9,3 +22,31 @@ export const useNav = defineStore('nav', () => {
|
|||
|
||||
return { state };
|
||||
});
|
||||
|
||||
export const useI18n = defineStore('i18n', () => {
|
||||
const locale = ref('en'),
|
||||
map = ref({
|
||||
en: en,
|
||||
});
|
||||
|
||||
function t(path) {
|
||||
const msgs = map.value[locale.value],
|
||||
fallback = map.value['en'],
|
||||
keys = path.split('.'),
|
||||
translate = msg => keys.reduce((obj, i) => obj?.[i], msg),
|
||||
translated = translate(msgs) || translate(fallback);
|
||||
|
||||
return translated || path;
|
||||
}
|
||||
|
||||
function setupLocale(code) {
|
||||
import(`@/locales/${code}.json`)
|
||||
.then(mod => mod.default)
|
||||
.then(mod => {
|
||||
map.value[code] = mod;
|
||||
locale.value = code;
|
||||
});
|
||||
}
|
||||
|
||||
return { locale, map, t, setupLocale };
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue