Skip to content

Commit

Permalink
feat(stark-ui): split translations from UI components in the differen…
Browse files Browse the repository at this point in the history
…t modules they belong to. Split common Core and common UI translations.

ISSUES CLOSED: #511
  • Loading branch information
christophercr committed Nov 9, 2018
1 parent 51dc8c3 commit bd6fbb6
Show file tree
Hide file tree
Showing 37 changed files with 674 additions and 297 deletions.
3 changes: 2 additions & 1 deletion packages/stark-core/src/common/translations.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./translations/common-translations";
export * from "./translations/locale.intf";
export * from "./translations/translations";
export * from "./translations/merge-translations";
11 changes: 11 additions & 0 deletions packages/stark-core/src/common/translations/common-translations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { translationsEn } from "./translations/en";
import { translationsFr } from "./translations/fr";
import { translationsNl } from "./translations/nl";

/**
* Common translations for features available in Stark-Core package
*/
export const commonCoreTranslations: object[] = [];
commonCoreTranslations["en"] = translationsEn;
commonCoreTranslations["fr"] = translationsFr;
commonCoreTranslations["nl"] = translationsNl;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, TestBed } from "@angular/core/testing";
import { TranslateModule, TranslateService } from "@ngx-translate/core";
import { mergeTranslations } from "./translations";
import { mergeTranslations } from "./merge-translations";
import { StarkLocale } from "./locale.intf";

/* tslint:disable:no-duplicate-string */
Expand Down Expand Up @@ -62,12 +62,12 @@ describe("Translations: mergeTranslations", () => {
const text1: string = translateService.instant("STARK.TEST.TEXT1");
const text2: string = translateService.instant("STARK.TEST.TEXT2");
const text3: string = translateService.instant("STARK.TEST.TEXT3");
const ascending: string = translateService.instant("STARK.SORTING.ASC");
const languageFr: string = translateService.instant("STARK.LANGUAGES.FR");

expect(text1).toBe(moduleTranslationsEn.STARK.TEST.TEXT1);
expect(text2).toBe(appTranslationsEn.STARK.TEST.TEXT2); // the app has the upper hand
expect(text3).toBe(appTranslationsEn.STARK.TEST.TEXT3);
expect(ascending).toBe("Ascending"); // Common translations
expect(languageFr).toBe("Français"); // Common translations
});

it("should return the merged translations from common, module and app when lazy loading modules", () => {
Expand All @@ -82,12 +82,12 @@ describe("Translations: mergeTranslations", () => {
const text1: string = translateService.instant("STARK.TEST.TEXT1");
const text2: string = translateService.instant("STARK.TEST.TEXT2");
const text3: string = translateService.instant("STARK.TEST.TEXT3");
const ascending: string = translateService.instant("STARK.SORTING.ASC");
const languageFr: string = translateService.instant("STARK.LANGUAGES.FR");

expect(text1).toBe(moduleTranslationsEn.STARK.TEST.TEXT1);
expect(text2).toBe(appTranslationsEn.STARK.TEST.TEXT2); // the app has the upper hand
expect(text3).toBe(appTranslationsEn.STARK.TEST.TEXT3);
expect(ascending).toBe("Ascending"); // Common translations
expect(languageFr).toBe("Français"); // Common translations
});

it("should return the merged translations, where the app has an extra language", () => {
Expand All @@ -101,13 +101,12 @@ describe("Translations: mergeTranslations", () => {
const text1: string = translateService.instant("STARK.TEST.TEXT1");
const text2: string = translateService.instant("STARK.TEST.TEXT2");
const text3: string = translateService.instant("STARK.TEST.TEXT3");
const ascending: string = translateService.instant("STARK.SORTING.ASC");
const languageFr: string = translateService.instant("STARK.LANGUAGES.FR");

expect(text1).toBe("Text1 aus der app");
expect(text2).toBe("Text2 aus der app");
expect(text3).toBe("Text3 aus der app");
expect(ascending).toBe("Ascending"); // missing in the app => translated from the default language 'en'
expect(languageFr).toBe("Français"); // missing in the app => translated from the default language 'en'
});
});
});
/* tslint:enable */
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { TranslateService } from "@ngx-translate/core";
import { StarkLocale } from "./locale.intf";
import { commonCoreTranslations } from "./common-translations";

/**
* @ignore
*/
const _cloneDeep: Function = require("lodash/cloneDeep");

import { StarkLocale } from "./locale.intf";
import { translationsEn } from "./translations/en";
import { translationsFr } from "./translations/fr";
import { translationsNl } from "./translations/nl";

/**
* This function can be used by Stark modules to merge their translations into existing translations,
* without losing any existing translations.
Expand All @@ -31,26 +29,18 @@ import { translationsNl } from "./translations/nl";
* 3. The 'module' translations are added in the translateService, replacing any existing translations
* 4. The 'stored' translations are added in the translateService, replacing any existing translations
*
* @param translateService
* Description: a reference to the translateService instance
* @param args
* Description: a list of StarkLocales that contain the translations for a specific language
* @param translateService - A reference to the translateService instance
* @param localesToMerge - A list of StarkLocales that contain the translations for a specific language
*
* @example:
* mergeTranslations(this.translateService, english, french, dutch);
*/
export function mergeTranslations(translateService: TranslateService, ...args: StarkLocale[]): void {
const locales: StarkLocale[] = [...args];
const translations: object = _cloneDeep(translateService.translations);

const commonTranslations: any[] = [];
commonTranslations["en"] = translationsEn;
commonTranslations["fr"] = translationsFr;
commonTranslations["nl"] = translationsNl;
export function mergeTranslations(translateService: TranslateService, ...localesToMerge: StarkLocale[]): void {
const currentTranslations: object = _cloneDeep(translateService.translations);

locales.forEach((starkLocale: StarkLocale) => {
translateService.setTranslation(starkLocale.languageCode, commonTranslations[starkLocale.languageCode], false);
translateService.setTranslation(starkLocale.languageCode, starkLocale.translations, true);
translateService.setTranslation(starkLocale.languageCode, translations[starkLocale.languageCode], true);
});
for (const locale of localesToMerge) {
translateService.setTranslation(locale.languageCode, commonCoreTranslations[locale.languageCode], false);
translateService.setTranslation(locale.languageCode, locale.translations, true);
translateService.setTranslation(locale.languageCode, currentTranslations[locale.languageCode], true);
}
}
81 changes: 0 additions & 81 deletions packages/stark-core/src/common/translations/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,11 @@
*/
export const translationsEn: object = {
STARK: {
APP_LOGOUT: {
TITLE: "Log out"
},
APP_FOOTER: {
COPYRIGHT: "National Bank of Belgium. All rights reserved",
COPYRIGHT_YEAR: "2016",
HELP: "Help",
LEGAL_INFO: "Legal information"
},
DATE_RANGE_PICKER: {
FROM: "From",
TO: "To"
},
ICONS: {
ADD_ITEM: "Add",
APP_DATA: "App data",
EDIT_ITEM: "Edit",
DELETE_ITEM: "Delete",
APPROVE_ITEM: "Approve",
REJECT_ITEM: "Reject",
RELOAD_PAGE: "Reload page",
OPEN_SELECTION: "Open selection",
SAVE_ITEM: "Save",
CLOSE_ITEM: "Close",
RESET: "Reset",
SEARCH: "Search",
NEW_ITEM: "New",
SAVE_AND_NEXT: "Save And Next"
},
LANGUAGES: {
EN: "English",
FR: "Français",
NL: "Nederlands",
DE: "Deutsch"
},
LOGIN: {
TITLE: "Login",
NO_PROFILE: "No profile available"
},
MULTI_COLUMN_SORTING: {
TITLE: "Multi-Column Sorting",
ADD_SORTING_LEVEL: "Add sorting level",
REMOVE_SORTING_LEVEL: "Remove sorting level",
SORT_BY: "Sort by",
THEN_BY: "Then by",
CANCEL: "Cancel",
SAVE: "Save"
},
PRELOADING: {
FETCHING_USER_PROFILE: "Initializing...",
FETCHING_USER_PROFILE_FAILURE: "Initialization failed: could not fetch user profile.",
CONTACT_IT_SUPPORT: "Please contact your IT support department.",
CORRELATION_ID: "Correlation ID",
RELOAD: "Reload"
},
SESSION_EXPIRED: {
TITLE: "Session expired",
MESSAGE: "",
RELOAD: "Reload"
},
SESSION_LOGOUT: {
TITLE: "Logged out",
LOGIN: "Log in again"
},
SORTING: {
ASC: "Ascending",
DESC: "Descending"
},
TABLE: {
NB_SELECTED_ROWS: "Selected",
TOGGLE_SELECTION: "Toggle selection",
SELECT_ALL: "Select all",
DESELECT_ALL: "Deselect all",
SELECT_DESELECT_ALL: "SELECT all/Deselect all",
MORE: "More",
INDEX: "Index",
ACTIONS: "Actions",
FILTER: "Filter (max 20 chars)",
CLEAR_FILTER: "Clear filter",
EXPAND_ALL: "Expand all lines",
COLLAPSE_ALL: "Collapse all lines",
PRISTINE_MESSAGE: "No data loaded yet.",
EMPTY_MESSAGE: "No elements found. Have a nice day!",
ITEMS_FOUND: "item(s)",
TOGGLE_COLUMNS: "Column filters",
MULTI_COLUMN_SORTING: "Multi-Column Sorting"
}
}
};
81 changes: 0 additions & 81 deletions packages/stark-core/src/common/translations/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,11 @@
*/
export const translationsFr: object = {
STARK: {
APP_LOGOUT: {
TITLE: "Déconnecter"
},
APP_FOOTER: {
COPYRIGHT: "Banque Nationale de Belgique. Tous droits réservés",
COPYRIGHT_YEAR: "2016",
HELP: "Aide",
LEGAL_INFO: "Informations légales"
},
DATE_RANGE_PICKER: {
FROM: "De",
TO: "A"
},
ICONS: {
ADD_ITEM: "Ajouter",
APP_DATA: "App data",
EDIT_ITEM: "Modifier",
DELETE_ITEM: "Supprimer",
APPROVE_ITEM: "Approuver",
REJECT_ITEM: "Rejeter",
RELOAD_PAGE: "Recharger la page",
OPEN_SELECTION: "Ouvrir la sélection",
SAVE_ITEM: "Sauver",
CLOSE_ITEM: "Fermer",
RESET: "Réinitialiser",
SEARCH: "Chercher",
NEW_ITEM: "Nouveau",
SAVE_AND_NEXT: "Sauver et Suivant"
},
LANGUAGES: {
EN: "English",
FR: "Français",
NL: "Nederlands",
DE: "Deutsch"
},
LOGIN: {
TITLE: "Connexion",
NO_PROFILE: "Aucun profil utilisateur disponible"
},
MULTI_COLUMN_SORTING: {
TITLE: "Tri multi-colonnes",
ADD_SORTING_LEVEL: "Ajouter le niveau de tri",
REMOVE_SORTING_LEVEL: "Supprimer le niveau de tri",
SORT_BY: "Trier par",
THEN_BY: "Puis par",
CANCEL: "Annuler",
SAVE: "Enregistrer"
},
PRELOADING: {
FETCHING_USER_PROFILE: "Initialisation...",
FETCHING_USER_PROFILE_FAILURE: "Échec de l'initialisation: impossible de récupérer le profil de l'utilisateur.",
CONTACT_IT_SUPPORT: "Veuillez contacter votre service d'assistance informatique.",
CORRELATION_ID: "ID de corrélation",
RELOAD: "Recharger"
},
SESSION_EXPIRED: {
TITLE: "La session a expiré",
MESSAGE: "",
RELOAD: "Recharger"
},
SESSION_LOGOUT: {
TITLE: "Déconnecté",
LOGIN: "Connexion"
},
SORTING: {
ASC: "Ascendant",
DESC: "Descendant"
},
TABLE: {
NB_SELECTED_ROWS: "Sélectionné",
TOGGLE_SELECTION: "Inverser la sélection",
SELECT_ALL: "Tout sélectionner",
DESELECT_ALL: "Tout désélectionner",
SELECT_DESELECT_ALL: "Tout sélectionner/Tout désélectionner",
MORE: "Plus",
INDEX: "Index",
ACTIONS: "Actions",
FILTER: "Filtre (max 20 cars)",
CLEAR_FILTER: "Vider le filtre",
EXPAND_ALL: "Afficher toutes les lignes",
COLLAPSE_ALL: "Cacher toutes les lignes",
PRISTINE_MESSAGE: "Il n'y a pas encore de données chargées.",
EMPTY_MESSAGE: "Aucun élément trouvé. Passez une bonne journée !",
ITEMS_FOUND: "élément(s)",
TOGGLE_COLUMNS: "Filtre colonnes",
MULTI_COLUMN_SORTING: "Tri multi-colonnes"
}
}
};
Loading

0 comments on commit bd6fbb6

Please sign in to comment.