(node: html.Element, context: any)
| 284 | } |
| 285 | |
| 286 | private _visitElementLike(node: html.Element, context: any): html.Element | null { |
| 287 | this._mayBeAddBlockChildren(node); |
| 288 | this._depth++; |
| 289 | const wasInI18nNode = this._inI18nNode; |
| 290 | const wasInImplicitNode = this._inImplicitNode; |
| 291 | let childNodes: html.Node[] = []; |
| 292 | let translatedChildNodes: html.Node[] = undefined!; |
| 293 | |
| 294 | // Extract: |
| 295 | // - top level nodes with the (implicit) "i18n" attribute if not already in a section |
| 296 | // - ICU messages |
| 297 | const nodeName = node.name; |
| 298 | const i18nAttr = _getI18nAttr(node); |
| 299 | const i18nMeta = i18nAttr ? i18nAttr.value : ''; |
| 300 | const isImplicit = |
| 301 | this._implicitTags.some((tag) => nodeName === tag) && |
| 302 | !this._inIcu && |
| 303 | !this._isInTranslatableSection; |
| 304 | const isTopLevelImplicit = !wasInImplicitNode && isImplicit; |
| 305 | this._inImplicitNode = wasInImplicitNode || isImplicit; |
| 306 | |
| 307 | if (!this._isInTranslatableSection && !this._inIcu) { |
| 308 | if (i18nAttr || isTopLevelImplicit) { |
| 309 | this._inI18nNode = true; |
| 310 | const message = this._addMessage(node.children, i18nMeta)!; |
| 311 | translatedChildNodes = this._translateMessage(node, message); |
| 312 | } |
| 313 | |
| 314 | if (this._mode == _VisitorMode.Extract) { |
| 315 | const isTranslatable = i18nAttr || isTopLevelImplicit; |
| 316 | if (isTranslatable) this._openTranslatableSection(node); |
| 317 | html.visitAll(this, node.children); |
| 318 | if (isTranslatable) this._closeTranslatableSection(node, node.children); |
| 319 | } |
| 320 | } else { |
| 321 | if (i18nAttr || isTopLevelImplicit) { |
| 322 | this._reportError( |
| 323 | node, |
| 324 | 'Could not mark an element as translatable inside a translatable section', |
| 325 | ); |
| 326 | } |
| 327 | |
| 328 | if (this._mode == _VisitorMode.Extract) { |
| 329 | // Descend into child nodes for extraction |
| 330 | html.visitAll(this, node.children); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | if (this._mode === _VisitorMode.Merge) { |
| 335 | const visitNodes = translatedChildNodes || node.children; |
| 336 | visitNodes.forEach((child) => { |
| 337 | const visited = child.visit(this, context); |
| 338 | if (visited && !this._isInTranslatableSection) { |
| 339 | // Do not add the children from translatable sections (= i18n blocks here) |
| 340 | // They will be added later in this loop when the block closes (i.e. on `<!-- /i18n -->`) |
| 341 | childNodes = childNodes.concat(visited); |
| 342 | } |
| 343 | }); |
no test coverage detected