fix(ivy): template compiler should render correct $localize placeholder names (#32509)
The `goog.getMsg()` function requires placeholder names to be camelCased. This is not the case for `$localize`. Here placeholder names need match what is serialized to translation files. Specifically such placeholder names keep their casing but have all characters that are not in `a-z`, `A-Z`, `0-9` and `_` converted to `_`. PR Close #32509
This commit is contained in:

committed by
Matias Niemelä

parent
9166baf709
commit
ea6a2e9f25
@ -9,7 +9,6 @@ import * as i18n from '../../../i18n/i18n_ast';
|
||||
import * as o from '../../../output/output_ast';
|
||||
|
||||
import {serializeIcuNode} from './icu_serializer';
|
||||
import {i18nMetaToDocStmt, metaFromI18nMessage} from './meta';
|
||||
import {formatI18nPlaceholderName} from './util';
|
||||
|
||||
export function createLocalizeStatements(
|
||||
@ -37,7 +36,7 @@ class MessagePiece {
|
||||
}
|
||||
class LiteralPiece extends MessagePiece {}
|
||||
class PlaceholderPiece extends MessagePiece {
|
||||
constructor(name: string) { super(formatI18nPlaceholderName(name)); }
|
||||
constructor(name: string) { super(formatI18nPlaceholderName(name, /* useCamelCase */ false)); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2021,13 +2021,15 @@ export function getTranslationDeclStmts(
|
||||
message: i18n.Message, variable: o.ReadVarExpr, closureVar: o.ReadVarExpr,
|
||||
params: {[name: string]: o.Expression} = {},
|
||||
transformFn?: (raw: o.ReadVarExpr) => o.Expression): o.Statement[] {
|
||||
const formattedParams = i18nFormatPlaceholderNames(params, /* useCamelCase */ true);
|
||||
const statements: o.Statement[] = [
|
||||
declareI18nVariable(variable),
|
||||
o.ifStmt(
|
||||
o.variable(NG_I18N_CLOSURE_MODE),
|
||||
createGoogleGetMsgStatements(variable, message, closureVar, formattedParams),
|
||||
createLocalizeStatements(variable, message, formattedParams)),
|
||||
createGoogleGetMsgStatements(
|
||||
variable, message, closureVar,
|
||||
i18nFormatPlaceholderNames(params, /* useCamelCase */ true)),
|
||||
createLocalizeStatements(
|
||||
variable, message, i18nFormatPlaceholderNames(params, /* useCamelCase */ false))),
|
||||
];
|
||||
|
||||
if (transformFn) {
|
||||
|
Reference in New Issue
Block a user