feat(ivy): add AttributeMarker.I18n
for i18n attributes (#30402)
`i18nAttributes` instructions always occur after the element instruction. This means that we need to treat `i18n-` attributes differently. By defining a specific `AttributeMarker` we can ensure that we won't trigger directive inputs with untranslated attribute values. FW-1332 #resolve PR Close #30402
This commit is contained in:

committed by
Matias Niemelä

parent
91699259b2
commit
53c6b78c51
@ -180,7 +180,23 @@ export const enum AttributeMarker {
|
||||
* ['attr', 'value', AttributeMarker.ProjectAs, ['', 'title', '']]
|
||||
* ```
|
||||
*/
|
||||
ProjectAs = 5
|
||||
ProjectAs = 5,
|
||||
|
||||
/**
|
||||
* Signals that the following attribute will be translated by runtime i18n
|
||||
*
|
||||
* For example, given the following HTML:
|
||||
*
|
||||
* ```
|
||||
* <div moo="car" foo="value" i18n-foo [bar]="binding" i18n-bar>
|
||||
* ```
|
||||
*
|
||||
* the generated code is:
|
||||
*
|
||||
* ```
|
||||
* var _c1 = ['moo', 'car', AttributeMarker.I18n, 'foo', 'bar'];
|
||||
*/
|
||||
I18n,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,17 +171,18 @@ function readClassValueFromTNode(tNode: TNode): string {
|
||||
* Attribute matching depends upon `isInlineTemplate` and `isProjectionMode`.
|
||||
* The following table summarizes which types of attributes we attempt to match:
|
||||
*
|
||||
* =========================================================================================
|
||||
* Modes | Normal Attributes | Bindings Attributes | Template Attributes
|
||||
* =========================================================================================
|
||||
* Inline + Projection | YES | YES | NO
|
||||
* -----------------------------------------------------------------------------------------
|
||||
* Inline + Directive | NO | NO | YES
|
||||
* -----------------------------------------------------------------------------------------
|
||||
* Non-inline + Projection | YES | YES | NO
|
||||
* -----------------------------------------------------------------------------------------
|
||||
* Non-inline + Directive | YES | YES | NO
|
||||
* =========================================================================================
|
||||
* ===========================================================================================================
|
||||
* Modes | Normal Attributes | Bindings Attributes | Template Attributes | I18n
|
||||
* Attributes
|
||||
* ===========================================================================================================
|
||||
* Inline + Projection | YES | YES | NO | YES
|
||||
* -----------------------------------------------------------------------------------------------------------
|
||||
* Inline + Directive | NO | NO | YES | NO
|
||||
* -----------------------------------------------------------------------------------------------------------
|
||||
* Non-inline + Projection | YES | YES | NO | YES
|
||||
* -----------------------------------------------------------------------------------------------------------
|
||||
* Non-inline + Directive | YES | YES | NO | YES
|
||||
* ===========================================================================================================
|
||||
*
|
||||
* @param name the name of the attribute to find
|
||||
* @param attrs the attribute array to examine
|
||||
@ -203,7 +204,8 @@ function findAttrIndexInNode(
|
||||
const maybeAttrName = attrs[i];
|
||||
if (maybeAttrName === name) {
|
||||
return i;
|
||||
} else if (maybeAttrName === AttributeMarker.Bindings) {
|
||||
} else if (
|
||||
maybeAttrName === AttributeMarker.Bindings || maybeAttrName === AttributeMarker.I18n) {
|
||||
bindingsMode = true;
|
||||
} else if (maybeAttrName === AttributeMarker.Classes) {
|
||||
let value = attrs[++i];
|
||||
|
@ -109,8 +109,9 @@ export function attrsStylingIndexOf(attrs: TAttributes, startIndex: number): num
|
||||
* attribute values in a `TAttributes` array are only the names of attributes,
|
||||
* and not name-value pairs.
|
||||
* @param marker The attribute marker to test.
|
||||
* @returns true if the marker is a "name-only" marker (e.g. `Bindings` or `Template`).
|
||||
* @returns true if the marker is a "name-only" marker (e.g. `Bindings`, `Template` or `I18n`).
|
||||
*/
|
||||
export function isNameOnlyAttributeMarker(marker: string | AttributeMarker | CssSelector) {
|
||||
return marker === AttributeMarker.Bindings || marker === AttributeMarker.Template;
|
||||
return marker === AttributeMarker.Bindings || marker === AttributeMarker.Template ||
|
||||
marker === AttributeMarker.I18n;
|
||||
}
|
||||
|
Reference in New Issue
Block a user