MCPcopy Create free account
hub / github.com/angular/angular / i18nStartFirstCreatePass

Function i18nStartFirstCreatePass

packages/core/src/render3/i18n/i18n_parse.ts:131–248  ·  view source on GitHub ↗
(
  tView: TView,
  parentTNodeIndex: number,
  lView: LView,
  index: number,
  message: string,
  subTemplateIndex: number,
)

Source from the content-addressed store, hash-verified

129 * `ngIf`) (-1 otherwise)
130 */
131export function i18nStartFirstCreatePass(
132 tView: TView,
133 parentTNodeIndex: number,
134 lView: LView,
135 index: number,
136 message: string,
137 subTemplateIndex: number,
138) {
139 const rootTNode = getCurrentParentTNode();
140 const createOpCodes: I18nCreateOpCodes = [] as any;
141 const updateOpCodes: I18nUpdateOpCodes = [] as any;
142 const existingTNodeStack: TNode[][] = [[]];
143 const astStack: Array<Array<I18nNode>> = [[]];
144 if (ngDevMode) {
145 attachDebugGetter(createOpCodes, i18nCreateOpCodesToString);
146 attachDebugGetter(updateOpCodes, i18nUpdateOpCodesToString);
147 }
148
149 message = getTranslationForTemplate(message, subTemplateIndex);
150 const msgParts = replaceNgsp(message).split(PH_REGEXP);
151 for (let i = 0; i < msgParts.length; i++) {
152 let value = msgParts[i];
153 if ((i & 1) === 0) {
154 // Even indexes are text (including bindings & ICU expressions)
155 const parts = i18nParseTextIntoPartsAndICU(value);
156 for (let j = 0; j < parts.length; j++) {
157 let part = parts[j];
158 if ((j & 1) === 0) {
159 // `j` is odd therefore `part` is string
160 const text = part as string;
161 ngDevMode && assertString(text, 'Parsed ICU part should be string');
162 if (text !== '') {
163 i18nStartFirstCreatePassProcessTextNode(
164 astStack[0],
165 tView,
166 rootTNode,
167 existingTNodeStack[0],
168 createOpCodes,
169 updateOpCodes,
170 lView,
171 text,
172 );
173 }
174 } else {
175 // `j` is Even therefor `part` is an `ICUExpression`
176 const icuExpression: IcuExpression = part as IcuExpression;
177 // Verify that ICU expression has the right shape. Translations might contain invalid
178 // constructions (while original messages were correct), so ICU parsing at runtime may
179 // not succeed (thus `icuExpression` remains a string).
180 // Note: we intentionally retain the error here by not using `ngDevMode`, because
181 // the value can change based on the locale and users aren't guaranteed to hit
182 // an invalid string while they're developing.
183 if (typeof icuExpression !== 'object') {
184 throw new Error(`Unable to parse ICU expression in "${message}" message.`);
185 }
186 const icuContainerTNode = createTNodeAndAddOpCode(
187 tView,
188 rootTNode,

Callers 3

toT18nFunction · 0.90
i18n_spec.tsFile · 0.90
ɵɵi18nStartFunction · 0.90

Calls 14

getCurrentParentTNodeFunction · 0.90
assertStringFunction · 0.90
assertGreaterThanOrEqualFunction · 0.90
assertOneOfFunction · 0.90
setCurrentTNodeFunction · 0.90
createTNodePlaceholderFunction · 0.90
attachDebugGetterFunction · 0.85
createTNodeAndAddOpCodeFunction · 0.85
icuStartFunction · 0.85

Tested by

no test coverage detected