UNPKG

@bmat/translation-management

Version:

Manage Front-End translations from multiple sources

1 lines 1.2 kB
'use strict';Object.defineProperty(exports,'__esModule',{value:true});const justKebabCase=require('just-kebab-case');const xmldom_1=require('xmldom');const xliff_1=require('../../../constants/xliff');class XLMBaseEntity{constructor(_attributes,_children){this._attributes=_attributes;this._children=_children;this.tagName='UNDEFINED';}toXML(doc){let document=doc;if(!document){const implementation=new xmldom_1.DOMImplementation();document=implementation.createDocument(xliff_1.NAMESPACE,'xliff',null);}const selfXML=document.createElementNS(xliff_1.NAMESPACE,this.tagName);Object.keys(this._attributes).forEach(key=>{const val=this._attributes[key];selfXML.setAttributeNS(xliff_1.NAMESPACE,justKebabCase(key),val.toString());});if(this._children){this._children.forEach(child=>{if(typeof child==='string'){selfXML.appendChild(document.createTextNode(child));}else{selfXML.appendChild(child.toXML(document));}});}return selfXML;}toVDOM(){const retObj={tagName:this.tagName,attributes:this._attributes,children:null};if(this._children){retObj.children=this._children.map(child=>{if(typeof child==='string'){return child;}else{return child.toVDOM();}});}return retObj;}}exports.XLMBaseEntity=XLMBaseEntity;