fix(ivy): update ICU placeholders format to match Closure compiler (#31459)
Since `goog.getMsg` does not process ICUs (post-processing is required via goog.i18n.MessageFormat, https://google.github.io/closure-library/api/goog.i18n.MessageFormat.html) and placeholder format used for ICUs and regular messages inside `goog.getMsg` are different, the current implementation (that assumed the same placeholder format) needs to be updated. This commit updates placeholder format used inside ICUs from `{$placeholder}` to `{PLACEHOLDER}` to better align with Closure. ICU placeholders (that were left as is prior to this commit) are now replaced with actual values in post-processing step (inside `i18nPostprocess`). PR Close #31459
This commit is contained in:

committed by
Matias Niemelä

parent
6da1446afc
commit
dee16a4355
@ -51,6 +51,7 @@ const ROOT_TEMPLATE_ID = 0;
|
||||
const PP_MULTI_VALUE_PLACEHOLDERS_REGEXP = /\[(<28>.+?<3F>?)\]/;
|
||||
const PP_PLACEHOLDERS_REGEXP = /\[(<28>.+?<3F>?)\]|(<28>\/?\*\d+:\d+<2B>)/g;
|
||||
const PP_ICU_VARS_REGEXP = /({\s*)(VAR_(PLURAL|SELECT)(_\d+)?)(\s*,)/g;
|
||||
const PP_ICU_PLACEHOLDERS_REGEXP = /{([A-Z0-9_]+)}/g;
|
||||
const PP_ICUS_REGEXP = /<2F>I18N_EXP_(ICU(_\d+)?)<29>/g;
|
||||
const PP_CLOSE_TEMPLATE_REGEXP = /\/\*/;
|
||||
const PP_TEMPLATE_ID_REGEXP = /\d+\:(\d+)/;
|
||||
@ -549,7 +550,8 @@ function appendI18nNode(
|
||||
*
|
||||
* 1. Resolve all multi-value cases (like [<5B>*1:1<><31>#2:1<>|<7C>#4:1<>|<7C>5<EFBFBD>])
|
||||
* 2. Replace all ICU vars (like "VAR_PLURAL")
|
||||
* 3. Replace all ICU references with corresponding values (like <EFBFBD>ICU_EXP_ICU_1<EFBFBD>)
|
||||
* 3. Replace all placeholders used inside ICUs in a form of {PLACEHOLDER}
|
||||
* 4. Replace all ICU references with corresponding values (like <20>ICU_EXP_ICU_1<5F>)
|
||||
* in case multiple ICUs have the same placeholder name
|
||||
*
|
||||
* @param message Raw translation string for post processing
|
||||
@ -627,7 +629,14 @@ export function ɵɵi18nPostprocess(
|
||||
});
|
||||
|
||||
/**
|
||||
* Step 3: replace all ICU references with corresponding values (like <EFBFBD>ICU_EXP_ICU_1<EFBFBD>) in case
|
||||
* Step 3: replace all placeholders used inside ICUs in a form of {PLACEHOLDER}
|
||||
*/
|
||||
result = result.replace(PP_ICU_PLACEHOLDERS_REGEXP, (match, key): string => {
|
||||
return replacements.hasOwnProperty(key) ? replacements[key] as string : match;
|
||||
});
|
||||
|
||||
/**
|
||||
* Step 4: replace all ICU references with corresponding values (like <20>ICU_EXP_ICU_1<5F>) in case
|
||||
* multiple ICUs have the same placeholder name
|
||||
*/
|
||||
result = result.replace(PP_ICUS_REGEXP, (match, key): string => {
|
||||
|
Reference in New Issue
Block a user