1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-05 01:53:55 +00:00

load locale files by require

This commit is contained in:
Kyle Spearrin
2018-01-24 15:22:13 -05:00
parent 2ab23c2c9e
commit e42bf66b2f
3 changed files with 13 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
import * as path from 'path';
// First locale is the default (English)
const SupportedLocales = [
'en', 'es',
@@ -49,14 +51,16 @@ export class I18nService {
return '';
}
private async loadMessages(locale: string, messagesObj: any): Promise<any> {
private loadMessages(locale: string, messagesObj: any): Promise<any> {
const formattedLocale = locale.replace('-', '_');
const file = await fetch(this.localesDirectory + '/' + formattedLocale + '/messages.json');
const locales = await file.json();
const filePath = path.join(__dirname, this.localesDirectory + '/' + formattedLocale + '/messages.json');
const locales = (window as any).require(filePath);
for (const prop in locales) {
if (locales.hasOwnProperty(prop)) {
messagesObj[prop] = locales[prop].message;
}
}
return Promise.resolve();
}
}