@hmcts/ccd-case-ui-toolkit 7.4.15-exui-5388 → 7.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3689,7 +3689,6 @@ class CaseField {
3689
3689
  _value;
3690
3690
  _list_items = [];
3691
3691
  isTranslatedFlag = false;
3692
- _translationHandledLocally;
3693
3692
  get value() {
3694
3693
  if (this.field_type && (this.field_type.type === 'DynamicList' || this.field_type.type === 'DynamicRadioList')) {
3695
3694
  return this._value && this._value.value ? this._value.value.code : this._value;
@@ -3811,17 +3810,11 @@ class CaseField {
3811
3810
  return this.id;
3812
3811
  }
3813
3812
  }
3814
- get isTranslated() {
3815
- return this.isTranslatedFlag;
3816
- }
3817
3813
  set isTranslated(val) {
3818
3814
  this.isTranslatedFlag = val;
3819
3815
  }
3820
- get translationHandledLocally() {
3821
- return !!this._translationHandledLocally;
3822
- }
3823
- set translationHandledLocally(value) {
3824
- this._translationHandledLocally = value;
3816
+ get isTranslated() {
3817
+ return this.isTranslatedFlag;
3825
3818
  }
3826
3819
  }
3827
3820
  __decorate([
@@ -7887,8 +7880,8 @@ ___
7887
7880
  class LabelSubstitutorDirective {
7888
7881
  fieldsUtils;
7889
7882
  placeholderService;
7883
+ rpxTranslationPipe;
7890
7884
  rpxTranslationService;
7891
- cdr;
7892
7885
  caseField;
7893
7886
  contextFields = [];
7894
7887
  formGroup;
@@ -7896,12 +7889,11 @@ class LabelSubstitutorDirective {
7896
7889
  initialLabel;
7897
7890
  initialHintText;
7898
7891
  languageSubscription;
7899
- templateTranslationSubscription;
7900
- constructor(fieldsUtils, placeholderService, rpxTranslationService, cdr) {
7892
+ constructor(fieldsUtils, placeholderService, rpxTranslationPipe, rpxTranslationService) {
7901
7893
  this.fieldsUtils = fieldsUtils;
7902
7894
  this.placeholderService = placeholderService;
7895
+ this.rpxTranslationPipe = rpxTranslationPipe;
7903
7896
  this.rpxTranslationService = rpxTranslationService;
7904
- this.cdr = cdr;
7905
7897
  }
7906
7898
  ngOnInit() {
7907
7899
  this.initialLabel = this.caseField.label;
@@ -7930,12 +7922,10 @@ class LabelSubstitutorDirective {
7930
7922
  }
7931
7923
  }
7932
7924
  }
7933
- applySubstitutions() {
7934
- this.templateTranslationSubscription?.unsubscribe();
7925
+ applySubstitutions(isLanguageChange = false) {
7935
7926
  const fields = this.getReadOnlyAndFormFields();
7936
- this.caseField.translationHandledLocally = false;
7937
7927
  if (this.shouldSubstitute('label')) {
7938
- this.applyLabelSubstitution(fields);
7928
+ this.applyLabelSubstitution(fields, isLanguageChange);
7939
7929
  }
7940
7930
  if (this.shouldSubstitute('hint_text')) {
7941
7931
  this.caseField.hint_text = this.resolvePlaceholders(fields, this.caseField.hint_text);
@@ -7944,7 +7934,7 @@ class LabelSubstitutorDirective {
7944
7934
  this.caseField.value = this.resolvePlaceholders(fields, this.caseField.value);
7945
7935
  }
7946
7936
  }
7947
- applyLabelSubstitution(fields) {
7937
+ applyLabelSubstitution(fields, isLanguageChange) {
7948
7938
  const currentLabel = this.caseField.label;
7949
7939
  // `originalLabel` stores the label exactly as it came from the server, before any
7950
7940
  // placeholder values were inserted. That gives us a clean starting point when the user
@@ -7965,41 +7955,46 @@ class LabelSubstitutorDirective {
7965
7955
  }
7966
7956
  // Preserve the original template the first time we successfully interpolate it.
7967
7957
  this.caseField.originalLabel = this.caseField.originalLabel || originalLabel;
7968
- this.applyTranslatedLabelState(fields, originalLabel, substitutedLabel);
7969
- }
7970
- applyTranslatedLabelState(fields, originalLabel, substitutedLabel) {
7971
- // Interpolated content must be rendered without another translation request.
7972
- this.caseField.translationHandledLocally = true;
7973
- this.setLabelState(substitutedLabel, false);
7974
- if (this.rpxTranslationService.language !== 'cy') {
7958
+ this.applyTranslatedLabelState(fields, originalLabel, substitutedLabel, isLanguageChange);
7959
+ }
7960
+ applyTranslatedLabelState(fields, originalLabel, substitutedLabel, isLanguageChange) {
7961
+ // Some labels only translate correctly if we translate the template first and then
7962
+ // substitute the helper values into the translated sentence.
7963
+ const translatedTemplateLabel = this.resolvePlaceholders(fields, isLanguageChange ? this.translateLabelOnLanguageChange(originalLabel) : this.translateLabel(originalLabel));
7964
+ // Other labels only translate correctly if we first resolve the English phrase and let
7965
+ // the render layer translate that final resolved string.
7966
+ const translatedResolvedLabel = isLanguageChange
7967
+ ? this.translateLabelOnLanguageChange(substitutedLabel)
7968
+ : this.translateLabel(substitutedLabel);
7969
+ const languageIsWelsh = this.rpxTranslationService.language === 'cy';
7970
+ const hasResolvedWelshTranslation = languageIsWelsh
7971
+ && translatedResolvedLabel
7972
+ && translatedResolvedLabel !== substitutedLabel;
7973
+ const hasTemplateWelshTranslation = languageIsWelsh
7974
+ && translatedTemplateLabel
7975
+ && translatedTemplateLabel !== substitutedLabel;
7976
+ if (hasResolvedWelshTranslation) {
7977
+ // Keep the resolved English label and mark it as not yet translated so the field
7978
+ // template can run `rpxTranslate` on the full phrase at render time.
7979
+ this.setLabelState(substitutedLabel);
7975
7980
  return;
7976
7981
  }
7977
- this.templateTranslationSubscription = this.rpxTranslationService
7978
- .getTranslation$(originalLabel)
7979
- .subscribe((translatedTemplate) => {
7980
- if (this.rpxTranslationService.language !== 'cy' ||
7981
- !translatedTemplate ||
7982
- translatedTemplate.includes('[Translation in progress]')) {
7983
- return;
7984
- }
7985
- // Initial English emissions and English fallbacks are not Welsh results.
7986
- if (translatedTemplate.trim() === originalLabel.trim()) {
7987
- this.setLabelState(substitutedLabel, false);
7988
- this.cdr.markForCheck();
7989
- return;
7990
- }
7991
- // Re-read values at emission time so delayed translations use the latest form/context values.
7992
- const latestFields = this.getReadOnlyAndFormFields();
7993
- const resolvedLabel = this.resolvePlaceholders(latestFields, translatedTemplate);
7994
- // Keep usable existing content if the template cannot be resolved.
7995
- if (resolvedLabel && resolvedLabel.trim()) {
7996
- this.setLabelState(resolvedLabel, resolvedLabel !== substitutedLabel);
7997
- }
7998
- else {
7999
- this.setLabelState(substitutedLabel, false);
8000
- }
8001
- this.cdr.markForCheck();
8002
- });
7982
+ if (hasTemplateWelshTranslation) {
7983
+ // Use the template-translated result when translating the fully resolved label does
7984
+ // not improve the Welsh output.
7985
+ this.setLabelState(translatedTemplateLabel, true);
7986
+ return;
7987
+ }
7988
+ // English, untranslated Welsh, or labels whose translation is handled elsewhere.
7989
+ this.setLabelState(substitutedLabel);
7990
+ }
7991
+ translateLabel(label) {
7992
+ return this.rpxTranslationPipe.transform(label);
7993
+ }
7994
+ translateLabelOnLanguageChange(label) {
7995
+ return this.rpxTranslationService.language === 'en'
7996
+ ? label
7997
+ : this.translateLabel(label);
8003
7998
  }
8004
7999
  setLabelState(label, isTranslated = false) {
8005
8000
  this.caseField.label = label;
@@ -8007,7 +8002,7 @@ class LabelSubstitutorDirective {
8007
8002
  }
8008
8003
  onLanguageChange() {
8009
8004
  this.resetToInitialValues(true);
8010
- this.applySubstitutions();
8005
+ this.applySubstitutions(true);
8011
8006
  }
8012
8007
  resetToInitialValues(isLanguageChange = false) {
8013
8008
  if (isLanguageChange && this.caseField?.originalLabel) {
@@ -8022,7 +8017,6 @@ class LabelSubstitutorDirective {
8022
8017
  // Check if isTranslated is a property on caseField before setting it
8023
8018
  if (this.caseField) {
8024
8019
  this.caseField.isTranslated = false;
8025
- this.caseField.translationHandledLocally = false;
8026
8020
  }
8027
8021
  }
8028
8022
  ngOnDestroy() {
@@ -8030,9 +8024,6 @@ class LabelSubstitutorDirective {
8030
8024
  if (this.languageSubscription) {
8031
8025
  this.languageSubscription.unsubscribe();
8032
8026
  }
8033
- if (this.templateTranslationSubscription) {
8034
- this.templateTranslationSubscription.unsubscribe();
8035
- }
8036
8027
  }
8037
8028
  shouldSubstitute(element) {
8038
8029
  return this.elementsToSubstitute.find(e => e === element) !== undefined;
@@ -8059,7 +8050,7 @@ class LabelSubstitutorDirective {
8059
8050
  resolvePlaceholders(fields, stringToResolve) {
8060
8051
  return this.placeholderService.resolvePlaceholders(fields, stringToResolve);
8061
8052
  }
8062
- static ɵfac = function LabelSubstitutorDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || LabelSubstitutorDirective)(i0.ɵɵdirectiveInject(FieldsUtils), i0.ɵɵdirectiveInject(PlaceholderService), i0.ɵɵdirectiveInject(i1.RpxTranslationService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
8053
+ static ɵfac = function LabelSubstitutorDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || LabelSubstitutorDirective)(i0.ɵɵdirectiveInject(FieldsUtils), i0.ɵɵdirectiveInject(PlaceholderService), i0.ɵɵdirectiveInject(i1.RpxTranslatePipe), i0.ɵɵdirectiveInject(i1.RpxTranslationService)); };
8063
8054
  static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: LabelSubstitutorDirective, selectors: [["", "ccdLabelSubstitutor", ""]], inputs: { caseField: "caseField", contextFields: "contextFields", formGroup: "formGroup", elementsToSubstitute: "elementsToSubstitute" }, standalone: false });
8064
8055
  }
8065
8056
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LabelSubstitutorDirective, [{
@@ -8068,7 +8059,7 @@ class LabelSubstitutorDirective {
8068
8059
  selector: '[ccdLabelSubstitutor]',
8069
8060
  standalone: false
8070
8061
  }]
8071
- }], () => [{ type: FieldsUtils }, { type: PlaceholderService }, { type: i1.RpxTranslationService }, { type: i0.ChangeDetectorRef }], { caseField: [{
8062
+ }], () => [{ type: FieldsUtils }, { type: PlaceholderService }, { type: i1.RpxTranslatePipe }, { type: i1.RpxTranslationService }], { caseField: [{
8072
8063
  type: Input
8073
8064
  }], contextFields: [{
8074
8065
  type: Input
@@ -19261,16 +19252,16 @@ class LabelFieldComponent {
19261
19252
  } if (rf & 2) {
19262
19253
  i0.ɵɵproperty("hidden", ctx.caseField.hidden)("caseField", ctx.caseField)("contextFields", ctx.caseFields)("id", ctx.caseField.id);
19263
19254
  i0.ɵɵadvance(2);
19264
- i0.ɵɵproperty("ngIf", ctx.labelCanBeTranslated && !ctx.caseField.isTranslated && !ctx.caseField.translationHandledLocally);
19255
+ i0.ɵɵproperty("ngIf", ctx.labelCanBeTranslated && !ctx.caseField.isTranslated);
19265
19256
  i0.ɵɵadvance();
19266
- i0.ɵɵproperty("ngIf", ctx.labelCanBeTranslated && (ctx.caseField.isTranslated || ctx.caseField.translationHandledLocally));
19257
+ i0.ɵɵproperty("ngIf", ctx.labelCanBeTranslated && ctx.caseField.isTranslated);
19267
19258
  i0.ɵɵadvance();
19268
19259
  i0.ɵɵproperty("ngIf", !ctx.labelCanBeTranslated);
19269
19260
  } }, encapsulation: 2 });
19270
19261
  }
19271
19262
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LabelFieldComponent, [{
19272
19263
  type: Component,
19273
- args: [{ selector: 'ccd-label-field', standalone: false, template: "<dl [hidden]=\"caseField.hidden\" class=\"case-field\" ccdLabelSubstitutor [caseField]=\"caseField\" [contextFields]=\"caseFields\" [id]=\"caseField.id\">\n <dt>\n <ccd-markdown *ngIf=\"labelCanBeTranslated && !caseField.isTranslated && !caseField.translationHandledLocally\"\n [content]=\"caseField.label | rpxTranslate\">\n </ccd-markdown>\n\n <ccd-markdown *ngIf=\"labelCanBeTranslated && (caseField.isTranslated || caseField.translationHandledLocally)\"\n [content]=\"caseField.label\">\n </ccd-markdown>\n\n <ccd-markdown *ngIf=\"!labelCanBeTranslated\" [content]=\"caseField.value || caseField.label\">\n </ccd-markdown>\n </dt>\n <dd></dd>\n</dl>\n" }]
19264
+ args: [{ selector: 'ccd-label-field', standalone: false, template: "<dl [hidden]=\"caseField.hidden\" class=\"case-field\" ccdLabelSubstitutor [caseField]=\"caseField\" [contextFields]=\"caseFields\" [id]=\"caseField.id\">\n <dt>\n <ccd-markdown *ngIf=\"labelCanBeTranslated && !caseField.isTranslated\" [content]=\"caseField.label | rpxTranslate\">\n </ccd-markdown>\n\n <ccd-markdown *ngIf=\"labelCanBeTranslated && caseField.isTranslated\" [content]=\"caseField.label\">\n </ccd-markdown>\n\n <ccd-markdown *ngIf=\"!labelCanBeTranslated\" [content]=\"caseField.value || caseField.label\">\n </ccd-markdown>\n </dt>\n <dd></dd>\n</dl>\n" }]
19274
19265
  }], null, { caseField: [{
19275
19266
  type: Input
19276
19267
  }], caseFields: [{