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