mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-16 05:26:31 +00:00
22414744b0
Co-authored-by: qwerty287 <qwerty287@posteo.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
36 lines
1,018 B
TypeScript
36 lines
1,018 B
TypeScript
import { nextTick } from 'vue';
|
|
import { createI18n } from 'vue-i18n';
|
|
|
|
import { getUserLanguage } from '~/utils/locale';
|
|
|
|
import { useDate } from './useDate';
|
|
|
|
const { setDayjsLocale } = useDate();
|
|
const userLanguage = getUserLanguage();
|
|
const fallbackLocale = 'en';
|
|
export const i18n = createI18n({
|
|
locale: userLanguage,
|
|
legacy: false,
|
|
globalInjection: true,
|
|
fallbackLocale,
|
|
});
|
|
|
|
const loadLocaleMessages = async (locale: string) => {
|
|
const messages = (await import(`~/assets/locales/${locale}.json`)) as { default: any };
|
|
|
|
i18n.global.setLocaleMessage(locale, messages.default);
|
|
|
|
return nextTick();
|
|
};
|
|
|
|
export const setI18nLanguage = async (lang: string): Promise<void> => {
|
|
if (!i18n.global.availableLocales.includes(lang)) {
|
|
await loadLocaleMessages(lang);
|
|
}
|
|
i18n.global.locale.value = lang;
|
|
await setDayjsLocale(lang);
|
|
};
|
|
|
|
loadLocaleMessages(fallbackLocale).catch(console.error);
|
|
loadLocaleMessages(userLanguage).catch(console.error);
|
|
setDayjsLocale(userLanguage).catch(console.error);
|