Files
Yumi/src/providers/Locale.ts
T

30 lines
725 B
TypeScript
Raw Normal View History

2022-06-06 20:11:54 +07:00
import { I18n } from 'i18n';
import * as path from 'path';
import Logger from '../libs/Logger';
class Locale {
public localePath: string;
constructor() {
this.localePath = path.join(process.cwd(), 'locales/');
}
public init(): void {
2022-06-07 13:00:01 +07:00
Logger.log('info', 'Loaded locales: ' + this.getLocaleProvider('en').getLocales().join(', '));
2022-06-06 20:11:54 +07:00
}
public getLocaleProvider(locale: string) {
const i18n = new I18n();
i18n.configure({
2022-06-06 20:41:03 +07:00
directory: this.localePath,
2022-06-07 13:00:01 +07:00
objectNotation: true,
defaultLocale: 'en',
retryInDefaultLocale: true
});
2022-06-06 20:11:54 +07:00
i18n.setLocale(locale);
return i18n;
}
}
2022-06-07 13:00:01 +07:00
export default new Locale();