| 239 | } |
| 240 | |
| 241 | visitElement(element: ml.Element, context: any): any { |
| 242 | switch (element.name) { |
| 243 | case _UNIT_TAG: |
| 244 | this._unitMlString = null!; |
| 245 | const idAttr = element.attrs.find((attr) => attr.name === 'id'); |
| 246 | if (!idAttr) { |
| 247 | this._addError(element, `<${_UNIT_TAG}> misses the "id" attribute`); |
| 248 | } else { |
| 249 | const id = idAttr.value; |
| 250 | if (this._msgIdToHtml.hasOwnProperty(id)) { |
| 251 | this._addError(element, `Duplicated translations for msg ${id}`); |
| 252 | } else { |
| 253 | ml.visitAll(this, element.children, null); |
| 254 | if (typeof this._unitMlString === 'string') { |
| 255 | this._msgIdToHtml[id] = this._unitMlString; |
| 256 | } else { |
| 257 | this._addError(element, `Message ${id} misses a translation`); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | break; |
| 262 | |
| 263 | // ignore those tags |
| 264 | case _SOURCE_TAG: |
| 265 | case _SEGMENT_SOURCE_TAG: |
| 266 | case _ALT_TRANS_TAG: |
| 267 | break; |
| 268 | |
| 269 | case _TARGET_TAG: |
| 270 | const innerTextStart = element.startSourceSpan.end.offset; |
| 271 | const innerTextEnd = element.endSourceSpan!.start.offset; |
| 272 | const content = element.startSourceSpan.start.file.content; |
| 273 | const innerText = content.slice(innerTextStart, innerTextEnd); |
| 274 | this._unitMlString = innerText; |
| 275 | break; |
| 276 | |
| 277 | case _FILE_TAG: |
| 278 | const localeAttr = element.attrs.find((attr) => attr.name === 'target-language'); |
| 279 | if (localeAttr) { |
| 280 | this._locale = localeAttr.value; |
| 281 | } |
| 282 | ml.visitAll(this, element.children, null); |
| 283 | break; |
| 284 | |
| 285 | default: |
| 286 | // TODO(vicb): assert file structure, xliff version |
| 287 | // For now only recurse on unhandled nodes |
| 288 | ml.visitAll(this, element.children, null); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | visitAttribute(attribute: ml.Attribute, context: any): any {} |
| 293 | |