28 lines
896 B
TypeScript
28 lines
896 B
TypeScript
import type { CharacterConfig, i18nID } from "~/types/character";
|
|
import characterConfig from '#shared/character-config.json';
|
|
import type { Localized } from "~/types/general";
|
|
|
|
const config = characterConfig as CharacterConfig;
|
|
|
|
let language: keyof Localized = 'fr_FR';
|
|
export function init()
|
|
{
|
|
language = localStorage.getItem('language') as keyof Localized ?? 'fr_FR';
|
|
}
|
|
export function setLang(lang: keyof Localized)
|
|
{
|
|
localStorage.setItem('language', lang);
|
|
language = lang;
|
|
}
|
|
export function getText(id?: i18nID): string
|
|
{
|
|
if(!id) return '';
|
|
if(!config.texts.hasOwnProperty(id)) return '';
|
|
if(!config.texts[id]!.hasOwnProperty(language)) return 'Untranslated';
|
|
else return config.texts[id]![language]!;
|
|
}
|
|
export function setText(id: i18nID, text: string)
|
|
{
|
|
if(!config.texts.hasOwnProperty(id)) config.texts[id] = {};
|
|
config.texts[id]![language] = text;
|
|
} |