Commit 84677107 authored by Florent Poittevin's avatar Florent Poittevin
Browse files

feat(admin language): [DLCM-1975] translate list language depending of the language of the app

parent 35a6578a
......@@ -25,7 +25,8 @@
"pdfjs-dist",
"iso3166-2-db",
"lodash",
"docx-preview"
"docx-preview",
"@cospired/i18n-iso-languages"
],
"outputPath": "dist/DLCM-Frontend",
"index": "src/index.html",
......
......@@ -41,7 +41,7 @@
"serve:prod": "cd dist/DLCM-Frontend && ws --spa index.html --rewrite \"/api/rss -> https://www.unige.ch/feed/rss\" -p 4200",
"simulate-prod-local": "rm -fr dist && cd ../Solidify-Frontend/ && npm run build && cp -fr dist/solidify-frontend ../AoU-Portal/node_modules && cd ../DLCM-Portal/ && npm run build:sourcemaps-prod-local && npm run serve:prod",
"refresh-ngsw-config": "ngsw-config dist/DLCM-Frontend ngsw-config.json",
"build-solidify": "rm -rf ./node_modules/folidify-frontend && cd ../solidify-frontend && npm run build && cp -fr dist/solidify-frontend ../dlcm-portal/node_modules"
"build-solidify": "rm -rf ./node_modules/Solidify-Frontend && cd ../Solidify-Frontend && npm run build && cp -fr dist/solidify-frontend ../DLCM-Portal/node_modules"
},
"dependencies": {
"@angular/animations": "12.2.7",
......@@ -56,7 +56,7 @@
"@angular/platform-browser-dynamic": "12.2.7",
"@angular/router": "12.2.7",
"@angular/service-worker": "12.2.7",
"@cospired/i18n-iso-languages": "^3.1.1",
"@cospired/i18n-iso-languages": "3.1.1",
"@fortawesome/angular-fontawesome": "0.9.0",
"@fortawesome/fontawesome-svg-core": "1.2.36",
"@fortawesome/free-solid-svg-icons": "5.15.4",
......
......@@ -10,7 +10,7 @@
[required]="formValidationHelper.hasRequiredField(fd)"
(blur)="checkAvailable(formDefinition.resId, fd)"
>
<mat-option *ngFor="let language of languagesList"
<mat-option *ngFor="let language of listLanguages"
[value]="language.iso"
>
{{language.name}}
......
......@@ -10,8 +10,11 @@ import {
FormBuilder,
Validators,
} from "@angular/forms";
import {AppState} from "@app/stores/app.state";
import {Language} from "@models";
import {Store} from "@ngxs/store";
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
import {AdminLanguage} from "@shared/models/admin-language.model";
import {BaseFormDefinition} from "@shared/models/base-form-definition.model";
import {RegionUtil} from "@shared/utils/region.util";
import {
......@@ -20,10 +23,10 @@ import {
} from "rxjs/operators";
import {
AbstractFormPresentational,
MemoizedUtil,
PropertyName,
SolidifyValidator,
} from "solidify-frontend";
import {AdminLanguage} from "@shared/models/admin-language.model";
@Component({
selector: "dlcm-admin-research-domain-form",
......@@ -37,12 +40,13 @@ export class AdminLanguageFormPresentational extends AbstractFormPresentational<
}
formDefinition: FormComponentFormDefinition = new FormComponentFormDefinition();
languagesList: AdminLanguage[] = RegionUtil.getLanguagesWithIsoCode();
listLanguages: AdminLanguage[] = RegionUtil.getLanguagesWithIsoCode(MemoizedUtil.selectSnapshot(this._storeNgxs, AppState, state => state.appLanguage));
constructor(protected readonly _changeDetectorRef: ChangeDetectorRef,
protected readonly _elementRef: ElementRef,
protected readonly _injector: Injector,
private readonly _fb: FormBuilder) {
private readonly _fb: FormBuilder,
private readonly _storeNgxs: Store) {
super(_changeDetectorRef, _elementRef, _injector);
}
......
import {
getNames,
LocalizedLanguageNames,
registerLocale,
toAlpha3T,
} from "@cospired/i18n-iso-languages";
import {Enums} from "@enums";
import {AdminLanguage} from "@shared/models/admin-language.model";
import {getNames, LocalizedLanguageNames, registerLocale, toAlpha3T} from "@cospired/i18n-iso-languages";
declare const require: any;
export class RegionUtil {
static getLanguagesWithIsoCode(): AdminLanguage[] {
registerLocale(require("@cospired/i18n-iso-languages/langs/en.json"));
const languagesList : LocalizedLanguageNames = getNames("en");
return Object.entries(languagesList).map(([k, v]) => ({ iso: k.toUpperCase(), name: v, iso3: toAlpha3T(k).toUpperCase() }));
static getLanguagesWithIsoCode(currentLanguage: Enums.Language.LanguageEnum): AdminLanguage[] {
registerLocale(require("@cospired/i18n-iso-languages/langs/" + currentLanguage + ".json"));
const listLanguages: LocalizedLanguageNames = getNames(currentLanguage);
return Object.entries(listLanguages).map(([k, v]) => ({iso: k.toUpperCase(), name: v, iso3: toAlpha3T(k).toUpperCase()}));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment