diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 6aadcda8..da80295b 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -1,5 +1,8 @@ { "hello": { "message": "hello" + }, + "world": { + "message": "world" } } diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index ba5110e0..8ab7b7ca 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -2,7 +2,7 @@ import { webFrame } from 'electron'; import { APP_INITIALIZER, - NgModule + NgModule, } from '@angular/core'; import { DesktopMessagingService } from '../../services/desktopMessaging.service'; @@ -112,8 +112,8 @@ function initFactory(i18n: I18nService): Function { provide: APP_INITIALIZER, useFactory: initFactory, deps: [I18nService], - multi: true - } + multi: true, + }, ], }) export class ServicesModule { diff --git a/src/services/i18n.service.ts b/src/services/i18n.service.ts index 1feeef64..4d0d3b86 100644 --- a/src/services/i18n.service.ts +++ b/src/services/i18n.service.ts @@ -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 { + private loadMessages(locale: string, messagesObj: any): Promise { 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(); } }