mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 03:56:44 -06:00
34 lines
845 B
TypeScript
34 lines
845 B
TypeScript
/**
|
|
* Languages Loader
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as yaml from 'js-yaml';
|
|
|
|
export type LangKey = 'de' | 'en' | 'fr' | 'ja' | 'pl';
|
|
export type LocaleObjectChildren = LocaleObject | string | undefined;
|
|
export type LocaleObject = {[key: string]: LocaleObjectChildren };
|
|
|
|
const loadLang = (lang: LangKey) => yaml.safeLoad(
|
|
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')) as LocaleObject;
|
|
|
|
const native = loadLang('ja');
|
|
|
|
const langs: {[key in LangKey]: LocaleObject} = {
|
|
'de': loadLang('de'),
|
|
'en': loadLang('en'),
|
|
'fr': loadLang('fr'),
|
|
'ja': native,
|
|
'pl': loadLang('pl')
|
|
};
|
|
|
|
Object.entries(langs).map(([, locale]) => {
|
|
// Extend native language (Japanese)
|
|
locale = Object.assign({}, native, locale);
|
|
});
|
|
|
|
export function isAvailableLanguage(lang: string): lang is LangKey {
|
|
return lang in langs;
|
|
}
|
|
|
|
export default langs;
|