fix(ivy): handle &ngsp; in i18n translations correctly (#31479)
Prior to this commit, the `` unicode symbol that represents `&ngsp` in translations was not handled correctly, i.e. was not replaced with a whitespace, thus appearing on a screen. This commit adds post-processing and replaces the mentioned symbol with a whitespace. PR Close #31479
This commit is contained in:

committed by
Matias Niemelä

parent
76e3b57a12
commit
6da1446afc
@ -403,7 +403,7 @@ function i18nStartFirstPass(
|
||||
const icuExpressions: TIcu[] = [];
|
||||
|
||||
const templateTranslation = getTranslationForTemplate(message, subTemplateIndex);
|
||||
const msgParts = templateTranslation.split(PH_REGEXP);
|
||||
const msgParts = replaceNgsp(templateTranslation).split(PH_REGEXP);
|
||||
for (let i = 0; i < msgParts.length; i++) {
|
||||
let value = msgParts[i];
|
||||
if (i & 1) {
|
||||
@ -1296,6 +1296,18 @@ function parseNodes(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Angular Dart introduced &ngsp; as a placeholder for non-removable space, see:
|
||||
* https://github.com/dart-lang/angular/blob/0bb611387d29d65b5af7f9d2515ab571fd3fbee4/_tests/test/compiler/preserve_whitespace_test.dart#L25-L32
|
||||
* In Angular Dart &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
|
||||
* and later on replaced by a space. We are re-implementing the same idea here, since translations
|
||||
* might contain this special character.
|
||||
*/
|
||||
const NGSP_UNICODE_REGEXP = /\uE500/g;
|
||||
function replaceNgsp(value: string): string {
|
||||
return value.replace(NGSP_UNICODE_REGEXP, ' ');
|
||||
}
|
||||
|
||||
let TRANSLATIONS: {[key: string]: string} = {};
|
||||
export interface I18nLocalizeOptions { translations: {[key: string]: string}; }
|
||||
|
||||
|
Reference in New Issue
Block a user