ilib-tools-common 1.20.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ResourceXliff.js +2 -2
- package/lib/ResourceXliff.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils.js +47 -10
- package/lib/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/ResourceXliff.js +4 -2
- package/src/index.js +2 -0
- package/src/utils.js +99 -47
package/lib/ResourceXliff.js
CHANGED
|
@@ -49,14 +49,14 @@ return res.comment}}json.pluralForm=form;json.pluralFormOther=res.getKey();retur
|
|
|
49
49
|
* @param {Resource} res the resource to convert
|
|
50
50
|
* @returns {Array.<TranslationUnit>} an array of translation units
|
|
51
51
|
* that represent the resource
|
|
52
|
-
*/return _createClass(ResourceXliff,[{key:"convertResource",value:function convertResource(res){var units=[],tu;try{switch(res.resType){case"string":tu=new _ilibXliff.TranslationUnit({project:res.project,key:res.getKey(),file:res.getPath(),sourceLocale:res.getSourceLocale(),source:res.getSource(),targetLocale:res.getTargetLocale(),target:res.getTarget(),state:res.getState(),id:res.getId(),translated:true,context:res.context,comment:res.comment,resType:res.resType,datatype:res.datatype,flavor:res.getFlavor?res.getFlavor():undefined,translate:!res.getDNT(),location:res.getLocation()});units.push(tu);break;case"array":var sarr=res.getSource();var tarr=res.getTarget();tu=new _ilibXliff.TranslationUnit({project:res.project,key:res.getKey(),file:res.getPath(),source:" ",sourceLocale:res.getSourceLocale(),targetLocale:res.getTargetLocale(),state:res.getState(),id:res.getId(),translated:true,context:res.context,comment:res.comment,resType:res.resType,datatype:res.datatype,flavor:res.getFlavor?res.getFlavor():undefined,translate:!res.getDNT(),location:res.getLocation()});for(var j=0;j<sarr.length;j++){// only output array items that have a translation
|
|
52
|
+
*/return _createClass(ResourceXliff,[{key:"convertResource",value:function convertResource(res){var units=[],tu;try{switch(res.resType){case"string":tu=new _ilibXliff.TranslationUnit({project:res.project,key:res.getKey(),file:res.getPath(),sourceLocale:res.getSourceLocale(),source:res.getSource(),targetLocale:res.getTargetLocale(),target:res.getTarget(),state:res.getState(),id:res.getId(),translated:true,context:res.context,comment:res.comment,resType:res.resType,datatype:res.datatype,flavor:res.getFlavor?res.getFlavor():undefined,translate:!res.getDNT(),location:res.getLocation(),metadata:res.metadata});units.push(tu);break;case"array":var sarr=res.getSource();var tarr=res.getTarget();tu=new _ilibXliff.TranslationUnit({project:res.project,key:res.getKey(),file:res.getPath(),source:" ",sourceLocale:res.getSourceLocale(),targetLocale:res.getTargetLocale(),state:res.getState(),id:res.getId(),translated:true,context:res.context,comment:res.comment,resType:res.resType,datatype:res.datatype,flavor:res.getFlavor?res.getFlavor():undefined,translate:!res.getDNT(),location:res.getLocation()});for(var j=0;j<sarr.length;j++){// only output array items that have a translation
|
|
53
53
|
if(sarr[j]){var newtu=tu.clone();newtu.source=sarr[j];newtu.ordinal=j;if(tarr&&j<tarr.length&&tarr[j]){newtu.target=tarr[j]}newtu.ordinal=j;units.push(newtu)}else if(tarr[j]){logger.warn("Translated array "+res.getKey()+" has no source string at index "+j+". Cannot translate. Resource is: "+JSON.stringify(res,undefined,4))}}break;case"plural":tu=new _ilibXliff.TranslationUnit({project:res.project,key:res.getKey(),file:res.getPath(),source:" ",sourceLocale:res.getSourceLocale(),targetLocale:res.getTargetLocale(),state:res.getState(),id:res.getId(),translated:true,context:res.context,resType:res.resType,datatype:res.datatype,flavor:res.getFlavor?res.getFlavor():undefined,location:res.getLocation(),translate:!res.getDNT()});var sp=res.getSource();var tp=res.getTarget();if(!tp||(0,_utils.isEmpty)(tp)){for(var p in sp){var _newtu=tu.clone();_newtu.source=sp[p];_newtu.quantity=p;_newtu.comment=generatePluralComment(res,sp,p);units.push(_newtu)}}else{for(var _p in tp){var _newtu2=tu.clone();_newtu2.source=sp[_p]||sp.other;_newtu2.target=tp[_p];_newtu2.quantity=_p;_newtu2.comment=generatePluralComment(res,sp,_p);units.push(_newtu2)}}break}}catch(e){logger.warn(e);logger.warn(JSON.stringify(res));logger.warn("Skipping that resource.")}return units}/**
|
|
54
54
|
* Convert a translation unit to a new loctool resource.
|
|
55
55
|
*
|
|
56
56
|
* @private
|
|
57
57
|
* @param {TranslationUnit} tu the translation to convert
|
|
58
58
|
* @return {Resource} the corresponding resource
|
|
59
|
-
*/},{key:"convertTransUnit",value:function convertTransUnit(tu){var res;switch(tu.resType){default:res=new _ResourceString["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:tu.source,targetLocale:tu.targetLocale,context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile});if(tu.target){res.setTarget(tu.target)}break;case"array":var arr=[];arr[tu.ordinal]=tu.source;res=new _ResourceArray["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:arr,targetLocale:tu.targetLocale,target:[],context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile});if(tu.target){res.addTargetItem(tu.ordinal,tu.target)}break;case"plural":var strings={};strings[tu.quantity]=tu.source;res=new _ResourcePlural["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:strings,targetLocale:tu.targetLocale,target:{},context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile});if(tu.target){res.addTargetPlural(tu.quantity,tu.target)}break}if(typeof tu.translate==="boolean"){res.setDNT(!tu.translate)}return res}},{key:"getPath",value:function getPath(){return this.path}},{key:"setPath",value:function setPath(newPath){this.path=newPath}/**
|
|
59
|
+
*/},{key:"convertTransUnit",value:function convertTransUnit(tu){var res;switch(tu.resType){default:res=new _ResourceString["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:tu.source,targetLocale:tu.targetLocale,context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile,metadata:tu.metadata});if(tu.target){res.setTarget(tu.target)}break;case"array":var arr=[];arr[tu.ordinal]=tu.source;res=new _ResourceArray["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:arr,targetLocale:tu.targetLocale,target:[],context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile});if(tu.target){res.addTargetItem(tu.ordinal,tu.target)}break;case"plural":var strings={};strings[tu.quantity]=tu.source;res=new _ResourcePlural["default"]({pathName:tu.file,project:tu.project,id:tu.id,key:tu.key,sourceLocale:tu.sourceLocale,source:strings,targetLocale:tu.targetLocale,target:{},context:tu.context,comment:tu.comment,resType:tu.resType,datatype:tu.datatype,state:tu.state,flavor:tu.flavor,location:new _Location["default"](tu.location),resfile:tu.resfile});if(tu.target){res.addTargetPlural(tu.quantity,tu.target)}break}if(typeof tu.translate==="boolean"){res.setDNT(!tu.translate)}return res}},{key:"getPath",value:function getPath(){return this.path}},{key:"setPath",value:function setPath(newPath){this.path=newPath}/**
|
|
60
60
|
* Parse the given xml and convert it into a set of resources.
|
|
61
61
|
*
|
|
62
62
|
* @param {string} xml the contents of the xliff file to parse
|
package/lib/ResourceXliff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceXliff.js","names":["_ilibXliff","require","_log4jsApi","_interopRequireDefault","_ResourceString","_ResourceArray","_ResourcePlural","_TranslationSet","_Location","_utils","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","_classCallCheck","a","n","TypeError","_defineProperties","r","t","length","enumerable","configurable","writable","Object","defineProperty","_toPropertyKey","key","_createClass","i","_toPrimitive","toPrimitive","call","String","Number","logger","log4js","getLogger","generatePluralComment","res","sourcePlurals","form","json","comment","JSON","parse","pluralForm","pluralFormOther","getKey","stringify","ResourceXliff","options","_options$xliff","_this","copyright","path","sourceLocale","project","allowDups","style","version","xliff","Xliff","ts","TranslationSet","getTranslationUnits","translationUnits","forEach","tu","add","convertTransUnit","value","convertResource","units","resType","TranslationUnit","file","getPath","getSourceLocale","source","getSource","targetLocale","getTargetLocale","target","getTarget","state","getState","id","getId","translated","context","datatype","flavor","getFlavor","undefined","translate","getDNT","location","getLocation","push","sarr","tarr","j","newtu","clone","ordinal","warn","sp","tp","isEmpty","p","quantity","other","ResourceString","pathName","Location","resfile","setTarget","arr","ResourceArray","addTargetItem","strings","ResourcePlural","addTargetPlural","setDNT","setPath","newPath","xml","tuList","deserialize","get","hashKey","addSourceItem","addSourcePlural","getResources","criteria","getAll","getBy","addResource","getText","size","resources","initialLength","instances","getInstances","concat","sort","left","right","index","clear","addTranslationUnits","serialize","getLines","getVersion","_default","exports","module","default"],"sources":["../src/ResourceXliff.js"],"sourcesContent":["/*\n * Xliff.js - convert an Xliff file into a set of resources and vice versa\n *\n * Copyright © 2022-2023, 2025 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Xliff, TranslationUnit } from 'ilib-xliff';\nimport log4js from \"@log4js-node/log4js-api\";\n\nimport ResourceString from './ResourceString.js';\nimport ResourceArray from './ResourceArray.js';\nimport ResourcePlural from './ResourcePlural.js';\nimport TranslationSet from './TranslationSet.js';\nimport Location from './Location.js';\nimport { isEmpty } from './utils.js';\n\nconst logger = log4js.getLogger(\"tools-common.ResourceXliff\");\n\nfunction generatePluralComment(res, sourcePlurals, form) {\n var json = {};\n\n if (res.comment) {\n try {\n // see if its json already. If so, we'll add to it\n json = JSON.parse(res.comment);\n } catch (e) {\n // not json, so just return it as is\n return res.comment;\n }\n }\n\n json.pluralForm = form;\n json.pluralFormOther = res.getKey();\n\n return JSON.stringify(json);\n}\n\n/**\n * @class a class that represents resources as an xliff file.\n */\nclass ResourceXliff {\n /**\n * Construct a new resource xliff instance. Operation of the instance\n * is controlled via the options. The options may be undefined, which represents a new,\n * clean Xliff instance.\n *\n * @constructor\n * @param {Object|undefined} options options to\n * initialize the file, or undefined for a new empty file\n * @param {string} [options.path] the path to the xliff file on disk\n * @param {string} [options.tool-id] the id of the tool that saved this xliff file\n * @param {string} [options.tool-name] the full name of the tool that saved this xliff file\n * @param {string} [options.tool-version] the version of the tool that save this xliff file\n * @param {string} [options.tool-company] the name of the company that made this tool\n * @param {string} [options.copyright] a copyright notice that you would like included into the xliff file\n * @param {string} [options.sourceLocale] specify the default source locale if a resource doesn't have a locale itself\n * @param {string} [options.allowDups] allow duplicate resources in the xliff. By default, dups are\n * filtered out. This option allows you to have trans-units that represent instances of the\n * same resource in the file with different metadata. For example, two instances of a\n * resource may have different comments which may both be useful to translators or\n * two instances of the same resource may have been extracted from different source files.\n * @param {string} [options.version] The version of xliff that will be produced by this instance. This\n * may be either \"1.2\" or \"2.0\"\n * @param {Xliff} [options.xliff] The xliff instance to use for this resource xliff instance.\n */\n constructor(options) {\n if (options) {\n this[\"tool-id\"] = options[\"tool-id\"];\n this[\"tool-name\"] = options[\"tool-name\"];\n this[\"tool-version\"] = options[\"tool-version\"];\n this[\"tool-company\"] = options[\"tool-company\"];\n this.copyright = options.copyright;\n this.path = options.path;\n this.sourceLocale = options.sourceLocale || \"en-US\";\n this.project = options.project;\n this.allowDups = options.allowDups;\n this.style = options.style || \"standard\";\n if (typeof(options.version) !== 'undefined') {\n this.version = options.version;\n }\n }\n this.sourceLocale = this.sourceLocale || \"en-US\";\n this.xliff = options?.xliff ?? new Xliff(options);\n this.ts = new TranslationSet(this.sourceLocale);\n\n if (this.xliff.getTranslationUnits().length) {\n const translationUnits = this.xliff.getTranslationUnits();\n translationUnits.forEach(tu => {\n this.ts.add(this.convertTransUnit(tu));\n });\n }\n }\n\n /**\n * Convert a resource into one or more translation units.\n *\n * @private\n * @param {Resource} res the resource to convert\n * @returns {Array.<TranslationUnit>} an array of translation units\n * that represent the resource\n */\n convertResource(res) {\n let units = [], tu;\n\n try {\n switch (res.resType) {\n case \"string\":\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n sourceLocale: res.getSourceLocale(),\n source: res.getSource(),\n targetLocale: res.getTargetLocale(),\n target: res.getTarget(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n comment: res.comment,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n translate: !res.getDNT(),\n location: res.getLocation()\n });\n units.push(tu);\n break;\n\n case \"array\":\n const sarr = res.getSource();\n let tarr = res.getTarget();\n\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n source: \" \",\n sourceLocale: res.getSourceLocale(),\n targetLocale: res.getTargetLocale(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n comment: res.comment,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n translate: !res.getDNT(),\n location: res.getLocation()\n });\n\n for (let j = 0; j < sarr.length; j++) {\n // only output array items that have a translation\n if (sarr[j]) {\n const newtu = tu.clone();\n newtu.source = sarr[j];\n newtu.ordinal = j;\n\n if (tarr && j < tarr.length && tarr[j]) {\n newtu.target = tarr[j];\n }\n\n newtu.ordinal = j;\n units.push(newtu);\n } else if (tarr[j]) {\n logger.warn(\"Translated array \" + res.getKey() + \" has no source string at index \" + j + \". Cannot translate. Resource is: \" + JSON.stringify(res, undefined, 4));\n }\n }\n break;\n\n case \"plural\":\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n source: \" \",\n sourceLocale: res.getSourceLocale(),\n targetLocale: res.getTargetLocale(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n location: res.getLocation(),\n translate: !res.getDNT()\n });\n\n const sp = res.getSource();\n const tp = res.getTarget();\n\n if (!tp || isEmpty(tp)) {\n for (let p in sp) {\n const newtu = tu.clone();\n newtu.source = sp[p];\n newtu.quantity = p;\n newtu.comment = generatePluralComment(res, sp, p);\n units.push(newtu);\n }\n } else {\n for (let p in tp) {\n const newtu = tu.clone();\n newtu.source = sp[p] || sp.other;\n newtu.target = tp[p];\n newtu.quantity = p;\n newtu.comment = generatePluralComment(res, sp, p);\n units.push(newtu);\n }\n }\n break;\n }\n } catch (e) {\n logger.warn(e);\n logger.warn(JSON.stringify(res));\n logger.warn(\"Skipping that resource.\");\n }\n\n return units;\n }\n\n /**\n * Convert a translation unit to a new loctool resource.\n *\n * @private\n * @param {TranslationUnit} tu the translation to convert\n * @return {Resource} the corresponding resource\n */\n convertTransUnit(tu) {\n let res;\n\n switch (tu.resType) {\n default:\n res = new ResourceString({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: tu.source,\n targetLocale: tu.targetLocale,\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile\n });\n\n if (tu.target) {\n res.setTarget(tu.target);\n }\n break;\n\n case \"array\":\n var arr = [];\n arr[tu.ordinal] = tu.source;\n res = new ResourceArray({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: arr,\n targetLocale: tu.targetLocale,\n target: [],\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile\n });\n\n if (tu.target) {\n res.addTargetItem(tu.ordinal, tu.target);\n }\n break;\n\n case \"plural\":\n var strings = {};\n strings[tu.quantity] = tu.source;\n res = new ResourcePlural({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: strings,\n targetLocale: tu.targetLocale,\n target: {},\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile\n });\n\n if (tu.target) {\n res.addTargetPlural(tu.quantity, tu.target);\n }\n break;\n }\n\n if (typeof(tu.translate) === \"boolean\") {\n res.setDNT(!tu.translate);\n }\n\n return res;\n }\n\n getPath() {\n return this.path;\n }\n\n setPath(newPath) {\n this.path = newPath;\n }\n\n /**\n * Parse the given xml and convert it into a set of resources.\n *\n * @param {string} xml the contents of the xliff file to parse\n * @returns {TranslationSet} the translation set that represents\n * the resources in the xliff file\n */\n parse(xml) {\n const tuList = this.xliff.deserialize(xml, this.path);\n let res;\n\n if (tuList) {\n for (var j = 0; j < tuList.length; j++) {\n const tu = tuList[j];\n\n switch (tu.resType) {\n default:\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n break;\n\n case \"array\":\n res = this.ts.get(ResourceArray.hashKey(tu.project, tu.context, tu.targetLocale || tu.sourceLocale, tu.key));\n if (res) {\n // if it already exists, amend the existing resource instead of creating a new one\n res.addSourceItem(tu.ordinal, tu.source);\n if (tu.target) {\n res.addTargetItem(tu.ordinal, tu.target);\n }\n } else {\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n }\n break;\n\n case \"plural\":\n res = this.ts.get(ResourcePlural.hashKey(tu.project, tu.context, tu.targetLocale || tu.sourceLocale, tu.key));\n if (res) {\n // if it already exists, amend the existing resource instead of creating a new one\n res.addSourcePlural(tu.quantity, tu.source);\n if (tu.target) {\n res.addTargetPlural(tu.quantity, tu.target);\n }\n } else {\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n }\n break;\n }\n }\n }\n\n return this.ts;\n }\n\n getResources(criteria) {\n if (!criteria) return this.ts.getAll();\n return this.ts.getBy(criteria);\n }\n\n addResource(res) {\n if (!res) return;\n\n if (res.getTargetLocale() === this.sourceLocale || res.getTargetLocale() === \"en\") {\n // don't add this one... cannot translate TO the source locale!\n return;\n }\n\n this.ts.add(res);\n }\n\n getText() {\n let units = [];\n\n if (this.ts.size() > 0) {\n // first convert the resources into translation units\n let resources = this.ts.getAll();\n\n if (this.allowDups) {\n // only look at the initial set of resources\n const initialLength = resources.length;\n for (let i = 0; i < initialLength; i++) {\n const res = resources[i];\n const instances = res.getInstances();\n if (instances && instances.length) {\n resources = resources.concat(instances);\n resources[i].instances = undefined;\n }\n }\n }\n resources.sort(function(left, right) {\n if (typeof(left.index) === 'number' && typeof(right.index) === 'number') {\n return left.index - right.index;\n }\n if (typeof(left.id) === 'number' && typeof(right.id) === 'number') {\n return left.id - right.id;\n }\n // no ids and no indexes? Well, then don't rearrange\n return 0;\n });\n\n // now add the translations\n for (var i = 0; i < resources.length; i++) {\n var res = resources[i];\n if (res.getTargetLocale() !== this.sourceLocale) {\n units = units.concat(this.convertResource(res));\n }\n }\n }\n\n // start with no translation units in it\n this.xliff.clear();\n this.xliff.addTranslationUnits(units);\n\n return this.xliff.serialize(true);\n }\n\n /**\n * Return the number of lines in the xml representation of this file.\n *\n * @returns {Number} the number of lines in the xml\n */\n getLines() {\n return this.xliff.getLines();\n }\n\n /**\n * Return the number of resources in this resource xliff file.\n * @returns {Number} the number of resources in this file\n */\n size() {\n return this.ts.size();\n }\n\n /**\n * Get the version number of this file. Currently, it only supports\n * xliff v1.2 and v2.0.\n * @returns {String} the version number of the file\n */\n getVersion() {\n return this.version;\n }\n}\n\nexport default ResourceXliff;\n"],"mappings":"gG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CAAAD,OAAA,CAAAA,OAAA,CAAAE,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ResourceXliff.js","names":["_ilibXliff","require","_log4jsApi","_interopRequireDefault","_ResourceString","_ResourceArray","_ResourcePlural","_TranslationSet","_Location","_utils","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","_classCallCheck","a","n","TypeError","_defineProperties","r","t","length","enumerable","configurable","writable","Object","defineProperty","_toPropertyKey","key","_createClass","i","_toPrimitive","toPrimitive","call","String","Number","logger","log4js","getLogger","generatePluralComment","res","sourcePlurals","form","json","comment","JSON","parse","pluralForm","pluralFormOther","getKey","stringify","ResourceXliff","options","_options$xliff","_this","copyright","path","sourceLocale","project","allowDups","style","version","xliff","Xliff","ts","TranslationSet","getTranslationUnits","translationUnits","forEach","tu","add","convertTransUnit","value","convertResource","units","resType","TranslationUnit","file","getPath","getSourceLocale","source","getSource","targetLocale","getTargetLocale","target","getTarget","state","getState","id","getId","translated","context","datatype","flavor","getFlavor","undefined","translate","getDNT","location","getLocation","metadata","push","sarr","tarr","j","newtu","clone","ordinal","warn","sp","tp","isEmpty","p","quantity","other","ResourceString","pathName","Location","resfile","setTarget","arr","ResourceArray","addTargetItem","strings","ResourcePlural","addTargetPlural","setDNT","setPath","newPath","xml","tuList","deserialize","get","hashKey","addSourceItem","addSourcePlural","getResources","criteria","getAll","getBy","addResource","getText","size","resources","initialLength","instances","getInstances","concat","sort","left","right","index","clear","addTranslationUnits","serialize","getLines","getVersion","_default","exports","module","default"],"sources":["../src/ResourceXliff.js"],"sourcesContent":["/*\n * Xliff.js - convert an Xliff file into a set of resources and vice versa\n *\n * Copyright © 2022-2023, 2025 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Xliff, TranslationUnit } from 'ilib-xliff';\nimport log4js from \"@log4js-node/log4js-api\";\n\nimport ResourceString from './ResourceString.js';\nimport ResourceArray from './ResourceArray.js';\nimport ResourcePlural from './ResourcePlural.js';\nimport TranslationSet from './TranslationSet.js';\nimport Location from './Location.js';\nimport { isEmpty } from './utils.js';\n\nconst logger = log4js.getLogger(\"tools-common.ResourceXliff\");\n\nfunction generatePluralComment(res, sourcePlurals, form) {\n var json = {};\n\n if (res.comment) {\n try {\n // see if its json already. If so, we'll add to it\n json = JSON.parse(res.comment);\n } catch (e) {\n // not json, so just return it as is\n return res.comment;\n }\n }\n\n json.pluralForm = form;\n json.pluralFormOther = res.getKey();\n\n return JSON.stringify(json);\n}\n\n/**\n * @class a class that represents resources as an xliff file.\n */\nclass ResourceXliff {\n /**\n * Construct a new resource xliff instance. Operation of the instance\n * is controlled via the options. The options may be undefined, which represents a new,\n * clean Xliff instance.\n *\n * @constructor\n * @param {Object|undefined} options options to\n * initialize the file, or undefined for a new empty file\n * @param {string} [options.path] the path to the xliff file on disk\n * @param {string} [options.tool-id] the id of the tool that saved this xliff file\n * @param {string} [options.tool-name] the full name of the tool that saved this xliff file\n * @param {string} [options.tool-version] the version of the tool that save this xliff file\n * @param {string} [options.tool-company] the name of the company that made this tool\n * @param {string} [options.copyright] a copyright notice that you would like included into the xliff file\n * @param {string} [options.sourceLocale] specify the default source locale if a resource doesn't have a locale itself\n * @param {string} [options.allowDups] allow duplicate resources in the xliff. By default, dups are\n * filtered out. This option allows you to have trans-units that represent instances of the\n * same resource in the file with different metadata. For example, two instances of a\n * resource may have different comments which may both be useful to translators or\n * two instances of the same resource may have been extracted from different source files.\n * @param {string} [options.version] The version of xliff that will be produced by this instance. This\n * may be either \"1.2\" or \"2.0\"\n * @param {Xliff} [options.xliff] The xliff instance to use for this resource xliff instance.\n */\n constructor(options) {\n if (options) {\n this[\"tool-id\"] = options[\"tool-id\"];\n this[\"tool-name\"] = options[\"tool-name\"];\n this[\"tool-version\"] = options[\"tool-version\"];\n this[\"tool-company\"] = options[\"tool-company\"];\n this.copyright = options.copyright;\n this.path = options.path;\n this.sourceLocale = options.sourceLocale || \"en-US\";\n this.project = options.project;\n this.allowDups = options.allowDups;\n this.style = options.style || \"standard\";\n if (typeof(options.version) !== 'undefined') {\n this.version = options.version;\n }\n }\n this.sourceLocale = this.sourceLocale || \"en-US\";\n this.xliff = options?.xliff ?? new Xliff(options);\n this.ts = new TranslationSet(this.sourceLocale);\n\n if (this.xliff.getTranslationUnits().length) {\n const translationUnits = this.xliff.getTranslationUnits();\n translationUnits.forEach(tu => {\n this.ts.add(this.convertTransUnit(tu));\n });\n }\n }\n\n /**\n * Convert a resource into one or more translation units.\n *\n * @private\n * @param {Resource} res the resource to convert\n * @returns {Array.<TranslationUnit>} an array of translation units\n * that represent the resource\n */\n convertResource(res) {\n let units = [], tu;\n\n try {\n switch (res.resType) {\n case \"string\":\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n sourceLocale: res.getSourceLocale(),\n source: res.getSource(),\n targetLocale: res.getTargetLocale(),\n target: res.getTarget(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n comment: res.comment,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n translate: !res.getDNT(),\n location: res.getLocation(),\n metadata: res.metadata\n });\n units.push(tu);\n break;\n\n case \"array\":\n const sarr = res.getSource();\n let tarr = res.getTarget();\n\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n source: \" \",\n sourceLocale: res.getSourceLocale(),\n targetLocale: res.getTargetLocale(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n comment: res.comment,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n translate: !res.getDNT(),\n location: res.getLocation()\n });\n\n for (let j = 0; j < sarr.length; j++) {\n // only output array items that have a translation\n if (sarr[j]) {\n const newtu = tu.clone();\n newtu.source = sarr[j];\n newtu.ordinal = j;\n\n if (tarr && j < tarr.length && tarr[j]) {\n newtu.target = tarr[j];\n }\n\n newtu.ordinal = j;\n units.push(newtu);\n } else if (tarr[j]) {\n logger.warn(\"Translated array \" + res.getKey() + \" has no source string at index \" + j + \". Cannot translate. Resource is: \" + JSON.stringify(res, undefined, 4));\n }\n }\n break;\n\n case \"plural\":\n tu = new TranslationUnit({\n project: res.project,\n key: res.getKey(),\n file: res.getPath(),\n source: \" \",\n sourceLocale: res.getSourceLocale(),\n targetLocale: res.getTargetLocale(),\n state: res.getState(),\n id: res.getId(),\n translated: true,\n context: res.context,\n resType: res.resType,\n datatype: res.datatype,\n flavor: res.getFlavor ? res.getFlavor() : undefined,\n location: res.getLocation(),\n translate: !res.getDNT()\n });\n\n const sp = res.getSource();\n const tp = res.getTarget();\n\n if (!tp || isEmpty(tp)) {\n for (let p in sp) {\n const newtu = tu.clone();\n newtu.source = sp[p];\n newtu.quantity = p;\n newtu.comment = generatePluralComment(res, sp, p);\n units.push(newtu);\n }\n } else {\n for (let p in tp) {\n const newtu = tu.clone();\n newtu.source = sp[p] || sp.other;\n newtu.target = tp[p];\n newtu.quantity = p;\n newtu.comment = generatePluralComment(res, sp, p);\n units.push(newtu);\n }\n }\n break;\n }\n } catch (e) {\n logger.warn(e);\n logger.warn(JSON.stringify(res));\n logger.warn(\"Skipping that resource.\");\n }\n\n return units;\n }\n\n /**\n * Convert a translation unit to a new loctool resource.\n *\n * @private\n * @param {TranslationUnit} tu the translation to convert\n * @return {Resource} the corresponding resource\n */\n convertTransUnit(tu) {\n let res;\n\n switch (tu.resType) {\n default:\n res = new ResourceString({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: tu.source,\n targetLocale: tu.targetLocale,\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile,\n metadata: tu.metadata\n });\n\n if (tu.target) {\n res.setTarget(tu.target);\n }\n break;\n\n case \"array\":\n var arr = [];\n arr[tu.ordinal] = tu.source;\n res = new ResourceArray({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: arr,\n targetLocale: tu.targetLocale,\n target: [],\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile\n });\n\n if (tu.target) {\n res.addTargetItem(tu.ordinal, tu.target);\n }\n break;\n\n case \"plural\":\n var strings = {};\n strings[tu.quantity] = tu.source;\n res = new ResourcePlural({\n pathName: tu.file,\n project: tu.project,\n id: tu.id,\n key: tu.key,\n sourceLocale: tu.sourceLocale,\n source: strings,\n targetLocale: tu.targetLocale,\n target: {},\n context: tu.context,\n comment: tu.comment,\n resType: tu.resType,\n datatype: tu.datatype,\n state: tu.state,\n flavor: tu.flavor,\n location: new Location(tu.location),\n resfile: tu.resfile\n });\n\n if (tu.target) {\n res.addTargetPlural(tu.quantity, tu.target);\n }\n break;\n }\n\n if (typeof(tu.translate) === \"boolean\") {\n res.setDNT(!tu.translate);\n }\n\n return res;\n }\n\n getPath() {\n return this.path;\n }\n\n setPath(newPath) {\n this.path = newPath;\n }\n\n /**\n * Parse the given xml and convert it into a set of resources.\n *\n * @param {string} xml the contents of the xliff file to parse\n * @returns {TranslationSet} the translation set that represents\n * the resources in the xliff file\n */\n parse(xml) {\n const tuList = this.xliff.deserialize(xml, this.path);\n let res;\n\n if (tuList) {\n for (var j = 0; j < tuList.length; j++) {\n const tu = tuList[j];\n\n switch (tu.resType) {\n default:\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n break;\n\n case \"array\":\n res = this.ts.get(ResourceArray.hashKey(tu.project, tu.context, tu.targetLocale || tu.sourceLocale, tu.key));\n if (res) {\n // if it already exists, amend the existing resource instead of creating a new one\n res.addSourceItem(tu.ordinal, tu.source);\n if (tu.target) {\n res.addTargetItem(tu.ordinal, tu.target);\n }\n } else {\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n }\n break;\n\n case \"plural\":\n res = this.ts.get(ResourcePlural.hashKey(tu.project, tu.context, tu.targetLocale || tu.sourceLocale, tu.key));\n if (res) {\n // if it already exists, amend the existing resource instead of creating a new one\n res.addSourcePlural(tu.quantity, tu.source);\n if (tu.target) {\n res.addTargetPlural(tu.quantity, tu.target);\n }\n } else {\n res = this.convertTransUnit(tu);\n this.ts.add(res);\n }\n break;\n }\n }\n }\n\n return this.ts;\n }\n\n getResources(criteria) {\n if (!criteria) return this.ts.getAll();\n return this.ts.getBy(criteria);\n }\n\n addResource(res) {\n if (!res) return;\n\n if (res.getTargetLocale() === this.sourceLocale || res.getTargetLocale() === \"en\") {\n // don't add this one... cannot translate TO the source locale!\n return;\n }\n\n this.ts.add(res);\n }\n\n getText() {\n let units = [];\n\n if (this.ts.size() > 0) {\n // first convert the resources into translation units\n let resources = this.ts.getAll();\n\n if (this.allowDups) {\n // only look at the initial set of resources\n const initialLength = resources.length;\n for (let i = 0; i < initialLength; i++) {\n const res = resources[i];\n const instances = res.getInstances();\n if (instances && instances.length) {\n resources = resources.concat(instances);\n resources[i].instances = undefined;\n }\n }\n }\n resources.sort(function(left, right) {\n if (typeof(left.index) === 'number' && typeof(right.index) === 'number') {\n return left.index - right.index;\n }\n if (typeof(left.id) === 'number' && typeof(right.id) === 'number') {\n return left.id - right.id;\n }\n // no ids and no indexes? Well, then don't rearrange\n return 0;\n });\n\n // now add the translations\n for (var i = 0; i < resources.length; i++) {\n var res = resources[i];\n if (res.getTargetLocale() !== this.sourceLocale) {\n units = units.concat(this.convertResource(res));\n }\n }\n }\n\n // start with no translation units in it\n this.xliff.clear();\n this.xliff.addTranslationUnits(units);\n\n return this.xliff.serialize(true);\n }\n\n /**\n * Return the number of lines in the xml representation of this file.\n *\n * @returns {Number} the number of lines in the xml\n */\n getLines() {\n return this.xliff.getLines();\n }\n\n /**\n * Return the number of resources in this resource xliff file.\n * @returns {Number} the number of resources in this file\n */\n size() {\n return this.ts.size();\n }\n\n /**\n * Get the version number of this file. Currently, it only supports\n * xliff v1.2 and v2.0.\n * @returns {String} the version number of the file\n */\n getVersion() {\n return this.version;\n }\n}\n\nexport default ResourceXliff;\n"],"mappings":"gGAmBA,IAAAA,UAAA,CAAAC,OAAA,eACA,IAAAC,UAAA,CAAAC,sBAAA,CAAAF,OAAA,6BAEA,IAAAG,eAAA,CAAAD,sBAAA,CAAAF,OAAA,yBACA,IAAAI,cAAA,CAAAF,sBAAA,CAAAF,OAAA,wBACA,IAAAK,eAAA,CAAAH,sBAAA,CAAAF,OAAA,yBACA,IAAAM,eAAA,CAAAJ,sBAAA,CAAAF,OAAA,yBACA,IAAAO,SAAA,CAAAL,sBAAA,CAAAF,OAAA,mBACA,IAAAQ,MAAA,CAAAR,OAAA,eAAqC,SAAAE,uBAAAO,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,YAAAA,CAAA,WAAAE,QAAAC,CAAA,mCAAAD,OAAA,oBAAAE,MAAA,mBAAAA,MAAA,CAAAC,QAAA,UAAAF,CAAA,gBAAAA,CAAA,WAAAA,CAAA,SAAAA,CAAA,qBAAAC,MAAA,EAAAD,CAAA,CAAAG,WAAA,GAAAF,MAAA,EAAAD,CAAA,GAAAC,MAAA,CAAAG,SAAA,iBAAAJ,CAAA,EAAAD,OAAA,CAAAC,CAAA,WAAAK,gBAAAC,CAAA,CAAAC,CAAA,OAAAD,CAAA,YAAAC,CAAA,YAAAC,SAAA,+CAAAC,kBAAAZ,CAAA,CAAAa,CAAA,UAAAC,CAAA,GAAAA,CAAA,CAAAD,CAAA,CAAAE,MAAA,CAAAD,CAAA,QAAAX,CAA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SAAAmF,QAAQA,CAAA,CAAG,CACP,MAAO,KAAI,CAAC7F,KAAK,CAAC6F,QAAQ,CAAC,CAC/B,CAEA;AACJ;AACA;AACA,OAHI,GAAA/H,GAAA,QAAA4C,KAAA,CAIA,SAAAsE,IAAIA,CAAA,CAAG,CACH,MAAO,KAAI,CAAC9E,EAAE,CAAC8E,IAAI,CAAC,CACxB,CAEA;AACJ;AACA;AACA;AACA,OAJI,GAAAlH,GAAA,cAAA4C,KAAA,CAKA,SAAAoF,UAAUA,CAAA,CAAG,CACT,MAAO,KAAI,CAAC/F,OAChB,CAAC,WAAAgG,QAAA,CAAAC,OAAA,YAGU3G,aAAa,CAAA4G,MAAA,CAAAD,OAAA,CAAAA,OAAA,CAAAE,OAAA","ignoreList":[]}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"Location",{enumerable:true,get:function get(){return _Location["default"]}});Object.defineProperty(exports,"Resource",{enumerable:true,get:function get(){return _Resource["default"]}});Object.defineProperty(exports,"ResourceArray",{enumerable:true,get:function get(){return _ResourceArray["default"]}});Object.defineProperty(exports,"ResourcePlural",{enumerable:true,get:function get(){return _ResourcePlural["default"]}});Object.defineProperty(exports,"ResourceString",{enumerable:true,get:function get(){return _ResourceString["default"]}});Object.defineProperty(exports,"ResourceXliff",{enumerable:true,get:function get(){return _ResourceXliff["default"]}});Object.defineProperty(exports,"TranslationSet",{enumerable:true,get:function get(){return _TranslationSet["default"]}});Object.defineProperty(exports,"TranslationUnit",{enumerable:true,get:function get(){return _TranslationUnit["default"]}});Object.defineProperty(exports,"TranslationVariant",{enumerable:true,get:function get(){return _TranslationVariant["default"]}});Object.defineProperty(exports,"VALID_STATES",{enumerable:true,get:function get(){return _Resource.VALID_STATES}});Object.defineProperty(exports,"cleanString",{enumerable:true,get:function get(){return _utils.cleanString}});Object.defineProperty(exports,"containsActualText",{enumerable:true,get:function get(){return _utils.containsActualText}});Object.defineProperty(exports,"convertICUToPluralRes",{enumerable:true,get:function get(){return _ResourceConvert.convertICUToPluralRes}});Object.defineProperty(exports,"convertPluralResToICU",{enumerable:true,get:function get(){return _ResourceConvert.convertPluralResToICU}});Object.defineProperty(exports,"escaperFactory",{enumerable:true,get:function get(){return _EscaperFactory["default"]}});Object.defineProperty(exports,"formatPath",{enumerable:true,get:function get(){return _utils.formatPath}});Object.defineProperty(exports,"getLanguagePluralCategories",{enumerable:true,get:function get(){return _utils.getLanguagePluralCategories}});Object.defineProperty(exports,"getLocaleFromPath",{enumerable:true,get:function get(){return _utils.getLocaleFromPath}});Object.defineProperty(exports,"hashKey",{enumerable:true,get:function get(){return _utils.hashKey}});Object.defineProperty(exports,"ignoreTags",{enumerable:true,get:function get(){return _utils.ignoreTags}});Object.defineProperty(exports,"isEmpty",{enumerable:true,get:function get(){return _utils.isEmpty}});Object.defineProperty(exports,"isValidState",{enumerable:true,get:function get(){return _Resource.isValidState}});Object.defineProperty(exports,"localizableAttributes",{enumerable:true,get:function get(){return _utils.localizableAttributes}});Object.defineProperty(exports,"makeDirs",{enumerable:true,get:function get(){return _utils.makeDirs}});Object.defineProperty(exports,"nonBreakingTags",{enumerable:true,get:function get(){return _utils.nonBreakingTags}});Object.defineProperty(exports,"objectMap",{enumerable:true,get:function get(){return _utils.objectMap}});Object.defineProperty(exports,"parsePath",{enumerable:true,get:function get(){return _utils.parsePath}});Object.defineProperty(exports,"selfClosingTags",{enumerable:true,get:function get(){return _utils.selfClosingTags}});Object.defineProperty(exports,"walk",{enumerable:true,get:function get(){return _DirectoryWalk["default"]}});var _Resource=_interopRequireWildcard(require("./Resource.js"));var _ResourceString=_interopRequireDefault(require("./ResourceString.js"));var _ResourceArray=_interopRequireDefault(require("./ResourceArray.js"));var _ResourcePlural=_interopRequireDefault(require("./ResourcePlural.js"));var _TranslationSet=_interopRequireDefault(require("./TranslationSet.js"));var _ResourceXliff=_interopRequireDefault(require("./ResourceXliff.js"));var _TranslationUnit=_interopRequireDefault(require("./TranslationUnit.js"));var _TranslationVariant=_interopRequireDefault(require("./TranslationVariant.js"));var _Location=_interopRequireDefault(require("./Location.js"));var _DirectoryWalk=_interopRequireDefault(require("./DirectoryWalk.js"));var _ResourceConvert=require("./ResourceConvert.js");var _EscaperFactory=_interopRequireDefault(require("./EscaperFactory.js"));var _utils=require("./utils.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap,t=new WeakMap;return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r})(e)}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=_typeof(e)&&"function"!=typeof e)return{"default":e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u]}return n["default"]=e,t&&t.set(e,n),n}
|
|
1
|
+
"use strict";function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"Location",{enumerable:true,get:function get(){return _Location["default"]}});Object.defineProperty(exports,"Resource",{enumerable:true,get:function get(){return _Resource["default"]}});Object.defineProperty(exports,"ResourceArray",{enumerable:true,get:function get(){return _ResourceArray["default"]}});Object.defineProperty(exports,"ResourcePlural",{enumerable:true,get:function get(){return _ResourcePlural["default"]}});Object.defineProperty(exports,"ResourceString",{enumerable:true,get:function get(){return _ResourceString["default"]}});Object.defineProperty(exports,"ResourceXliff",{enumerable:true,get:function get(){return _ResourceXliff["default"]}});Object.defineProperty(exports,"TranslationSet",{enumerable:true,get:function get(){return _TranslationSet["default"]}});Object.defineProperty(exports,"TranslationUnit",{enumerable:true,get:function get(){return _TranslationUnit["default"]}});Object.defineProperty(exports,"TranslationVariant",{enumerable:true,get:function get(){return _TranslationVariant["default"]}});Object.defineProperty(exports,"VALID_STATES",{enumerable:true,get:function get(){return _Resource.VALID_STATES}});Object.defineProperty(exports,"cleanString",{enumerable:true,get:function get(){return _utils.cleanString}});Object.defineProperty(exports,"containsActualText",{enumerable:true,get:function get(){return _utils.containsActualText}});Object.defineProperty(exports,"convertICUToPluralRes",{enumerable:true,get:function get(){return _ResourceConvert.convertICUToPluralRes}});Object.defineProperty(exports,"convertPluralResToICU",{enumerable:true,get:function get(){return _ResourceConvert.convertPluralResToICU}});Object.defineProperty(exports,"escaperFactory",{enumerable:true,get:function get(){return _EscaperFactory["default"]}});Object.defineProperty(exports,"formatLocaleParams",{enumerable:true,get:function get(){return _utils.formatLocaleParams}});Object.defineProperty(exports,"formatPath",{enumerable:true,get:function get(){return _utils.formatPath}});Object.defineProperty(exports,"getLanguagePluralCategories",{enumerable:true,get:function get(){return _utils.getLanguagePluralCategories}});Object.defineProperty(exports,"getLocaleFromPath",{enumerable:true,get:function get(){return _utils.getLocaleFromPath}});Object.defineProperty(exports,"hashKey",{enumerable:true,get:function get(){return _utils.hashKey}});Object.defineProperty(exports,"ignoreTags",{enumerable:true,get:function get(){return _utils.ignoreTags}});Object.defineProperty(exports,"isEmpty",{enumerable:true,get:function get(){return _utils.isEmpty}});Object.defineProperty(exports,"isValidState",{enumerable:true,get:function get(){return _Resource.isValidState}});Object.defineProperty(exports,"localizableAttributes",{enumerable:true,get:function get(){return _utils.localizableAttributes}});Object.defineProperty(exports,"makeDirs",{enumerable:true,get:function get(){return _utils.makeDirs}});Object.defineProperty(exports,"nonBreakingTags",{enumerable:true,get:function get(){return _utils.nonBreakingTags}});Object.defineProperty(exports,"objectMap",{enumerable:true,get:function get(){return _utils.objectMap}});Object.defineProperty(exports,"parsePath",{enumerable:true,get:function get(){return _utils.parsePath}});Object.defineProperty(exports,"selfClosingTags",{enumerable:true,get:function get(){return _utils.selfClosingTags}});Object.defineProperty(exports,"walk",{enumerable:true,get:function get(){return _DirectoryWalk["default"]}});var _Resource=_interopRequireWildcard(require("./Resource.js"));var _ResourceString=_interopRequireDefault(require("./ResourceString.js"));var _ResourceArray=_interopRequireDefault(require("./ResourceArray.js"));var _ResourcePlural=_interopRequireDefault(require("./ResourcePlural.js"));var _TranslationSet=_interopRequireDefault(require("./TranslationSet.js"));var _ResourceXliff=_interopRequireDefault(require("./ResourceXliff.js"));var _TranslationUnit=_interopRequireDefault(require("./TranslationUnit.js"));var _TranslationVariant=_interopRequireDefault(require("./TranslationVariant.js"));var _Location=_interopRequireDefault(require("./Location.js"));var _DirectoryWalk=_interopRequireDefault(require("./DirectoryWalk.js"));var _ResourceConvert=require("./ResourceConvert.js");var _EscaperFactory=_interopRequireDefault(require("./EscaperFactory.js"));var _utils=require("./utils.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap,t=new WeakMap;return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r})(e)}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=_typeof(e)&&"function"!=typeof e)return{"default":e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u]}return n["default"]=e,t&&t.set(e,n),n}
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_Resource","_interopRequireWildcard","require","_ResourceString","_interopRequireDefault","_ResourceArray","_ResourcePlural","_TranslationSet","_ResourceXliff","_TranslationUnit","_TranslationVariant","_Location","_DirectoryWalk","_ResourceConvert","_EscaperFactory","_utils","e","__esModule","_getRequireWildcardCache","WeakMap","r","t","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set"],"sources":["../src/index.js"],"sourcesContent":["/*\n * index.js - export all the library code from one main file\n *\n * Copyright © 2022 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Resource, { VALID_STATES, isValidState } from './Resource.js';\nimport ResourceString from './ResourceString.js';\nimport ResourceArray from './ResourceArray.js';\nimport ResourcePlural from './ResourcePlural.js';\nimport TranslationSet from './TranslationSet.js';\nimport ResourceXliff from './ResourceXliff.js';\nimport TranslationUnit from './TranslationUnit.js';\nimport TranslationVariant from './TranslationVariant.js';\nimport Location from './Location.js';\nimport walk from './DirectoryWalk.js';\nimport {convertPluralResToICU, convertICUToPluralRes} from './ResourceConvert.js';\nimport escaperFactory from './EscaperFactory.js';\n\nimport {\n formatPath,\n parsePath,\n getLocaleFromPath,\n cleanString,\n isEmpty,\n makeDirs,\n containsActualText,\n objectMap,\n hashKey,\n nonBreakingTags,\n selfClosingTags,\n ignoreTags,\n localizableAttributes,\n getLanguagePluralCategories\n} from './utils.js';\n\nexport {\n Resource,\n VALID_STATES,\n isValidState,\n ResourceString,\n ResourceArray,\n ResourcePlural,\n TranslationSet,\n TranslationUnit,\n TranslationVariant,\n ResourceXliff,\n formatPath,\n parsePath,\n getLocaleFromPath,\n cleanString,\n isEmpty,\n makeDirs,\n containsActualText,\n objectMap,\n hashKey,\n nonBreakingTags,\n selfClosingTags,\n ignoreTags,\n localizableAttributes,\n Location,\n walk,\n convertPluralResToICU,\n convertICUToPluralRes,\n escaperFactory,\n getLanguagePluralCategories\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_Resource","_interopRequireWildcard","require","_ResourceString","_interopRequireDefault","_ResourceArray","_ResourcePlural","_TranslationSet","_ResourceXliff","_TranslationUnit","_TranslationVariant","_Location","_DirectoryWalk","_ResourceConvert","_EscaperFactory","_utils","e","__esModule","_getRequireWildcardCache","WeakMap","r","t","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set"],"sources":["../src/index.js"],"sourcesContent":["/*\n * index.js - export all the library code from one main file\n *\n * Copyright © 2022 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Resource, { VALID_STATES, isValidState } from './Resource.js';\nimport ResourceString from './ResourceString.js';\nimport ResourceArray from './ResourceArray.js';\nimport ResourcePlural from './ResourcePlural.js';\nimport TranslationSet from './TranslationSet.js';\nimport ResourceXliff from './ResourceXliff.js';\nimport TranslationUnit from './TranslationUnit.js';\nimport TranslationVariant from './TranslationVariant.js';\nimport Location from './Location.js';\nimport walk from './DirectoryWalk.js';\nimport {convertPluralResToICU, convertICUToPluralRes} from './ResourceConvert.js';\nimport escaperFactory from './EscaperFactory.js';\n\nimport {\n formatLocaleParams,\n formatPath,\n parsePath,\n getLocaleFromPath,\n cleanString,\n isEmpty,\n makeDirs,\n containsActualText,\n objectMap,\n hashKey,\n nonBreakingTags,\n selfClosingTags,\n ignoreTags,\n localizableAttributes,\n getLanguagePluralCategories\n} from './utils.js';\n\nexport {\n Resource,\n VALID_STATES,\n isValidState,\n ResourceString,\n ResourceArray,\n ResourcePlural,\n TranslationSet,\n TranslationUnit,\n TranslationVariant,\n ResourceXliff,\n formatLocaleParams,\n formatPath,\n parsePath,\n getLocaleFromPath,\n cleanString,\n isEmpty,\n makeDirs,\n containsActualText,\n objectMap,\n hashKey,\n nonBreakingTags,\n selfClosingTags,\n ignoreTags,\n localizableAttributes,\n Location,\n walk,\n convertPluralResToICU,\n convertICUToPluralRes,\n escaperFactory,\n getLanguagePluralCategories\n};\n"],"mappings":"0wHAmBA,IAAAA,SAAA,CAAAC,uBAAA,CAAAC,OAAA,mBACA,IAAAC,eAAA,CAAAC,sBAAA,CAAAF,OAAA,yBACA,IAAAG,cAAA,CAAAD,sBAAA,CAAAF,OAAA,wBACA,IAAAI,eAAA,CAAAF,sBAAA,CAAAF,OAAA,yBACA,IAAAK,eAAA,CAAAH,sBAAA,CAAAF,OAAA,yBACA,IAAAM,cAAA,CAAAJ,sBAAA,CAAAF,OAAA,wBACA,IAAAO,gBAAA,CAAAL,sBAAA,CAAAF,OAAA,0BACA,IAAAQ,mBAAA,CAAAN,sBAAA,CAAAF,OAAA,6BACA,IAAAS,SAAA,CAAAP,sBAAA,CAAAF,OAAA,mBACA,IAAAU,cAAA,CAAAR,sBAAA,CAAAF,OAAA,wBACA,IAAAW,gBAAA,CAAAX,OAAA,yBACA,IAAAY,eAAA,CAAAV,sBAAA,CAAAF,OAAA,yBAEA,IAAAa,MAAA,CAAAb,OAAA,eAgBoB,SAAAE,uBAAAY,CAAA,SAAA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containsActualText=containsActualText;exports.formatPath=formatPath;exports.getLanguagePluralCategories=getLanguagePluralCategories;exports.getLocaleFromPath=getLocaleFromPath;exports.hashKey=hashKey;exports.ignoreTags=void 0;exports.isEmpty=isEmpty;exports.localizableAttributes=void 0;exports.makeDirs=makeDirs;exports.nonBreakingTags=void 0;exports.objectMap=objectMap;exports.parsePath=parsePath;exports.selfClosingTags=void 0;var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _ilibLocale=_interopRequireDefault(require("ilib-locale"));var _ilibCtype=require("ilib-ctype");var _pluralCategories=_interopRequireDefault(require("./pluralCategories.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}/*
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.cleanString=cleanString;exports.containsActualText=containsActualText;exports.formatLocaleParams=formatLocaleParams;exports.formatPath=formatPath;exports.getLanguagePluralCategories=getLanguagePluralCategories;exports.getLocaleFromPath=getLocaleFromPath;exports.hashKey=hashKey;exports.ignoreTags=void 0;exports.isEmpty=isEmpty;exports.localizableAttributes=void 0;exports.makeDirs=makeDirs;exports.nonBreakingTags=void 0;exports.objectMap=objectMap;exports.parsePath=parsePath;exports.selfClosingTags=void 0;var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _ilibLocale=_interopRequireDefault(require("ilib-locale"));var _ilibCtype=require("ilib-ctype");var _pluralCategories=_interopRequireDefault(require("./pluralCategories.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}/*
|
|
2
2
|
* utils.js - utility functions to support the other code
|
|
3
3
|
*
|
|
4
|
-
* Copyright © 2022-2023, 2025 JEDLSoft
|
|
4
|
+
* Copyright © 2022-2023, 2025-2026 JEDLSoft
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -26,6 +26,41 @@
|
|
|
26
26
|
* @param {Object} obj object to test
|
|
27
27
|
* @returns {Boolean} true if there are no properties, false otherwise
|
|
28
28
|
*/function isEmpty(obj){var prop=undefined;if(!obj){return true}for(prop in obj){if(prop&&obj[prop]){return false}}return true};/**
|
|
29
|
+
* Format a string template with locale-related parameters.
|
|
30
|
+
*
|
|
31
|
+
* This function substitutes locale-related placeholders in a template string
|
|
32
|
+
* without treating the string as a file path (no path normalization).
|
|
33
|
+
* This is useful for formatting headers, footers, or other strings that
|
|
34
|
+
* contain locale placeholders but should not be treated as file paths.
|
|
35
|
+
*
|
|
36
|
+
* This function recognizes and replaces the following strings in
|
|
37
|
+
* templates:
|
|
38
|
+
* - [locale] the full BCP-47 locale specification for the target locale
|
|
39
|
+
* eg. "zh-Hans-CN" -> "zh-Hans-CN"
|
|
40
|
+
* - [language] the language portion of the full locale
|
|
41
|
+
* eg. "zh-Hans-CN" -> "zh"
|
|
42
|
+
* - [script] the script portion of the full locale
|
|
43
|
+
* eg. "zh-Hans-CN" -> "Hans"
|
|
44
|
+
* - [region] the region portion of the full locale
|
|
45
|
+
* eg. "zh-Hans-CN" -> "CN"
|
|
46
|
+
* - [localeDir] the full locale where each portion of the locale
|
|
47
|
+
* is a directory in this order: [langage], [script], [region].
|
|
48
|
+
* eg, "zh-Hans-CN" -> "zh/Hans/CN", but "en" -> "en".
|
|
49
|
+
* - [localeUnder] the full BCP-47 locale specification, but using
|
|
50
|
+
* underscores to separate the locale parts instead of dashes.
|
|
51
|
+
* eg. "zh-Hans-CN" -> "zh_Hans_CN"
|
|
52
|
+
* - [localeLower] the full BCP-47 locale specification, but makes
|
|
53
|
+
* all locale parts lowercased.
|
|
54
|
+
* eg. "zh-Hans-CN" -> "zh-hans-cn"
|
|
55
|
+
*
|
|
56
|
+
* Unknown keywords are preserved in the output unchanged.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} template the template string to format
|
|
59
|
+
* @param {string|Object} locale the locale specifier, either as a string
|
|
60
|
+
* or as a Locale object
|
|
61
|
+
* @returns {string} the formatted string with locale placeholders replaced
|
|
62
|
+
*/function formatLocaleParams(template,locale){if(!template)return"";var l=typeof locale==="string"?new _ilibLocale["default"](locale||"en"):locale;var localeSpec=l.getSpec();var output="";for(var i=0;i<template.length;i++){if(template[i]!=="["){output+=template[i]}else{var start=++i;while(i<template.length&&template[i]!=="]"){i++}var keyword=template.substring(start,i);switch(keyword){case"locale":output+=localeSpec;break;case"language":output+=l.getLanguage()||"";break;case"script":output+=l.getScript()||"";break;case"region":output+=l.getRegion()||"";break;case"localeDir":output+=localeSpec.replace(/-/g,"/");break;case"localeUnder":output+=localeSpec.replace(/-/g,"_");break;case"localeLower":output+=localeSpec.toLowerCase();break;default:// unknown keyword, preserve it unchanged
|
|
63
|
+
output+="["+keyword+"]";break}}}return output}/**
|
|
29
64
|
* Format a file path using a path template and parameters.
|
|
30
65
|
*
|
|
31
66
|
* This function is used to generate an output file path for a given
|
|
@@ -61,15 +96,17 @@
|
|
|
61
96
|
* all locale parts lowercased.
|
|
62
97
|
* eg. "zh-Hans-CN" -> "zh-hans-cn"
|
|
63
98
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @param {string}
|
|
70
|
-
*
|
|
99
|
+
* @param {string} template the path template string
|
|
100
|
+
* @param {Object} parameters an object containing:
|
|
101
|
+
* @param {string} parameters.sourcepath the path to the source file, relative to the
|
|
102
|
+
* root of the project
|
|
103
|
+
* @param {string} parameters.locale the locale for the output file path
|
|
104
|
+
* @param {string} parameters.resourceDir optional resource directory to substitute
|
|
105
|
+
* for [resourceDir] in the template
|
|
71
106
|
* @returns {string} the formatted file path
|
|
72
|
-
*/function formatPath(template,parameters){var pathname=parameters.sourcepath||"";var locale=parameters.locale||"en";var
|
|
107
|
+
*/function formatPath(template,parameters){var pathname=parameters.sourcepath||"";var locale=parameters.locale||"en";var resourceDir=parameters.resourceDir||".";// First, handle locale-related substitutions without path normalization
|
|
108
|
+
var output=formatLocaleParams(template,locale);// Now handle path-specific keywords
|
|
109
|
+
var base;var lastDot;output=output.replace(/\[dir\]/g,_path["default"].dirname(pathname));output=output.replace(/\[filename\]/g,_path["default"].basename(pathname));output=output.replace(/\[resourceDir\]/g,resourceDir);if(output.includes("[extension]")){base=_path["default"].basename(pathname);output=output.replace(/\[extension\]/g,base.indexOf(".")>-1?base.substring(base.lastIndexOf(".")+1):"")}if(output.includes("[basename]")){base=_path["default"].basename(pathname);lastDot=base.lastIndexOf(".");output=output.replace(/\[basename\]/g,lastDot>-1?base.substring(0,lastDot):base)}return _path["default"].normalize(output)};var matchExprs={"dir":{regex:"(.*)",brackets:1,groups:{dir:1}},"basename":{regex:"(.*?)",brackets:1,groups:{basename:1}},"extension":{regex:"(.*)",brackets:1,groups:{extension:1}},"locale":{regex:"(([a-z][a-z][a-z]?)(-([A-Z][a-z][a-z][a-z]))?(-([A-Z][A-Z]|[0-9][0-9][0-9]))?)",brackets:6,groups:{locale:1,language:2,script:4,region:6}},"language":{regex:"([a-z][a-z][a-z]?)",brackets:1,groups:{language:1}},"script":{regex:"([A-Z][a-z][a-z][a-z])",brackets:1,groups:{script:1}},"region":{regex:"([A-Z][A-Z]|[0-9][0-9][0-9])",brackets:1,groups:{region:1}},"localeDir":{regex:"(([a-z][a-z][a-z]?)(/([A-Z][a-z][a-z][a-z]))?(/([A-Z][A-Z]|[0-9][0-9][0-9]))?)",brackets:6,groups:{localeDir:1,language:2,script:4,region:6}},"localeUnder":{regex:"(([a-z][a-z][a-z]?)(_([A-Z][a-z][a-z][a-z]))?(_([A-Z][A-Z]|[0-9][0-9][0-9]))?)",brackets:6,groups:{localeUnder:1,language:2,script:4,region:6}},"localeLower":{regex:"(([a-z][a-z][a-z]?)(-([a-z][a-z][a-z][a-z]))?(-([a-z][a-z]|[0-9][0-9][0-9]))?)",brackets:6,groups:{localeUnder:1,language:2,script:4,region:6}}};/**
|
|
73
110
|
* Parse a path according to the given template, and return the parts.
|
|
74
111
|
* The parts can be any of the fields mentioned in the {@link formatPath}
|
|
75
112
|
* documentation. If any field is not parsed, the result is an empty object
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_fs","_interopRequireDefault","require","_path","_ilibLocale","_ilibCtype","_pluralCategories","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","cleanString","str","undefined","toLowerCase","replace","trim","isEmpty","obj","prop","formatPath","template","parameters","pathname","sourcepath","locale","l","Locale","output","base","i","length","start","keyword","substring","path","dirname","basename","indexOf","lastIndexOf","getLanguage","getScript","getRegion","getSpec","normalize","matchExprs","regex","brackets","groups","dir","extension","language","script","region","localeDir","localeUnder","parsePath","matchGroups","totalBrackets","defaultMappings","logger","warning","re","RegExp","match","exec","found","groupName","getLocaleFromPath","charAt","toUpperCase","slice","makeDirs","parts","split","p","join","fs","existsSync","mkdirSync","containsActualText","cleaned","c","isAlnum","isIdeo","isPrimitive","type","objectMap","object","visitor","Array","isArray","map","item","ret","hasOwnProperty","hashKey","source","hash","modulus","multiple","charCodeAt","value","nonBreakingTags","exports","selfClosingTags","ignoreTags","localizableAttributes","defaultPluralCategories","getLanguagePluralCategories","_locale$getLanguage","_pluralCategories$lan","lang","pluralCategories"],"sources":["../src/utils.js"],"sourcesContent":["/*\n * utils.js - utility functions to support the other code\n *\n * Copyright © 2022-2023, 2025 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport path from 'path';\nimport Locale from 'ilib-locale';\n\nimport { isAlnum, isIdeo } from 'ilib-ctype';\n\nimport pluralCategories from './pluralCategories.js';\n\n/**\n * Clean a string for matching against other strings by removing\n * differences that are inconsequential for translation.\n *\n * @param {String} str string to clean\n * @returns {String} the cleaned string\n */\nexport function cleanString(str) {\n if (typeof(str) !== 'string') {\n return undefined;\n }\n return str.toLowerCase().\n replace(/\\\\n/g, \" \").\n replace(/\\\\t/g, \" \").\n replace(/\\\\/g, \"\").\n replace(/\\s+/g, \" \").\n trim().\n replace(/'/g, \"'\").\n replace(/"/g, '\"').\n replace(/</g, \"<\").\n replace(/>/g, \">\").\n replace(/&/g, \"&\").\n replace(/’/g, \"'\");\n};\n\n/**\n * Is an empty object or not\n * @param {Object} obj object to test\n * @returns {Boolean} true if there are no properties, false otherwise\n */\nexport function isEmpty(obj) {\n let prop = undefined;\n\n if (!obj) {\n return true;\n }\n\n for (prop in obj) {\n if (prop && obj[prop]) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Format a file path using a path template and parameters.\n *\n * This function is used to generate an output file path for a given\n * source file path and a locale specifier.\n * The template replaces strings in square brackets with special values,\n * and keeps any characters intact that are not in square brackets.\n * This function recognizes and replaces the following strings in\n * templates:\n * - [dir] the original directory where the source file\n * came from. This is given as a directory that is relative\n * to the root of the project. eg. \"foo/bar/strings.json\" -> \"foo/bar\"\n * - [filename] the file name of the source file.\n * eg. \"foo/bar/strings.json\" -> \"strings.json\"\n * - [basename] the basename of the source file without any extension\n * eg. \"foo/bar/strings.json\" -> \"strings\"\n * - [extension] the extension part of the file name of the source file.\n * etc. \"foo/bar/strings.json\" -> \"json\"\n * - [locale] the full BCP-47 locale specification for the target locale\n * eg. \"zh-Hans-CN\" -> \"zh-Hans-CN\"\n * - [language] the language portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"zh\"\n * - [script] the script portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"Hans\"\n * - [region] the region portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"CN\"\n * - [localeDir] the full locale where each portion of the locale\n * is a directory in this order: [langage], [script], [region].\n * eg, \"zh-Hans-CN\" -> \"zh/Hans/CN\", but \"en\" -> \"en\".\n * - [localeUnder] the full BCP-47 locale specification, but using\n * underscores to separate the locale parts instead of dashes.\n * eg. \"zh-Hans-CN\" -> \"zh_Hans_CN\"\n * - [localeLower] the full BCP-47 locale specification, but makes\n * all locale parts lowercased.\n * eg. \"zh-Hans-CN\" -> \"zh-hans-cn\"\n *\n * The parameters may include the following:\n * - sourcepath - the path to the source file, relative to the root of\n * the project\n * - locale - the locale for the output file path\n *\n * @param {string} template the string to escape\n * @param {Object} parameters the parameters to format into the template\n * @returns {string} the formatted file path\n */\nexport function formatPath(template, parameters) {\n const pathname = parameters.sourcepath || \"\";\n const locale = parameters.locale || \"en\";\n const l = new Locale(locale);\n let output = \"\";\n let base;\n\n for (let i = 0; i < template.length; i++) {\n if ( template[i] !== '[' ) {\n output += template[i];\n } else {\n let start = ++i;\n while (i < template.length && template[i] !== ']') {\n i++;\n }\n const keyword = template.substring(start, i);\n switch (keyword) {\n case 'dir':\n output += path.dirname(pathname);\n break;\n case 'filename':\n output += path.basename(pathname);\n break;\n case 'extension':\n base = path.basename(pathname);\n output += base.indexOf('.') > -1 ? base.substring(base.lastIndexOf('.')+1) : \"\";\n break;\n case 'basename':\n base = path.basename(pathname);\n output += base.substring(0, base.lastIndexOf('.'));\n break;\n default:\n case 'locale':\n output += locale;\n break;\n case 'language':\n output += l.getLanguage() || \"\";\n break;\n case 'script':\n output += l.getScript() || \"\";\n break;\n case 'region':\n output += l.getRegion() || \"\";\n break;\n case 'localeDir':\n output += l.getSpec().replace(/-/g, '/');\n break;\n case 'localeUnder':\n output += l.getSpec().replace(/-/g, '_');\n break;\n case 'localeLower':\n output += l.getSpec().toLowerCase();\n break;\n }\n }\n }\n\n return path.normalize(output);\n};\n\nconst matchExprs = {\n \"dir\": {\n regex: \"(.*)\",\n brackets: 1,\n groups: {\n dir: 1\n }\n },\n \"basename\": {\n regex: \"(.*?)\",\n brackets: 1,\n groups: {\n basename: 1\n }\n },\n \"extension\": {\n regex: \"(.*)\",\n brackets: 1,\n groups: {\n extension: 1\n }\n },\n \"locale\": {\n regex: \"(([a-z][a-z][a-z]?)(-([A-Z][a-z][a-z][a-z]))?(-([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n locale: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"language\": {\n regex: \"([a-z][a-z][a-z]?)\",\n brackets: 1,\n groups: {\n language: 1\n }\n },\n \"script\": {\n regex: \"([A-Z][a-z][a-z][a-z])\",\n brackets: 1,\n groups: {\n script: 1\n }\n },\n \"region\": {\n regex: \"([A-Z][A-Z]|[0-9][0-9][0-9])\",\n brackets: 1,\n groups: {\n region: 1\n }\n },\n \"localeDir\": {\n regex: \"(([a-z][a-z][a-z]?)(/([A-Z][a-z][a-z][a-z]))?(/([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeDir: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"localeUnder\": {\n regex: \"(([a-z][a-z][a-z]?)(_([A-Z][a-z][a-z][a-z]))?(_([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeUnder: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"localeLower\": {\n regex: \"(([a-z][a-z][a-z]?)(-([a-z][a-z][a-z][a-z]))?(-([a-z][a-z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeUnder: 1,\n language: 2,\n script: 4,\n region: 6\n }\n }\n};\n\n/**\n * Parse a path according to the given template, and return the parts.\n * The parts can be any of the fields mentioned in the {@link formatPath}\n * documentation. If any field is not parsed, the result is an empty object\n *\n * @param {String} template the ilib template for matching against the path\n * @param {String} pathname the path name to match against the template\n * @returns {Object} an object mapping the fields to their values in the\n * the pathname\n */\nexport function parsePath(template, pathname) {\n let regex = \"\";\n let matchGroups = {};\n let totalBrackets = 0;\n let base;\n\n if (!template) {\n template = defaultMappings[\"**/*.json\"].template;\n }\n\n for (let i = 0; i < template.length; i++) {\n if ( template[i] !== '[' ) {\n regex += template[i];\n } else {\n let start = ++i;\n while (i < template.length && template[i] !== ']') {\n i++;\n }\n const keyword = template.substring(start, i);\n switch (keyword) {\n case 'filename':\n regex += path.basename(pathname);\n break;\n default:\n if (!matchExprs[keyword]) {\n logger.warning(\"Warning: template contains unknown substitution parameter \" + keyword);\n return \"\";\n }\n regex += matchExprs[keyword].regex;\n for (let prop in matchExprs[keyword].groups) {\n matchGroups[prop] = totalBrackets + matchExprs[keyword].groups[prop];\n }\n totalBrackets += matchExprs[keyword].brackets;\n break;\n }\n }\n }\n\n const re = new RegExp(regex, \"u\");\n let match;\n\n if ((match = re.exec(pathname)) !== null) {\n let groups = {};\n let found = false;\n for (let groupName in matchGroups) {\n if (match[matchGroups[groupName]]) {\n groups[groupName] = match[matchGroups[groupName]];\n found = true;\n }\n }\n return groups;\n }\n\n return {};\n}\n\n/**\n * Return a locale encoded in the path using template to parse that path.\n * See {#formatPath} for the full description of the syntax of the template.\n * @param {String} template template for the output file\n * @param {String} pathname path to the source file\n * @returns {String} the locale within the path, or undefined if no locale found\n */\nexport function getLocaleFromPath(template, pathname) {\n const groups = parsePath(template, pathname);\n\n if (groups.locale || groups.language || groups.script || groups.region ) {\n // TODO: Remove script transformation once similar change is implemented in iLib/Locale class.\n if (groups.script && groups.script.length) {\n groups.script = groups.script.charAt(0).toUpperCase() + groups.script.slice(1).toLowerCase();\n }\n\n const l = groups.locale ?\n new Locale(groups.locale) :\n new Locale(groups.language, groups.region, undefined, groups.script);\n\n return l.getSpec();\n }\n\n return \"\";\n};\n\nexport function makeDirs(path) {\n const parts = path.split(/[\\\\\\/]/);\n\n for (let i = 1; i <= parts.length; i++) {\n const p = parts.slice(0, i).join(\"/\");\n if (p && p.length > 0 && !fs.existsSync(p)) {\n fs.mkdirSync(p);\n }\n }\n};\n\n/**\n * Return true if the string still contains some text after removing all HTML tags and entities.\n * @param {string} str the string to check\n * @returns {boolean} true if there is text left over, and false otherwise\n */\nexport function containsActualText(str) {\n // remove the html and entities first\n const cleaned = str.replace(/<(\"(\\\\\"|[^\"])*\"|'(\\\\'|[^'])*'|[^>])*>/g, \"\").replace(/&[a-zA-Z]+;/g, \"\");\n\n for (let i = 0; i < cleaned.length; i++) {\n const c = cleaned.charAt(i);\n if (isAlnum(c) || isIdeo(c)) return true;\n }\n return false;\n};\n\nfunction isPrimitive(type) {\n return [\"boolean\", \"number\", \"integer\", \"string\"].indexOf(type) > -1;\n}\n\n/**\n * Recursively visit every node in an object and call the visitor on any\n * primitive values.\n * @param {*} object any object, arrary, or primitive\n * @param {Function(*)} visitor function to call on any primitive\n * @returns {*} the same type as the original object, but with every\n * primitive processed by the visitor function\n */\nexport function objectMap(object, visitor) {\n if (!object) return object;\n if (isPrimitive(typeof(object))) {\n return visitor(object);\n } else if (Array.isArray(object)) {\n return object.map(item => {\n return objectMap(item, visitor);\n });\n } else {\n const ret = {};\n for (let prop in object) {\n if (object.hasOwnProperty(prop)) {\n ret[prop] = objectMap(object[prop], visitor);\n }\n }\n return ret;\n }\n};\n\n/**\n * Return a standard hash of the given source string.\n *\n * @param {String} source the source string as extracted from the\n * source code, unmodified\n * @returns {String} the hash key\n */\nexport function hashKey(source) {\n if (!source) return undefined;\n let hash = 0;\n // these two numbers together = 46 bits so it won't blow out the precision of an integer in javascript\n const modulus = 1073741789; // largest prime number that fits in 30 bits\n const multiple = 65521; // largest prime that fits in 16 bits, co-prime with the modulus\n\n // logger.trace(\"hash starts off at \" + hash);\n\n for (let i = 0; i < source.length; i++) {\n // logger.trace(\"hash \" + hash + \" char \" + source.charCodeAt(i) + \"=\" + source.charAt(i));\n hash += source.charCodeAt(i);\n hash *= multiple;\n hash %= modulus;\n }\n const value = \"r\" + hash;\n\n // System.out.println(\"String '\" + source + \"' hashes to \" + value);\n\n return value;\n};\n\n/**\n * A hash containing a list of HTML tags that do not\n * cause a break in a resource string. These tags should\n * be included in the middle of the string.\n */\nexport const nonBreakingTags = {\n \"a\": true,\n \"abbr\": true,\n \"b\": true,\n \"bdi\": true,\n \"bdo\": true,\n \"br\": true,\n \"dfn\": true,\n \"del\": true,\n \"em\": true,\n \"i\": true,\n \"ins\": true,\n \"mark\": true,\n \"ruby\": true,\n \"rt\": true,\n \"span\": true,\n \"strong\": true,\n \"sub\": true,\n \"sup\": true,\n \"time\": true,\n \"u\": true,\n \"var\": true,\n \"wbr\": true\n};\n\n/**\n * A hash containing a list of HTML tags that are\n * typically self-closing. That is, in HTML4 and earlier,\n * the close tag was not needed for these.\n */\nexport const selfClosingTags = {\n \"area\": true,\n \"base\": true,\n \"bdi\": true,\n \"bdo\": true,\n \"br\": true,\n \"embed\": true,\n \"hr\": true,\n \"img\": true,\n \"input\": true,\n \"link\": true,\n \"option\": true,\n \"param\": true,\n \"source\": true,\n \"track\": true\n};\n\n/**\n * A hash containing a list of HTML tags where\n * the text content inside of those tags should be\n * ignored for localization purposes. Instead,\n * those contents should just be copied to the\n * localized file unmodified.\n */\nexport const ignoreTags = {\n \"code\": true,\n \"output\": true,\n \"samp\": true,\n \"script\": true,\n \"style\": true\n};\n\n/**\n * List of html5 tags and their attributes that contain localizable strings.\n * The \"*\" indicates it applies to the given attributes on every tag.\n * Also added ARIA attributes to localize for accessibility. For more details,\n * see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/\n */\nexport const localizableAttributes = {\n \"area\": {\"alt\":true},\n \"img\": {\"alt\":true},\n \"input\": {\n \"alt\": true,\n \"placeholder\": true\n },\n \"optgroup\": {\"label\":true},\n \"option\": {\"label\":true},\n \"textarea\": {\"placeholder\":true},\n \"track\": {\"label\":true},\n \"*\": {\n \"title\": true,\n \"aria-braillelabel\": true,\n \"aria-brailleroledescription\": true,\n \"aria-description\": true,\n \"aria-label\": true,\n \"aria-placeholder\": true,\n \"aria-roledescription\": true,\n \"aria-rowindextext\": true,\n \"aria-valuetext\": true\n }\n};\n\n// this is for English and many other languages\nconst defaultPluralCategories = [\n \"one\",\n \"other\"\n];\n\n/**\n * Return the plural categories for the given language.\n * If there is no entry for the given\n * language, then the default English plural categories are returned.\n *\n * @param {string|undefined} language the ISO 639 language code to get the plural\n * categories for\n * @returns {Array} an array of strings containing the names of the plural categories\n */\nexport function getLanguagePluralCategories(language) {\n // make sure to get the language only if someone accidentally sends in a full locale\n const locale = new Locale(language);\n const lang = locale.getLanguage() ?? \"en\";\n return pluralCategories[lang] ?? defaultPluralCategories;\n}\n"],"mappings":"6hBAmBA,IAAAA,GAAA,CAAAC,sBAAA,CAAAC,OAAA,QACA,IAAAC,KAAA,CAAAF,sBAAA,CAAAC,OAAA,UACA,IAAAE,WAAA,CAAAH,sBAAA,CAAAC,OAAA,iBAEA,IAAAG,UAAA,CAAAH,OAAA,eAEA,IAAAI,iBAAA,CAAAL,sBAAA,CAAAC,OAAA,2BAAqD,SAAAD,uBAAAM,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,YAAAA,CAAA,WAAAE,QAAAC,CAAA,mCAAAD,OAAA,oBAAAE,MAAA,mBAAAA,MAAA,CAAAC,QAAA,UAAAF,CAAA,gBAAAA,CAAA,WAAAA,CAAA,SAAAA,CAAA,qBAAAC,MAAA,EAAAD,CAAA,CAAAG,WAAA,GAAAF,MAAA,EAAAD,CAAA,GAAAC,MAAA,CAAAG,SAAA,iBAAAJ,CAAA,EAAAD,OAAA,CAAAC,CAAA,EAzBrD;AACA;AACA;AACA;AACA;AACA;AACA;A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ED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACO,QAAS,CAAAC,2BAA2BA,CAAC1D,QAAQ,CAAE,KAAA2D,mBAAA,CAAAC,qBAAA,CAClD;AACA,GAAM,CAAAtF,MAAM,CAAG,GAAI,CAAAE,sBAAM,CAACwB,QAAQ,CAAC,CACnC,GAAM,CAAA6D,IAAI,EAAAF,mBAAA,CAAGrF,MAAM,CAACe,WAAW,CAAC,CAAC,UAAAsE,mBAAA,UAAAA,mBAAA,CAAI,IAAI,CACzC,OAAAC,qBAAA,CAAOE,4BAAgB,CAACD,IAAI,CAAC,UAAAD,qBAAA,UAAAA,qBAAA,CAAIH,uBACrC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_fs","_interopRequireDefault","require","_path","_ilibLocale","_ilibCtype","_pluralCategories","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","cleanString","str","undefined","toLowerCase","replace","trim","isEmpty","obj","prop","formatLocaleParams","template","locale","l","Locale","localeSpec","getSpec","output","i","length","start","keyword","substring","getLanguage","getScript","getRegion","formatPath","parameters","pathname","sourcepath","resourceDir","base","lastDot","path","dirname","basename","includes","indexOf","lastIndexOf","normalize","matchExprs","regex","brackets","groups","dir","extension","language","script","region","localeDir","localeUnder","parsePath","matchGroups","totalBrackets","defaultMappings","logger","warning","re","RegExp","match","exec","found","groupName","getLocaleFromPath","charAt","toUpperCase","slice","makeDirs","parts","split","p","join","fs","existsSync","mkdirSync","containsActualText","cleaned","c","isAlnum","isIdeo","isPrimitive","type","objectMap","object","visitor","Array","isArray","map","item","ret","hasOwnProperty","hashKey","source","hash","modulus","multiple","charCodeAt","value","nonBreakingTags","exports","selfClosingTags","ignoreTags","localizableAttributes","defaultPluralCategories","getLanguagePluralCategories","_locale$getLanguage","_pluralCategories$lan","lang","pluralCategories"],"sources":["../src/utils.js"],"sourcesContent":["/*\n * utils.js - utility functions to support the other code\n *\n * Copyright © 2022-2023, 2025-2026 JEDLSoft\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport path from 'path';\nimport Locale from 'ilib-locale';\n\nimport { isAlnum, isIdeo } from 'ilib-ctype';\n\nimport pluralCategories from './pluralCategories.js';\n\n/**\n * Clean a string for matching against other strings by removing\n * differences that are inconsequential for translation.\n *\n * @param {String} str string to clean\n * @returns {String} the cleaned string\n */\nexport function cleanString(str) {\n if (typeof(str) !== 'string') {\n return undefined;\n }\n return str.toLowerCase().\n replace(/\\\\n/g, \" \").\n replace(/\\\\t/g, \" \").\n replace(/\\\\/g, \"\").\n replace(/\\s+/g, \" \").\n trim().\n replace(/'/g, \"'\").\n replace(/"/g, '\"').\n replace(/</g, \"<\").\n replace(/>/g, \">\").\n replace(/&/g, \"&\").\n replace(/’/g, \"'\");\n};\n\n/**\n * Is an empty object or not\n * @param {Object} obj object to test\n * @returns {Boolean} true if there are no properties, false otherwise\n */\nexport function isEmpty(obj) {\n let prop = undefined;\n\n if (!obj) {\n return true;\n }\n\n for (prop in obj) {\n if (prop && obj[prop]) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Format a string template with locale-related parameters.\n *\n * This function substitutes locale-related placeholders in a template string\n * without treating the string as a file path (no path normalization).\n * This is useful for formatting headers, footers, or other strings that\n * contain locale placeholders but should not be treated as file paths.\n *\n * This function recognizes and replaces the following strings in\n * templates:\n * - [locale] the full BCP-47 locale specification for the target locale\n * eg. \"zh-Hans-CN\" -> \"zh-Hans-CN\"\n * - [language] the language portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"zh\"\n * - [script] the script portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"Hans\"\n * - [region] the region portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"CN\"\n * - [localeDir] the full locale where each portion of the locale\n * is a directory in this order: [langage], [script], [region].\n * eg, \"zh-Hans-CN\" -> \"zh/Hans/CN\", but \"en\" -> \"en\".\n * - [localeUnder] the full BCP-47 locale specification, but using\n * underscores to separate the locale parts instead of dashes.\n * eg. \"zh-Hans-CN\" -> \"zh_Hans_CN\"\n * - [localeLower] the full BCP-47 locale specification, but makes\n * all locale parts lowercased.\n * eg. \"zh-Hans-CN\" -> \"zh-hans-cn\"\n *\n * Unknown keywords are preserved in the output unchanged.\n *\n * @param {string} template the template string to format\n * @param {string|Object} locale the locale specifier, either as a string\n * or as a Locale object\n * @returns {string} the formatted string with locale placeholders replaced\n */\nexport function formatLocaleParams(template, locale) {\n if (!template) return \"\";\n const l = typeof locale === 'string' ? new Locale(locale || \"en\") : locale;\n const localeSpec = l.getSpec();\n let output = \"\";\n\n for (let i = 0; i < template.length; i++) {\n if (template[i] !== '[') {\n output += template[i];\n } else {\n let start = ++i;\n while (i < template.length && template[i] !== ']') {\n i++;\n }\n const keyword = template.substring(start, i);\n switch (keyword) {\n case 'locale':\n output += localeSpec;\n break;\n case 'language':\n output += l.getLanguage() || \"\";\n break;\n case 'script':\n output += l.getScript() || \"\";\n break;\n case 'region':\n output += l.getRegion() || \"\";\n break;\n case 'localeDir':\n output += localeSpec.replace(/-/g, '/');\n break;\n case 'localeUnder':\n output += localeSpec.replace(/-/g, '_');\n break;\n case 'localeLower':\n output += localeSpec.toLowerCase();\n break;\n default:\n // unknown keyword, preserve it unchanged\n output += '[' + keyword + ']';\n break;\n }\n }\n }\n return output;\n}\n\n/**\n * Format a file path using a path template and parameters.\n *\n * This function is used to generate an output file path for a given\n * source file path and a locale specifier.\n * The template replaces strings in square brackets with special values,\n * and keeps any characters intact that are not in square brackets.\n * This function recognizes and replaces the following strings in\n * templates:\n * - [dir] the original directory where the source file\n * came from. This is given as a directory that is relative\n * to the root of the project. eg. \"foo/bar/strings.json\" -> \"foo/bar\"\n * - [filename] the file name of the source file.\n * eg. \"foo/bar/strings.json\" -> \"strings.json\"\n * - [basename] the basename of the source file without any extension\n * eg. \"foo/bar/strings.json\" -> \"strings\"\n * - [extension] the extension part of the file name of the source file.\n * etc. \"foo/bar/strings.json\" -> \"json\"\n * - [locale] the full BCP-47 locale specification for the target locale\n * eg. \"zh-Hans-CN\" -> \"zh-Hans-CN\"\n * - [language] the language portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"zh\"\n * - [script] the script portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"Hans\"\n * - [region] the region portion of the full locale\n * eg. \"zh-Hans-CN\" -> \"CN\"\n * - [localeDir] the full locale where each portion of the locale\n * is a directory in this order: [langage], [script], [region].\n * eg, \"zh-Hans-CN\" -> \"zh/Hans/CN\", but \"en\" -> \"en\".\n * - [localeUnder] the full BCP-47 locale specification, but using\n * underscores to separate the locale parts instead of dashes.\n * eg. \"zh-Hans-CN\" -> \"zh_Hans_CN\"\n * - [localeLower] the full BCP-47 locale specification, but makes\n * all locale parts lowercased.\n * eg. \"zh-Hans-CN\" -> \"zh-hans-cn\"\n *\n * @param {string} template the path template string\n * @param {Object} parameters an object containing:\n * @param {string} parameters.sourcepath the path to the source file, relative to the\n * root of the project\n * @param {string} parameters.locale the locale for the output file path\n * @param {string} parameters.resourceDir optional resource directory to substitute\n * for [resourceDir] in the template\n * @returns {string} the formatted file path\n */\nexport function formatPath(template, parameters) {\n const pathname = parameters.sourcepath || \"\";\n const locale = parameters.locale || \"en\";\n const resourceDir = parameters.resourceDir || \".\";\n\n // First, handle locale-related substitutions without path normalization\n let output = formatLocaleParams(template, locale);\n\n // Now handle path-specific keywords\n let base;\n let lastDot;\n\n output = output.replace(/\\[dir\\]/g, path.dirname(pathname));\n output = output.replace(/\\[filename\\]/g, path.basename(pathname));\n output = output.replace(/\\[resourceDir\\]/g, resourceDir);\n\n if (output.includes('[extension]')) {\n base = path.basename(pathname);\n output = output.replace(/\\[extension\\]/g, base.indexOf('.') > -1 ? base.substring(base.lastIndexOf('.')+1) : \"\");\n }\n\n if (output.includes('[basename]')) {\n base = path.basename(pathname);\n lastDot = base.lastIndexOf('.');\n output = output.replace(/\\[basename\\]/g, lastDot > -1 ? base.substring(0, lastDot) : base);\n }\n\n return path.normalize(output);\n};\n\nconst matchExprs = {\n \"dir\": {\n regex: \"(.*)\",\n brackets: 1,\n groups: {\n dir: 1\n }\n },\n \"basename\": {\n regex: \"(.*?)\",\n brackets: 1,\n groups: {\n basename: 1\n }\n },\n \"extension\": {\n regex: \"(.*)\",\n brackets: 1,\n groups: {\n extension: 1\n }\n },\n \"locale\": {\n regex: \"(([a-z][a-z][a-z]?)(-([A-Z][a-z][a-z][a-z]))?(-([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n locale: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"language\": {\n regex: \"([a-z][a-z][a-z]?)\",\n brackets: 1,\n groups: {\n language: 1\n }\n },\n \"script\": {\n regex: \"([A-Z][a-z][a-z][a-z])\",\n brackets: 1,\n groups: {\n script: 1\n }\n },\n \"region\": {\n regex: \"([A-Z][A-Z]|[0-9][0-9][0-9])\",\n brackets: 1,\n groups: {\n region: 1\n }\n },\n \"localeDir\": {\n regex: \"(([a-z][a-z][a-z]?)(/([A-Z][a-z][a-z][a-z]))?(/([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeDir: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"localeUnder\": {\n regex: \"(([a-z][a-z][a-z]?)(_([A-Z][a-z][a-z][a-z]))?(_([A-Z][A-Z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeUnder: 1,\n language: 2,\n script: 4,\n region: 6\n }\n },\n \"localeLower\": {\n regex: \"(([a-z][a-z][a-z]?)(-([a-z][a-z][a-z][a-z]))?(-([a-z][a-z]|[0-9][0-9][0-9]))?)\",\n brackets: 6,\n groups: {\n localeUnder: 1,\n language: 2,\n script: 4,\n region: 6\n }\n }\n};\n\n/**\n * Parse a path according to the given template, and return the parts.\n * The parts can be any of the fields mentioned in the {@link formatPath}\n * documentation. If any field is not parsed, the result is an empty object\n *\n * @param {String} template the ilib template for matching against the path\n * @param {String} pathname the path name to match against the template\n * @returns {Object} an object mapping the fields to their values in the\n * the pathname\n */\nexport function parsePath(template, pathname) {\n let regex = \"\";\n let matchGroups = {};\n let totalBrackets = 0;\n let base;\n\n if (!template) {\n template = defaultMappings[\"**/*.json\"].template;\n }\n\n for (let i = 0; i < template.length; i++) {\n if ( template[i] !== '[' ) {\n regex += template[i];\n } else {\n let start = ++i;\n while (i < template.length && template[i] !== ']') {\n i++;\n }\n const keyword = template.substring(start, i);\n switch (keyword) {\n case 'filename':\n regex += path.basename(pathname);\n break;\n default:\n if (!matchExprs[keyword]) {\n logger.warning(\"Warning: template contains unknown substitution parameter \" + keyword);\n return \"\";\n }\n regex += matchExprs[keyword].regex;\n for (let prop in matchExprs[keyword].groups) {\n matchGroups[prop] = totalBrackets + matchExprs[keyword].groups[prop];\n }\n totalBrackets += matchExprs[keyword].brackets;\n break;\n }\n }\n }\n\n const re = new RegExp(regex, \"u\");\n let match;\n\n if ((match = re.exec(pathname)) !== null) {\n let groups = {};\n let found = false;\n for (let groupName in matchGroups) {\n if (match[matchGroups[groupName]]) {\n groups[groupName] = match[matchGroups[groupName]];\n found = true;\n }\n }\n return groups;\n }\n\n return {};\n}\n\n/**\n * Return a locale encoded in the path using template to parse that path.\n * See {#formatPath} for the full description of the syntax of the template.\n * @param {String} template template for the output file\n * @param {String} pathname path to the source file\n * @returns {String} the locale within the path, or undefined if no locale found\n */\nexport function getLocaleFromPath(template, pathname) {\n const groups = parsePath(template, pathname);\n\n if (groups.locale || groups.language || groups.script || groups.region ) {\n // TODO: Remove script transformation once similar change is implemented in iLib/Locale class.\n if (groups.script && groups.script.length) {\n groups.script = groups.script.charAt(0).toUpperCase() + groups.script.slice(1).toLowerCase();\n }\n\n const l = groups.locale ?\n new Locale(groups.locale) :\n new Locale(groups.language, groups.region, undefined, groups.script);\n\n return l.getSpec();\n }\n\n return \"\";\n};\n\nexport function makeDirs(path) {\n const parts = path.split(/[\\\\\\/]/);\n\n for (let i = 1; i <= parts.length; i++) {\n const p = parts.slice(0, i).join(\"/\");\n if (p && p.length > 0 && !fs.existsSync(p)) {\n fs.mkdirSync(p);\n }\n }\n};\n\n/**\n * Return true if the string still contains some text after removing all HTML tags and entities.\n * @param {string} str the string to check\n * @returns {boolean} true if there is text left over, and false otherwise\n */\nexport function containsActualText(str) {\n // remove the html and entities first\n const cleaned = str.replace(/<(\"(\\\\\"|[^\"])*\"|'(\\\\'|[^'])*'|[^>])*>/g, \"\").replace(/&[a-zA-Z]+;/g, \"\");\n\n for (let i = 0; i < cleaned.length; i++) {\n const c = cleaned.charAt(i);\n if (isAlnum(c) || isIdeo(c)) return true;\n }\n return false;\n};\n\nfunction isPrimitive(type) {\n return [\"boolean\", \"number\", \"integer\", \"string\"].indexOf(type) > -1;\n}\n\n/**\n * Recursively visit every node in an object and call the visitor on any\n * primitive values.\n * @param {*} object any object, arrary, or primitive\n * @param {Function(*)} visitor function to call on any primitive\n * @returns {*} the same type as the original object, but with every\n * primitive processed by the visitor function\n */\nexport function objectMap(object, visitor) {\n if (!object) return object;\n if (isPrimitive(typeof(object))) {\n return visitor(object);\n } else if (Array.isArray(object)) {\n return object.map(item => {\n return objectMap(item, visitor);\n });\n } else {\n const ret = {};\n for (let prop in object) {\n if (object.hasOwnProperty(prop)) {\n ret[prop] = objectMap(object[prop], visitor);\n }\n }\n return ret;\n }\n};\n\n/**\n * Return a standard hash of the given source string.\n *\n * @param {String} source the source string as extracted from the\n * source code, unmodified\n * @returns {String} the hash key\n */\nexport function hashKey(source) {\n if (!source) return undefined;\n let hash = 0;\n // these two numbers together = 46 bits so it won't blow out the precision of an integer in javascript\n const modulus = 1073741789; // largest prime number that fits in 30 bits\n const multiple = 65521; // largest prime that fits in 16 bits, co-prime with the modulus\n\n // logger.trace(\"hash starts off at \" + hash);\n\n for (let i = 0; i < source.length; i++) {\n // logger.trace(\"hash \" + hash + \" char \" + source.charCodeAt(i) + \"=\" + source.charAt(i));\n hash += source.charCodeAt(i);\n hash *= multiple;\n hash %= modulus;\n }\n const value = \"r\" + hash;\n\n // System.out.println(\"String '\" + source + \"' hashes to \" + value);\n\n return value;\n};\n\n/**\n * A hash containing a list of HTML tags that do not\n * cause a break in a resource string. These tags should\n * be included in the middle of the string.\n */\nexport const nonBreakingTags = {\n \"a\": true,\n \"abbr\": true,\n \"b\": true,\n \"bdi\": true,\n \"bdo\": true,\n \"br\": true,\n \"dfn\": true,\n \"del\": true,\n \"em\": true,\n \"i\": true,\n \"ins\": true,\n \"mark\": true,\n \"ruby\": true,\n \"rt\": true,\n \"span\": true,\n \"strong\": true,\n \"sub\": true,\n \"sup\": true,\n \"time\": true,\n \"u\": true,\n \"var\": true,\n \"wbr\": true\n};\n\n/**\n * A hash containing a list of HTML tags that are\n * typically self-closing. That is, in HTML4 and earlier,\n * the close tag was not needed for these.\n */\nexport const selfClosingTags = {\n \"area\": true,\n \"base\": true,\n \"bdi\": true,\n \"bdo\": true,\n \"br\": true,\n \"embed\": true,\n \"hr\": true,\n \"img\": true,\n \"input\": true,\n \"link\": true,\n \"option\": true,\n \"param\": true,\n \"source\": true,\n \"track\": true\n};\n\n/**\n * A hash containing a list of HTML tags where\n * the text content inside of those tags should be\n * ignored for localization purposes. Instead,\n * those contents should just be copied to the\n * localized file unmodified.\n */\nexport const ignoreTags = {\n \"code\": true,\n \"output\": true,\n \"samp\": true,\n \"script\": true,\n \"style\": true\n};\n\n/**\n * List of html5 tags and their attributes that contain localizable strings.\n * The \"*\" indicates it applies to the given attributes on every tag.\n * Also added ARIA attributes to localize for accessibility. For more details,\n * see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/\n */\nexport const localizableAttributes = {\n \"area\": {\"alt\":true},\n \"img\": {\"alt\":true},\n \"input\": {\n \"alt\": true,\n \"placeholder\": true\n },\n \"optgroup\": {\"label\":true},\n \"option\": {\"label\":true},\n \"textarea\": {\"placeholder\":true},\n \"track\": {\"label\":true},\n \"*\": {\n \"title\": true,\n \"aria-braillelabel\": true,\n \"aria-brailleroledescription\": true,\n \"aria-description\": true,\n \"aria-label\": true,\n \"aria-placeholder\": true,\n \"aria-roledescription\": true,\n \"aria-rowindextext\": true,\n \"aria-valuetext\": true\n }\n};\n\n// this is for English and many other languages\nconst defaultPluralCategories = [\n \"one\",\n \"other\"\n];\n\n/**\n * Return the plural categories for the given language.\n * If there is no entry for the given\n * language, then the default English plural categories are returned.\n *\n * @param {string|undefined} language the ISO 639 language code to get the plural\n * categories for\n * @returns {Array} an array of strings containing the names of the plural categories\n */\nexport function getLanguagePluralCategories(language) {\n // make sure to get the language only if someone accidentally sends in a full locale\n const locale = new Locale(language);\n const lang = locale.getLanguage() ?? \"en\";\n return pluralCategories[lang] ?? defaultPluralCategories;\n}\n"],"mappings":"2kBAmBA,IAAAA,GAAA,CAAAC,sBAAA,CAAAC,OAAA,QACA,IAAAC,KAAA,CAAAF,sBAAA,CAAAC,OAAA,UACA,IAAAE,WAAA,CAAAH,sBAAA,CAAAC,OAAA,iBAEA,IAAAG,UAAA,CAAAH,OAAA,eAEA,IAAAI,iBAAA,CAAAL,sBAAA,CAAAC,OAAA,2BAAqD,SAAAD,uBAAAM,CAAA,SAAAA,CAAA,EAAAA,CAAA,CAAAC,UAAA,CAAAD,CAAA,YAAAA,CAAA,WAAAE,QAAAC,CAAA,mCAAAD,OAAA,oBAAAE,MAAA,mBAAAA,MAAA,CAAAC,QAAA,UAAAF,CAAA,gBAAAA,CAAA,WAAAA,CAAA,SAAAA,CAAA,qBAAAC,MAAA,EAAAD,CAAA,CAAAG,WAAA,GAAAF,MAAA,EAAAD,CAAA,GAAAC,MAAA,CAAAG,SAAA,iBAAAJ,CAAA,EAAAD,OAA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A6D,IAAI,EAAAF,mBAAA,CAAG7F,MAAM,CAACW,WAAW,CAAC,CAAC,UAAAkF,mBAAA,UAAAA,mBAAA,CAAI,IAAI,CACzC,OAAAC,qBAAA,CAAOE,4BAAgB,CAACD,IAAI,CAAC,UAAAD,qBAAA,UAAAA,qBAAA,CAAIH,uBACrC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilib-tools-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|
|
50
|
-
"url": "https://github.com/iLib-js/ilib-mono
|
|
50
|
+
"url": "https://github.com/iLib-js/ilib-mono"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=12 <23"
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@log4js-node/log4js-api": "^1.0.2",
|
|
81
|
-
"ilib-xliff-webos": "^1.0.
|
|
81
|
+
"ilib-xliff-webos": "^1.0.5",
|
|
82
82
|
"intl-messageformat": "^10.7.11",
|
|
83
83
|
"micromatch": "^4.0.8",
|
|
84
84
|
"ilib-ctype": "^1.3.0",
|
|
85
85
|
"ilib-istring": "^1.1.1",
|
|
86
|
-
"ilib-locale": "^1.
|
|
86
|
+
"ilib-locale": "^1.3.0",
|
|
87
87
|
"ilib-xliff": "^1.4.1"
|
|
88
88
|
},
|
|
89
89
|
"scripts": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"build:dev": "grunt babel --mode=dev && pnpm build:pkg",
|
|
93
93
|
"build:pkg": "echo '{\"type\": \"commonjs\"}' > lib/package.json",
|
|
94
94
|
"build:data": "node --experimental-vm-modules ./scripts/genPluralCategories.mjs",
|
|
95
|
-
"coverage": "pnpm test --
|
|
95
|
+
"coverage": "pnpm test --coverage",
|
|
96
96
|
"test": "LANG=en_US.UTF8 node --experimental-vm-modules node_modules/jest/bin/jest.js --testEnvironment node",
|
|
97
97
|
"test:watch": "pnpm test:jest --watch",
|
|
98
98
|
"debug": "LANG=en_US.UTF8 node --experimental-vm-modules --inspect-brk node_modules/jest/bin/jest.js -i --testEnvironment node",
|
package/src/ResourceXliff.js
CHANGED
|
@@ -135,7 +135,8 @@ class ResourceXliff {
|
|
|
135
135
|
datatype: res.datatype,
|
|
136
136
|
flavor: res.getFlavor ? res.getFlavor() : undefined,
|
|
137
137
|
translate: !res.getDNT(),
|
|
138
|
-
location: res.getLocation()
|
|
138
|
+
location: res.getLocation(),
|
|
139
|
+
metadata: res.metadata
|
|
139
140
|
});
|
|
140
141
|
units.push(tu);
|
|
141
142
|
break;
|
|
@@ -260,7 +261,8 @@ class ResourceXliff {
|
|
|
260
261
|
state: tu.state,
|
|
261
262
|
flavor: tu.flavor,
|
|
262
263
|
location: new Location(tu.location),
|
|
263
|
-
resfile: tu.resfile
|
|
264
|
+
resfile: tu.resfile,
|
|
265
|
+
metadata: tu.metadata
|
|
264
266
|
});
|
|
265
267
|
|
|
266
268
|
if (tu.target) {
|
package/src/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import {convertPluralResToICU, convertICUToPluralRes} from './ResourceConvert.js
|
|
|
31
31
|
import escaperFactory from './EscaperFactory.js';
|
|
32
32
|
|
|
33
33
|
import {
|
|
34
|
+
formatLocaleParams,
|
|
34
35
|
formatPath,
|
|
35
36
|
parsePath,
|
|
36
37
|
getLocaleFromPath,
|
|
@@ -58,6 +59,7 @@ export {
|
|
|
58
59
|
TranslationUnit,
|
|
59
60
|
TranslationVariant,
|
|
60
61
|
ResourceXliff,
|
|
62
|
+
formatLocaleParams,
|
|
61
63
|
formatPath,
|
|
62
64
|
parsePath,
|
|
63
65
|
getLocaleFromPath,
|
package/src/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* utils.js - utility functions to support the other code
|
|
3
3
|
*
|
|
4
|
-
* Copyright © 2022-2023, 2025 JEDLSoft
|
|
4
|
+
* Copyright © 2022-2023, 2025-2026 JEDLSoft
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -71,23 +71,15 @@ export function isEmpty(obj) {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Format a
|
|
74
|
+
* Format a string template with locale-related parameters.
|
|
75
|
+
*
|
|
76
|
+
* This function substitutes locale-related placeholders in a template string
|
|
77
|
+
* without treating the string as a file path (no path normalization).
|
|
78
|
+
* This is useful for formatting headers, footers, or other strings that
|
|
79
|
+
* contain locale placeholders but should not be treated as file paths.
|
|
75
80
|
*
|
|
76
|
-
* This function is used to generate an output file path for a given
|
|
77
|
-
* source file path and a locale specifier.
|
|
78
|
-
* The template replaces strings in square brackets with special values,
|
|
79
|
-
* and keeps any characters intact that are not in square brackets.
|
|
80
81
|
* This function recognizes and replaces the following strings in
|
|
81
82
|
* templates:
|
|
82
|
-
* - [dir] the original directory where the source file
|
|
83
|
-
* came from. This is given as a directory that is relative
|
|
84
|
-
* to the root of the project. eg. "foo/bar/strings.json" -> "foo/bar"
|
|
85
|
-
* - [filename] the file name of the source file.
|
|
86
|
-
* eg. "foo/bar/strings.json" -> "strings.json"
|
|
87
|
-
* - [basename] the basename of the source file without any extension
|
|
88
|
-
* eg. "foo/bar/strings.json" -> "strings"
|
|
89
|
-
* - [extension] the extension part of the file name of the source file.
|
|
90
|
-
* etc. "foo/bar/strings.json" -> "json"
|
|
91
83
|
* - [locale] the full BCP-47 locale specification for the target locale
|
|
92
84
|
* eg. "zh-Hans-CN" -> "zh-Hans-CN"
|
|
93
85
|
* - [language] the language portion of the full locale
|
|
@@ -106,24 +98,21 @@ export function isEmpty(obj) {
|
|
|
106
98
|
* all locale parts lowercased.
|
|
107
99
|
* eg. "zh-Hans-CN" -> "zh-hans-cn"
|
|
108
100
|
*
|
|
109
|
-
*
|
|
110
|
-
* - sourcepath - the path to the source file, relative to the root of
|
|
111
|
-
* the project
|
|
112
|
-
* - locale - the locale for the output file path
|
|
101
|
+
* Unknown keywords are preserved in the output unchanged.
|
|
113
102
|
*
|
|
114
|
-
* @param {string} template the string to
|
|
115
|
-
* @param {Object}
|
|
116
|
-
*
|
|
103
|
+
* @param {string} template the template string to format
|
|
104
|
+
* @param {string|Object} locale the locale specifier, either as a string
|
|
105
|
+
* or as a Locale object
|
|
106
|
+
* @returns {string} the formatted string with locale placeholders replaced
|
|
117
107
|
*/
|
|
118
|
-
export function
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
108
|
+
export function formatLocaleParams(template, locale) {
|
|
109
|
+
if (!template) return "";
|
|
110
|
+
const l = typeof locale === 'string' ? new Locale(locale || "en") : locale;
|
|
111
|
+
const localeSpec = l.getSpec();
|
|
122
112
|
let output = "";
|
|
123
|
-
let base;
|
|
124
113
|
|
|
125
114
|
for (let i = 0; i < template.length; i++) {
|
|
126
|
-
if (
|
|
115
|
+
if (template[i] !== '[') {
|
|
127
116
|
output += template[i];
|
|
128
117
|
} else {
|
|
129
118
|
let start = ++i;
|
|
@@ -132,23 +121,8 @@ export function formatPath(template, parameters) {
|
|
|
132
121
|
}
|
|
133
122
|
const keyword = template.substring(start, i);
|
|
134
123
|
switch (keyword) {
|
|
135
|
-
case 'dir':
|
|
136
|
-
output += path.dirname(pathname);
|
|
137
|
-
break;
|
|
138
|
-
case 'filename':
|
|
139
|
-
output += path.basename(pathname);
|
|
140
|
-
break;
|
|
141
|
-
case 'extension':
|
|
142
|
-
base = path.basename(pathname);
|
|
143
|
-
output += base.indexOf('.') > -1 ? base.substring(base.lastIndexOf('.')+1) : "";
|
|
144
|
-
break;
|
|
145
|
-
case 'basename':
|
|
146
|
-
base = path.basename(pathname);
|
|
147
|
-
output += base.substring(0, base.lastIndexOf('.'));
|
|
148
|
-
break;
|
|
149
|
-
default:
|
|
150
124
|
case 'locale':
|
|
151
|
-
output +=
|
|
125
|
+
output += localeSpec;
|
|
152
126
|
break;
|
|
153
127
|
case 'language':
|
|
154
128
|
output += l.getLanguage() || "";
|
|
@@ -160,17 +134,95 @@ export function formatPath(template, parameters) {
|
|
|
160
134
|
output += l.getRegion() || "";
|
|
161
135
|
break;
|
|
162
136
|
case 'localeDir':
|
|
163
|
-
output +=
|
|
137
|
+
output += localeSpec.replace(/-/g, '/');
|
|
164
138
|
break;
|
|
165
139
|
case 'localeUnder':
|
|
166
|
-
output +=
|
|
140
|
+
output += localeSpec.replace(/-/g, '_');
|
|
167
141
|
break;
|
|
168
142
|
case 'localeLower':
|
|
169
|
-
output +=
|
|
143
|
+
output += localeSpec.toLowerCase();
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
// unknown keyword, preserve it unchanged
|
|
147
|
+
output += '[' + keyword + ']';
|
|
170
148
|
break;
|
|
171
149
|
}
|
|
172
150
|
}
|
|
173
151
|
}
|
|
152
|
+
return output;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Format a file path using a path template and parameters.
|
|
157
|
+
*
|
|
158
|
+
* This function is used to generate an output file path for a given
|
|
159
|
+
* source file path and a locale specifier.
|
|
160
|
+
* The template replaces strings in square brackets with special values,
|
|
161
|
+
* and keeps any characters intact that are not in square brackets.
|
|
162
|
+
* This function recognizes and replaces the following strings in
|
|
163
|
+
* templates:
|
|
164
|
+
* - [dir] the original directory where the source file
|
|
165
|
+
* came from. This is given as a directory that is relative
|
|
166
|
+
* to the root of the project. eg. "foo/bar/strings.json" -> "foo/bar"
|
|
167
|
+
* - [filename] the file name of the source file.
|
|
168
|
+
* eg. "foo/bar/strings.json" -> "strings.json"
|
|
169
|
+
* - [basename] the basename of the source file without any extension
|
|
170
|
+
* eg. "foo/bar/strings.json" -> "strings"
|
|
171
|
+
* - [extension] the extension part of the file name of the source file.
|
|
172
|
+
* etc. "foo/bar/strings.json" -> "json"
|
|
173
|
+
* - [locale] the full BCP-47 locale specification for the target locale
|
|
174
|
+
* eg. "zh-Hans-CN" -> "zh-Hans-CN"
|
|
175
|
+
* - [language] the language portion of the full locale
|
|
176
|
+
* eg. "zh-Hans-CN" -> "zh"
|
|
177
|
+
* - [script] the script portion of the full locale
|
|
178
|
+
* eg. "zh-Hans-CN" -> "Hans"
|
|
179
|
+
* - [region] the region portion of the full locale
|
|
180
|
+
* eg. "zh-Hans-CN" -> "CN"
|
|
181
|
+
* - [localeDir] the full locale where each portion of the locale
|
|
182
|
+
* is a directory in this order: [langage], [script], [region].
|
|
183
|
+
* eg, "zh-Hans-CN" -> "zh/Hans/CN", but "en" -> "en".
|
|
184
|
+
* - [localeUnder] the full BCP-47 locale specification, but using
|
|
185
|
+
* underscores to separate the locale parts instead of dashes.
|
|
186
|
+
* eg. "zh-Hans-CN" -> "zh_Hans_CN"
|
|
187
|
+
* - [localeLower] the full BCP-47 locale specification, but makes
|
|
188
|
+
* all locale parts lowercased.
|
|
189
|
+
* eg. "zh-Hans-CN" -> "zh-hans-cn"
|
|
190
|
+
*
|
|
191
|
+
* @param {string} template the path template string
|
|
192
|
+
* @param {Object} parameters an object containing:
|
|
193
|
+
* @param {string} parameters.sourcepath the path to the source file, relative to the
|
|
194
|
+
* root of the project
|
|
195
|
+
* @param {string} parameters.locale the locale for the output file path
|
|
196
|
+
* @param {string} parameters.resourceDir optional resource directory to substitute
|
|
197
|
+
* for [resourceDir] in the template
|
|
198
|
+
* @returns {string} the formatted file path
|
|
199
|
+
*/
|
|
200
|
+
export function formatPath(template, parameters) {
|
|
201
|
+
const pathname = parameters.sourcepath || "";
|
|
202
|
+
const locale = parameters.locale || "en";
|
|
203
|
+
const resourceDir = parameters.resourceDir || ".";
|
|
204
|
+
|
|
205
|
+
// First, handle locale-related substitutions without path normalization
|
|
206
|
+
let output = formatLocaleParams(template, locale);
|
|
207
|
+
|
|
208
|
+
// Now handle path-specific keywords
|
|
209
|
+
let base;
|
|
210
|
+
let lastDot;
|
|
211
|
+
|
|
212
|
+
output = output.replace(/\[dir\]/g, path.dirname(pathname));
|
|
213
|
+
output = output.replace(/\[filename\]/g, path.basename(pathname));
|
|
214
|
+
output = output.replace(/\[resourceDir\]/g, resourceDir);
|
|
215
|
+
|
|
216
|
+
if (output.includes('[extension]')) {
|
|
217
|
+
base = path.basename(pathname);
|
|
218
|
+
output = output.replace(/\[extension\]/g, base.indexOf('.') > -1 ? base.substring(base.lastIndexOf('.')+1) : "");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (output.includes('[basename]')) {
|
|
222
|
+
base = path.basename(pathname);
|
|
223
|
+
lastDot = base.lastIndexOf('.');
|
|
224
|
+
output = output.replace(/\[basename\]/g, lastDot > -1 ? base.substring(0, lastDot) : base);
|
|
225
|
+
}
|
|
174
226
|
|
|
175
227
|
return path.normalize(output);
|
|
176
228
|
};
|