Sharkey/locales/index.ts

35 lines
845 B
TypeScript
Raw Normal View History

2017-05-16 18:00:56 +03:00
/**
* Languages Loader
*/
import * as fs from 'fs';
import * as yaml from 'js-yaml';
2018-06-17 13:09:24 +03:00
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;
2017-05-16 18:00:56 +03:00
const native = loadLang('ja');
2018-06-17 13:09:24 +03:00
const langs: {[key in LangKey]: LocaleObject} = {
2018-05-17 09:41:07 +03:00
'de': loadLang('de'),
2018-04-14 23:57:30 +03:00
'en': loadLang('en'),
2018-04-15 23:59:21 +03:00
'fr': loadLang('fr'),
'ja': native,
2018-05-17 03:28:31 +03:00
'pl': loadLang('pl')
2017-12-16 21:02:30 +02:00
};
2017-05-16 18:00:56 +03:00
2017-12-16 21:02:30 +02:00
Object.entries(langs).map(([, locale]) => {
2017-05-16 18:00:56 +03:00
// Extend native language (Japanese)
locale = Object.assign({}, native, locale);
});
2018-06-17 13:09:24 +03:00
export function isAvailableLanguage(lang: string): lang is LangKey {
return lang in langs;
}
2017-05-16 18:00:56 +03:00
export default langs;