/** * translations.ts is where we concat all translations. */ import { OpaqueToken } from '@angular/core'; import { NgModule, ModuleWithProviders } from '@angular/core'; // import translations import { SystemLocales } from './system-locales'; import { CORE_LABELS_EN } from './core-labels-en'; import { CORE_LABELS_AR } from './core-labels-ar'; import { CORE_NOTIFICATION_MESSAGES_EN } from './core-messages-en'; import { CORE_NOTIFICATION_MESSAGES_AR } from './core-messages-ar'; /** *We created an opaque token called translations. *An opaque token is an object with no application interfaces. *It's a special kind of provider lookup key for use in dependency injection. */ export const TRANSLATIONS = new OpaqueToken('translations'); // links all our translations. let dictionary = { [SystemLocales.LANG_EN]: CORE_LABELS_EN, [SystemLocales.LANG_AR]: CORE_LABELS_AR, }; $.extend(true, dictionary[SystemLocales.LANG_EN], CORE_NOTIFICATION_MESSAGES_EN) $.extend(true, dictionary[SystemLocales.LANG_AR], CORE_NOTIFICATION_MESSAGES_AR) // we use the opaque token that we defined earlier, and supply our dictionary as value. export const TRANSLATION_PROVIDERS = [ { provide: TRANSLATIONS, useValue: dictionary }, ]; // dropdown list words with keys export const SUPPORTED_LANGUAGES = [ { display: 'English', value: 'en' }, { display: 'العربية', value: 'ar' } ]; /** * @desc a class to get other translations files from all modules * and add them to the core dictionary * @export * @class CoreTranslation */ export class CoreTranslation { static addTranslationModule(translationMap: Map) { //get translations map of modules according to languages keys let moduleEnglishTranslations = translationMap.get(SystemLocales.LANG_EN); let moduleArabicTranslations = translationMap.get(SystemLocales.LANG_AR); // copy array of keys (objects) of modules to the core array $.extend(true, dictionary[SystemLocales.LANG_EN], moduleEnglishTranslations); $.extend(true, dictionary[SystemLocales.LANG_AR], moduleArabicTranslations); } }