Skip to content

Commit

Permalink
editor: fix addon right and left translation
Browse files Browse the repository at this point in the history
* Closes rero/rero-ils#3547.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Jan 10, 2024
1 parent 4c670b6 commit d656faf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
18 changes: 17 additions & 1 deletion projects/ng-core-tester/src/app/record/editor/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"remoteTypeaheadWithoutFilters",
"remoteTypeaheadWithFilters",
"input_with_default_value",
"name_with_definition"
"name_with_definition",
"field_with_addon_left_right"
],
"required": [
"required"
Expand Down Expand Up @@ -1012,6 +1013,21 @@
"$ref": "#/definitions/name_definition"
}
}
},
"field_with_addon_left_right": {
"title": "Field with addon left and right",
"type": "integer",
"minimum": 0,
"form": {
"templateOptions": {
"addonRight": {
"text": "day(s)"
},
"addonLeft": {
"text": "from"
}
}
}
}
},
"definitions": {
Expand Down
4 changes: 3 additions & 1 deletion projects/ng-core-tester/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"location": "Standort",
"created year": "Erstellungsjahr",
"library": "Bibliothek",
"German": "Deutsch"
"German": "Deutsch",
"from": "Von",
"day(s)": "Tag(e)"
}
4 changes: 3 additions & 1 deletion projects/ng-core-tester/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"location": "Localisation",
"created year": "Année de création",
"library": "Bibliothèque",
"German": "Allemand"
"German": "Allemand",
"from": "De",
"day(s)": "jour(s)"
}
4 changes: 3 additions & 1 deletion projects/ng-core-tester/src/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"location": "Localizzazione",
"created year": "Anno di creazione",
"library": "Biblioteca",
"German": "Tedesco"
"German": "Tedesco",
"from": "Da",
"day(s)": "giorni"
}
17 changes: 14 additions & 3 deletions projects/rero/ng-core/src/lib/record/editor/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO angular core
* Copyright (C) 2020-2023 RERO
* Copyright (C) 2020-2024 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -16,7 +16,7 @@
*/
import { UntypedFormControl } from '@angular/forms';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { FormlyFieldConfig, FormlyTemplateOptions } from '@ngx-formly/core';
import { TranslateService } from '@ngx-translate/core';
import { cloneDeep } from 'lodash-es';
import moment from 'moment';
Expand Down Expand Up @@ -454,7 +454,7 @@ export class TranslateExtension {
}
// Options
if (to.options) {
// Process only if the array options is observable or contains a dictionnary with label/value
// Process only if the array options is observable or contains a dictionary with label/value
if (isObservable(to.options) || to.options.some((o: any) => 'label' in o && 'value' in o)) {
to.options = !isObservable(to.options) ? of(to.options) : to.options;
to.options = to.options.pipe(
Expand All @@ -480,6 +480,17 @@ export class TranslateExtension {
);
}
}
// AddonRight or AddonLeft
if (to.addonRight?.text) {
// Store original text to the new key
to.addonRight.originalText = cloneDeep(to.addonRight.text);
this._translate.onLangChange.subscribe(() => to.addonRight.text = this._translate.instant(to.addonRight.originalText));
}
if (to.addonLeft?.text) {
// Store original text to the new key
to.addonLeft.originalText = cloneDeep(to.addonLeft.text);
this._translate.onLangChange.subscribe(() => to.addonLeft.text = this._translate.instant(to.addonLeft.originalText));
}
}
}

Expand Down

0 comments on commit d656faf

Please sign in to comment.