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