@hmcts/ccd-case-ui-toolkit 7.3.45-exui-4368-2916 → 7.3.45-exui-4277

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.
@@ -6624,7 +6624,6 @@ class LabelSubstitutorDirective {
6624
6624
  contextFields = [];
6625
6625
  formGroup;
6626
6626
  elementsToSubstitute = ['label', 'hint_text'];
6627
- initialLabel;
6628
6627
  initialHintText;
6629
6628
  languageSubscription;
6630
6629
  constructor(fieldsUtils, placeholderService, rpxTranslationPipe, rpxTranslationService) {
@@ -6634,10 +6633,9 @@ class LabelSubstitutorDirective {
6634
6633
  this.rpxTranslationService = rpxTranslationService;
6635
6634
  }
6636
6635
  ngOnInit() {
6637
- this.initialLabel = this.caseField.label;
6638
6636
  this.initialHintText = this.caseField.hint_text;
6637
+ this.caseField.originalLabel = this.caseField.label;
6639
6638
  this.noCacheProcessing();
6640
- this.caseField.originalLabel = this.caseField.originalLabel || this.caseField.label;
6641
6639
  this.formGroup = this.formGroup || new FormGroup({});
6642
6640
  this.languageSubscription = this.rpxTranslationService.language$.pipe(skip(1)).subscribe(() => {
6643
6641
  this.onLanguageChange();
@@ -6660,10 +6658,23 @@ class LabelSubstitutorDirective {
6660
6658
  }
6661
6659
  }
6662
6660
  }
6663
- applySubstitutions(isLanguageChange = false) {
6661
+ applySubstitutions() {
6664
6662
  const fields = this.getReadOnlyAndFormFields();
6665
6663
  if (this.shouldSubstitute('label')) {
6666
- this.applyLabelSubstitution(fields, isLanguageChange);
6664
+ const oldLabel = this.caseField.label;
6665
+ const substitutedLabel = this.resolvePlaceholders(fields, this.caseField.label);
6666
+ if (oldLabel && oldLabel !== substitutedLabel) {
6667
+ // we need to translate the uninterpolated data then substitute the values in translated string
6668
+ this.caseField.originalLabel = substitutedLabel;
6669
+ const translated = this.rpxTranslationPipe.transform(oldLabel);
6670
+ const transSubstitutedLabel = this.resolvePlaceholders(fields, translated);
6671
+ this.caseField.label = transSubstitutedLabel;
6672
+ this.caseField.isTranslated = this.rpxTranslationService.language === 'cy' && translated !== oldLabel;
6673
+ }
6674
+ else {
6675
+ this.caseField.label = substitutedLabel;
6676
+ this.caseField.isTranslated = false;
6677
+ }
6667
6678
  }
6668
6679
  if (this.shouldSubstitute('hint_text')) {
6669
6680
  this.caseField.hint_text = this.resolvePlaceholders(fields, this.caseField.hint_text);
@@ -6672,83 +6683,14 @@ class LabelSubstitutorDirective {
6672
6683
  this.caseField.value = this.resolvePlaceholders(fields, this.caseField.value);
6673
6684
  }
6674
6685
  }
6675
- applyLabelSubstitution(fields, isLanguageChange) {
6676
- const currentLabel = this.caseField.label;
6677
- // `originalLabel` stores the label exactly as it came from the server, before any
6678
- // placeholder values were inserted. That gives us a clean starting point when the user
6679
- // changes language or returns to the page later.
6680
- const originalLabel = this.caseField.originalLabel || currentLabel;
6681
- const substitutedCurrentLabel = this.resolvePlaceholders(fields, currentLabel);
6682
- const substitutedOriginalLabel = originalLabel === currentLabel
6683
- ? substitutedCurrentLabel
6684
- : this.resolvePlaceholders(fields, originalLabel);
6685
- const substitutedLabel = substitutedCurrentLabel || substitutedOriginalLabel;
6686
- const hasAnyLabelSubstitution = (currentLabel && currentLabel !== substitutedCurrentLabel)
6687
- || (originalLabel && originalLabel !== substitutedOriginalLabel);
6688
- if (!hasAnyLabelSubstitution) {
6689
- // No placeholders were resolved, so keep the current label and allow the render layer
6690
- // to translate it normally if needed.
6691
- this.setLabelState(substitutedLabel);
6692
- return;
6693
- }
6694
- // Preserve the original template the first time we successfully interpolate it.
6695
- this.caseField.originalLabel = this.caseField.originalLabel || originalLabel;
6696
- this.applyTranslatedLabelState(fields, originalLabel, substitutedLabel, isLanguageChange);
6697
- }
6698
- applyTranslatedLabelState(fields, originalLabel, substitutedLabel, isLanguageChange) {
6699
- // Some labels only translate correctly if we translate the template first and then
6700
- // substitute the helper values into the translated sentence.
6701
- const translatedTemplateLabel = this.resolvePlaceholders(fields, isLanguageChange ? this.translateLabelOnLanguageChange(originalLabel) : this.translateLabel(originalLabel));
6702
- // Other labels only translate correctly if we first resolve the English phrase and let
6703
- // the render layer translate that final resolved string.
6704
- const translatedResolvedLabel = isLanguageChange
6705
- ? this.translateLabelOnLanguageChange(substitutedLabel)
6706
- : this.translateLabel(substitutedLabel);
6707
- const languageIsWelsh = this.rpxTranslationService.language === 'cy';
6708
- const hasResolvedWelshTranslation = languageIsWelsh
6709
- && translatedResolvedLabel
6710
- && translatedResolvedLabel !== substitutedLabel;
6711
- const hasTemplateWelshTranslation = languageIsWelsh
6712
- && translatedTemplateLabel
6713
- && translatedTemplateLabel !== substitutedLabel;
6714
- if (hasResolvedWelshTranslation) {
6715
- // Keep the resolved English label and mark it as not yet translated so the field
6716
- // template can run `rpxTranslate` on the full phrase at render time.
6717
- this.setLabelState(substitutedLabel);
6718
- return;
6719
- }
6720
- if (hasTemplateWelshTranslation) {
6721
- // Use the template-translated result when translating the fully resolved label does
6722
- // not improve the Welsh output.
6723
- this.setLabelState(translatedTemplateLabel, true);
6724
- return;
6725
- }
6726
- // English, untranslated Welsh, or labels whose translation is handled elsewhere.
6727
- this.setLabelState(substitutedLabel);
6728
- }
6729
- translateLabel(label) {
6730
- return this.rpxTranslationPipe.transform(label);
6731
- }
6732
- translateLabelOnLanguageChange(label) {
6733
- return this.rpxTranslationService.language === 'en'
6734
- ? label
6735
- : this.translateLabel(label);
6736
- }
6737
- setLabelState(label, isTranslated = false) {
6738
- this.caseField.label = label;
6739
- this.caseField.isTranslated = isTranslated;
6740
- }
6741
6686
  onLanguageChange() {
6742
- this.resetToInitialValues(true);
6743
- this.applySubstitutions(true);
6687
+ this.resetToInitialValues();
6688
+ this.applySubstitutions();
6744
6689
  }
6745
- resetToInitialValues(isLanguageChange = false) {
6746
- if (isLanguageChange && this.caseField?.originalLabel) {
6690
+ resetToInitialValues() {
6691
+ if (this.caseField?.originalLabel) {
6747
6692
  this.caseField.label = this.caseField.originalLabel;
6748
6693
  }
6749
- if (!isLanguageChange && this.initialLabel) {
6750
- this.caseField.label = this.initialLabel;
6751
- }
6752
6694
  if (this.initialHintText) {
6753
6695
  this.caseField.hint_text = this.initialHintText;
6754
6696
  }