ilib-tools-common 1.20.1 → 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/Resource.js +39 -4
- package/lib/Resource.js.map +1 -1
- package/lib/ResourceXliff.js +3 -3
- 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 +6 -6
- package/src/index.js +2 -0
- package/src/utils.js +99 -47
package/lib/Resource.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;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)}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}/*
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=exports.VALID_STATES=void 0;exports.isValidState=isValidState;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)}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}/*
|
|
2
2
|
* Resource.js - super class that represents a resource
|
|
3
3
|
*
|
|
4
4
|
* Copyright © 2022-2025 JEDLSoft
|
|
@@ -15,7 +15,41 @@
|
|
|
15
15
|
*
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
|
-
*/var validStates={
|
|
18
|
+
*/var validStates={// XLIFF 2.0 standard states
|
|
19
|
+
// https://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html
|
|
20
|
+
"initial":true,"translated":true,"reviewed":true,"final":true,// XLIFF 1.2 standard states
|
|
21
|
+
// from https://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
|
|
22
|
+
"new":true,"needs-translation":true,"needs-adaptation":true,"needs-l10n":true,"needs-review-translation":true,"needs-review-adaptation":true,"needs-review-l10n":true,"signed-off":true,// Additional common states used in practice
|
|
23
|
+
"needs-review":true,"fuzzy":true,"accepted":true,"rejected":true,"approved":true,"needs-approval":true};/**
|
|
24
|
+
* Array of all valid state names that can be used with Resource objects.
|
|
25
|
+
* This array is sorted alphabetically and includes states from:
|
|
26
|
+
* - XLIFF 2.0 standard states
|
|
27
|
+
* - XLIFF 1.2 standard states
|
|
28
|
+
* - Additional common states used in practice
|
|
29
|
+
*
|
|
30
|
+
* Custom states with "x-" prefix are also valid but not included in this array.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Check if a state is valid
|
|
34
|
+
* if (VALID_STATES.includes(state)) {
|
|
35
|
+
* console.log('Valid state');
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* @type {string[]}
|
|
39
|
+
* @since 1.19.0
|
|
40
|
+
*/var VALID_STATES=exports.VALID_STATES=Object.keys(validStates).sort();/**
|
|
41
|
+
* Check if a state is valid according to XLIFF 1.2 or 2.0 specification
|
|
42
|
+
* or if the state is used with ilib projects.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} state the state to validate
|
|
45
|
+
* @returns {boolean} true if the state is valid, false otherwise
|
|
46
|
+
* @since 1.19.0
|
|
47
|
+
*/function isValidState(state){// Must be a string
|
|
48
|
+
if(typeof state!=="string"){return false}// Empty string is invalid
|
|
49
|
+
if(state.length===0){return false}// Check predefined states first
|
|
50
|
+
if(validStates[state]){return true}// Custom states must start with "x-" and have content after the hyphen
|
|
51
|
+
if(state.startsWith("x-")){// Must have non-whitespace content after "x-"
|
|
52
|
+
var contentAfterX=state.substring(2);if(contentAfterX.trim().length>0){return true}}return false}var translationImportant=["context","datatype","dnt","flavor","project","reskey","resType","sourceLocale","targetLocale"];/**
|
|
19
53
|
* @class Represents a resource from a resource file or
|
|
20
54
|
* extracted from the code.
|
|
21
55
|
* @abstract
|
|
@@ -153,7 +187,8 @@ this.metadata=props.metadata||undefined}this.instances=[];this.pathName=this.pat
|
|
|
153
187
|
* "translated", or "accepted".
|
|
154
188
|
*
|
|
155
189
|
* @param {string} state the state of this resource
|
|
156
|
-
|
|
190
|
+
* @throws {Error} if the state is invalid
|
|
191
|
+
*/},{key:"setState",value:function setState(state){if(!isValidState(state)){throw new Error("Attempt to set an invalid state on a resource: \"".concat(state,"\". Valid states are: ").concat(VALID_STATES.join(", "),", or custom states starting with \"x-\""))}this.state=state;this.dirty=true}/**
|
|
157
192
|
* Return the original path to the file from which this resource was
|
|
158
193
|
* originally extracted.
|
|
159
194
|
*
|
|
@@ -304,5 +339,5 @@ return"'"+str.replace(/\\'/g,"'").replace(/'/g,"\\'")+"'";case"undefined":return
|
|
|
304
339
|
*
|
|
305
340
|
* @abstract
|
|
306
341
|
* @returns {string} a unique hash key for this resource with a cleaned string
|
|
307
|
-
*/},{key:"cleanHashKey",value:function cleanHashKey(){throw new Error("cleanHashKey() not implemented")}}])}();var _default=exports["default"]=Resource;
|
|
342
|
+
*/},{key:"cleanHashKey",value:function cleanHashKey(){throw new Error("cleanHashKey() not implemented")}}])}();var _default=exports["default"]=Resource;
|
|
308
343
|
//# sourceMappingURL=Resource.js.map
|
package/lib/Resource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resource.js","names":["validStates","translationImportant","Resource","props","_classCallCheck","_defineProperty","constructor","Error","autoKey","project","context","undefined","sourceLocale","locale","targetLocale","reskey","key","pathName","state","id","formatted","comment","origin","dnt","datatype","sourceHash","localize","flavor","index","location","resfile","metadata","instances","dirty","_createClass","value","getProject","getKey","getSource","source","getTarget","target","getType","resType","getDataType","getAutoKey","getContext","getMetadata","setMetadata","data","getSourceLocale","setSourceLocale","getTargetLocale","setTargetLocale","getState","setProject","setState","getPath","getComment","setComment","getDNT","setDNT","flag","TypeError","getId","getOrigin","getLocalize","getFlavor","getResFile","same","other","i","length","escapeText","str","_typeof","replace","toString","addInstance","resource","isInstance","unique","every","res","push","_this","prop","getInstances","isDirty","clearDirty","getLocation","_this$location","hashKey","cleanHashKey","_default","exports","module","default"],"sources":["../src/Resource.js"],"sourcesContent":["/*\n * Resource.js - super class that represents a resource\n *\n * Copyright © 2022-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\nconst validStates = {\n \"new\":true,\n \"translated\":true,\n \"accepted\":true\n}\n\nconst translationImportant = [\n \"context\",\n \"datatype\",\n \"dnt\",\n \"flavor\",\n \"project\",\n \"reskey\",\n \"resType\",\n \"sourceLocale\",\n \"targetLocale\"\n];\n\n\n/**\n * @class Represents a resource from a resource file or\n * extracted from the code.\n * @abstract\n */\nclass Resource {\n /**\n * The type of this resource instance.\n * @type {String | undefined}\n */\n resType;\n\n /**\n * The source string or strings for the resource.\n * @type {String|Array.<String>|Object}\n */\n source;\n\n /**\n * The target string or strings for the resource.\n * @type {String|Array.<String>|Object}\n */\n target;\n\n /**\n * The resource file that this resource was loaded from.\n * @type {string|undefined}\n */\n resfile;\n\n /**\n * Construct a new Resource instance.\n * The props may contain any\n * of the following properties:\n *\n * <ul>\n * </ul>\n *\n * @constructor\n * @param {Object} props properties of the string, as defined above\n * @param {string} [props.project] the project that this resource is in\n * @param {string} [props.context] The context for this resource,\n * such as \"landscape mode\", or \"7200dp\", which differentiates it\n * from the base resource that has no special context. The default\n * if this property is not specified is undefined, meaning no\n * context.\n * @param {string} [props.sourceLocale] the locale of the source resource.\n * @param {string} [props.targetLocale] the locale of the target resource.\n * @param {string} [props.key] the unique key of this string, which should include the context\n * of the string\n * @param {string} [props.pathName] pathName to the file where the string was extracted from\n * @param {boolean} [props.autoKey] true if the key was generated based on the source text\n * @param {string} [props.state] current state of the resource (ie. \"new\", \"translated\", or \"accepted\")\n * @param {string} [props.id] the id of the current resource\n * @param {string} [props.comment] the comment (translator's note) of this resource\n * @param {boolean} [props.dnt] Do not translate this resource when this is set to true. Default: false\n * @param {string} [props.datatype] the type of file that this resource came from\n * @param {string} [props.flavor] the \"flavor\" of this string, if any. (Android)\n * @param {Location} [props.location] the location in the file given in pathName where this this resource\n * is located\n * @param {string | undefined} [props.resfile] if this resource was extracted from a resource file, this\n * is the path to the resource file that contains this resource. This is different from the pathName\n * property, which is the path to the source file that this resource was extracted from. This property\n * is only used for resources from resource files, such as Android string.xml files or xliff files.\n * Otherwise, the property is undefined.\n * @param {Object|undefined} [props.metadata] the metadata of the resource or undefined for no metadata.\n * This can be any arbitrary object of any depth, as long as the values of properties are all static.\n * It is up to the parsers to parse this and serializers to serialize this appropriately.\n */\n constructor(props) {\n if (this.constructor === Resource) {\n throw new Error(\"Cannot instantiate abstract class Resource!\");\n }\n\n this.autoKey = false;\n\n if (props) {\n this.project = props.project;\n this.context = props.context || undefined; // avoid the empty string\n this.sourceLocale = props.sourceLocale || props.locale;\n this.targetLocale = props.targetLocale;\n this.reskey = props.key || props.reskey;\n this.pathName = props.pathName;\n this.autoKey = typeof(props.autoKey) === \"boolean\" ? props.autoKey : false;\n this.state = props.state || undefined;\n this.id = props.id; // the database id\n this.formatted = props.formatted; // for Android layout resources\n this.comment = props.comment;\n this.origin = props.origin || \"source\";\n this.dnt = props.dnt;\n this.datatype = props.datatype;\n this.sourceHash = props.sourceHash;\n this.localize = typeof(props.localize) === \"boolean\" ? props.localize : true; // some files have resources we do not want to localize/translate\n this.flavor = props.flavor;\n this.index = props.index;\n this.location = props.location; // optional location of the transunits in the xml file\n this.resfile = props.resfile; // optional resource file path\n this.metadata = props.metadata || undefined;\n }\n\n this.instances = [];\n this.pathName = this.pathName || \"\";\n this.dirty = false;\n }\n\n /**\n * Return the project that this resource was found in.\n *\n * @returns {string} the project of this resource\n */\n getProject() {\n return this.project;\n }\n\n /**\n * Return the unique key of this resource.\n *\n * @returns {string} the unique key of this resource\n */\n getKey() {\n return this.reskey;\n }\n\n /**\n * Return the source string or strings for this resource.\n *\n * @returns {String|Array.<String>|Object} the source string or\n * strings of this resource\n */\n getSource() {\n return this.source;\n }\n\n /**\n * Return the target string or strings for this resource.\n *\n * @returns {String|Array.<String>|Object|undefined} the source string or\n * strings of this resource\n */\n getTarget() {\n return this.target;\n }\n\n /**\n * Return the resource type of this resource. This is one of\n * string, array, or plural.\n *\n * @returns {string} the resource type of this resource\n */\n getType() {\n return this.resType || \"string\";\n }\n\n /**\n * Return the data type of this resource.\n *\n * @returns {string} the data type of this resource\n */\n getDataType() {\n return this.datatype;\n }\n\n /**\n * Return true if the key of this resource was automatically generated,\n * and false if it was an explicit key.\n *\n * @returns {boolean} true if the key of this string was auto generated,\n * false otherwise\n */\n getAutoKey() {\n return this.autoKey;\n }\n\n /**\n * Return the context of this resource, or undefined if there\n * is no context.\n * @returns {String|undefined} the context of this resource, or undefined if there\n * is no context.\n */\n getContext() {\n return this.context;\n }\n\n /**\n * Get the metadata of this resource.\n *\n * @returns {Object|undefined} the metadata of this resource.\n */\n getMetadata() {\n return this.metadata;\n }\n\n /**\n * Set the metadata of this resource.\n * @param {Object|undefined} data the metadata of this resource.\n */\n setMetadata(data) {\n this.metadata = data;\n }\n\n /**\n * Return the source locale of this resource, or undefined if there\n * is no context or the locale is the same as the project's source locale.\n * @returns {String|undefined} the locale of this resource, or undefined if there\n * is no locale.\n */\n getSourceLocale() {\n return this.sourceLocale || \"en-US\";\n }\n\n /**\n * Set the source locale of this resource.\n * @param {string} locale the source locale of this resource\n */\n setSourceLocale(locale) {\n this.sourceLocale = locale || this.sourceLocale;\n this.dirty = true;\n }\n\n /**\n * Return the target locale of this resource, or undefined if the resource\n * is a source-only resource.\n * @returns {String|undefined} the locale of this resource, or undefined if there\n * is no locale.\n */\n getTargetLocale() {\n return this.targetLocale;\n }\n\n /**\n * Set the target locale of this resource.\n * @param {string} locale the target locale of this resource\n */\n setTargetLocale(locale) {\n this.targetLocale = locale || this.targetLocale;\n this.dirty = true;\n }\n\n /**\n * Return the state of this resource. This is a string that gives the\n * stage of life of this resource. Currently, it can be one of \"new\",\n * \"translated\", or \"accepted\".\n *\n * @returns {string} the state of this resource\n */\n getState() {\n return this.state;\n }\n\n /**\n * Set the project of this resource. This is a string that gives the\n * id of the project for this resource.\n *\n * @param {string} project the project name to set for this resource\n */\n setProject(project) {\n this.project = project;\n this.dirty = true;\n }\n\n /**\n * Set the state of this resource. This is a string that gives the\n * stage of life of this resource. Currently, it can be one of \"new\",\n * \"translated\", or \"accepted\".\n *\n * @param {string} state the state of this resource\n */\n setState(state) {\n this.state = validStates[state] ? state : this.state;\n this.dirty = true;\n }\n\n /**\n * Return the original path to the file from which this resource was\n * originally extracted.\n *\n * @returns {string} the path to the file containing this resource\n */\n getPath() {\n return this.pathName;\n }\n\n /**\n * Return the translator's comment for this resource if there is\n * one, or undefined if not.\n *\n * @returns {String|undefined} the translator's comment for this resource\n * if the engineer put one in the code\n */\n getComment() {\n return this.comment;\n }\n\n /**\n * Set the translator's comment for this resource.\n *\n * @param {String|undefined} comment the translator's comment to set. Use\n * undefined to clear the comment\n */\n setComment(comment) {\n this.comment = comment;\n this.dirty = true;\n }\n\n /**\n * Get the \"do not translate\" flag for this resource.\n *\n * @returns {boolean} true means that the current resource should not\n * be translated, and false means it will be translated.\n */\n getDNT() {\n return typeof(this.dnt) === 'boolean' ? this.dnt : false;\n }\n\n /**\n * Set the \"do not translate\" flag for this resource.\n *\n * @param {boolean} flag set the dnt flag to this value\n */\n setDNT(flag) {\n if (typeof(flag) !== 'boolean') {\n throw new TypeError('value must be boolean');\n }\n this.dnt = flag;\n this.dirty = true;\n }\n\n /**\n * Return the database id if this resource has previously been saved in the\n * database.\n *\n * @returns {number|undefined} the database id if this resource has previously\n * been saved in the database, or undefined if it is has not\n */\n getId() {\n return this.id;\n }\n\n /**\n * Return the origin of this resource. The origin may be either the string\n * \"source\" or \"target\". Source origin resources are ones that are extracted\n * from the source code, whereas target ones are translations from the\n * translators.\n *\n * @returns {string} the origin of this resource\n */\n getOrigin() {\n return this.origin;\n }\n\n /**\n * Return the localize flag of this resource.\n * This flag indicates whether we should look up a translation for this resource.\n * When false, we should simply substitute the source back\n *\n * @returns {Boolean} the localize flag of this resource\n */\n getLocalize() {\n return this.localize;\n }\n\n /**\n * Return the name of the flavor for this resource, or undefined\n * for the \"main\" or default flavor.\n *\n * @return {String|undefined} the name of the flavor for this\n * resource or undefined for the main or default flavor\n */\n getFlavor() {\n return this.flavor;\n }\n\n /**\n * Return the path to the resource file that contains this resource.\n * This is different from the pathName property, which is the path to\n * the source file that this resource was extracted from. This property\n * is only used for resources from resource files, such as Android\n * string.xml files or xliff files. Otherwise, the property is undefined.\n *\n * @returns {string|undefined} the path to the resource file that contains\n * this resource, or undefined if this resource was not extracted from\n * a resource file\n */\n getResFile() {\n return this.resfile;\n }\n\n /**\n * Return true if the other resource represents the same resource as\n * the current one. The project, context, locale, key, flavor, and type must\n * match. Other fields such as the pathName, state, and comment fields are\n * ignored as minor variations.\n *\n * @param {Resource} other another resource to test against the current one\n * @returns {boolean} true if these represent the same resource, false otherwise\n */\n same(other) {\n if (!other) return false;\n\n const props = [\"project\", \"context\", \"sourceLocale\", \"targetLocale\", \"reskey\", \"resType\", \"flavor\"];\n for (let i = 0; i < props.length; i++) {\n if (this[props[i]] !== other[props[i]]) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Escape text for writing to a database in a SQL command. This puts single\n * quotes around the string, and makes sure that all single quotes within\n * the string are escaped.\n *\n * @param {Object} str the item to escape\n * @returns {string} the escaped string\n */\n escapeText(str) {\n switch (typeof(str)) {\n case \"string\":\n // unescape first, then re-escape to make everything consistent\n return \"'\" + str.replace(/\\\\'/g, \"'\").replace(/'/g, \"\\\\'\") + \"'\";\n case \"undefined\":\n return \"NULL\";\n case \"boolean\":\n return str ? \"TRUE\" : \"FALSE\";\n default:\n if (str === null) {\n return \"NULL\";\n }\n return str.toString();\n }\n }\n\n /**\n * Add an instance of the same resource to the list of\n * instances. If the given resource matches the\n * current instance in all properties that affect the\n * possible translation, and differs from the current\n * instance by some property that does not affect\n * its translation, it will be added as an instance of\n * the same string. The following properties affect the\n * translation:\n *\n * <ul>\n * <li>context</li>\n * <li>datatype</li>\n * <li>dnt</li>\n * <li>flavor</li>\n * <li>project</li>\n * <li>reskey</li>\n * <li>resType</li>\n * <li>source</li>\n * <li>sourceHash</li>\n * <li>sourceArray</li>\n * <li>sourceLocale</li>\n * <li>targetLocale</li>\n * </ul>\n *\n * Differences in other properties, such as \"comment\" or\n * \"origin\" are considered instances of the same resource.\n *\n * If this method is given a resource that differs from\n * the current one by one of the above translation affecting\n * properties, it is not added to the list of instances. This\n * can be checked easily by calling the isInstance() method.\n *\n * @param {Resource} resource an instance of the current resource to\n * record\n * @returns {boolean} true if the instance was added, and\n * and false otherwise\n */\n addInstance(resource) {\n if (!this.isInstance(resource)) {\n return false;\n }\n const unique = this !== resource && this.instances.every(res => {\n return res !== resource;\n });\n if (!unique) {\n return false;\n }\n this.instances.push(resource);\n this.dirty = true;\n return true;\n }\n\n /**\n * Check if the given resource is an instance of the current\n * resource. This method returns true if all properties which\n * affect the possible translation match between the given and\n * the current resource.\n *\n * @param {Resource} resource a resource to check\n * @returns {boolean} true if this is an instance of\n * the current resource, false otherwise.\n */\n isInstance(resource) {\n if (typeof(resource) !== 'object' || !(resource instanceof Resource)) {\n return false;\n }\n\n return translationImportant.every(prop => {\n return this[prop] === resource[prop];\n });\n }\n\n /**\n * Return the list of instances of the current resource.\n *\n * @returns {Array.<Resource>} the list of instances of\n * the current resource\n */\n getInstances() {\n return this.instances;\n }\n\n /**\n * Return true if this instance has been modified since its creation, and false otherwise.\n */\n isDirty() {\n return this.dirty\n }\n\n /**\n * Clear the dirty flag. This is used for example when the Resource was\n * written to disk and the modifications are already recorded, allowing\n * new modifications later.\n */\n clearDirty() {\n this.dirty = false;\n }\n\n /**\n * Return the location of the resource instance in the original file where it was read\n * from. This is usually an object containing a line and a char property which gives the\n * line number and character within that line where the representation of the resource\n * instance starts.\n *\n * @returns {Location|undefined} the location information, or undefined if no location\n * information is available\n */\n getLocation() {\n return this.location?.getLocation();\n }\n\n /**\n * Return the a hash key that uniquely identifies this resource.\n *\n * @abstract\n * @returns {string} a unique hash key for this resource\n */\n hashKey() {\n throw new Error(\"hashKey() not implemented\");\n }\n\n /**\n * Return the a hash key that uniquely identifies this resource, but uses the cleaned version of the string\n *\n * @abstract\n * @returns {string} a unique hash key for this resource with a cleaned string\n */\n cleanHashKey() {\n throw new Error(\"cleanHashKey() not implemented\");\n }\n}\n\nexport default Resource;\n"],"mappings":"k0CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAEA,GAAM,CAAAA,WAAW,CAAG,CAChB,KAAK,CAAC,IAAI,CACV,YAAY,CAAC,IAAI,CACjB,UAAU,CAAC,IACf,CAAC,CAED,GAAM,CAAAC,oBAAoB,CAAG,CACzB,SAAS,CACT,UAAU,CACV,KAAK,CACL,QAAQ,CACR,SAAS,CACT,QAAQ,CACR,SAAS,CACT,cAAc,CACd,cAAc,CACjB,CAGD;AACA;AACA;AACA;AACA,GAJA,GAKM,CAAAC,QAAQ,yBAyBV;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MACI,SAAAA,SAAYC,KAAK,CAAE,CAAAC,eAAA,MAAAF,QAAA,EA/DnB;AACJ;AACA;AACA,OAHIG,eAAA,wBAMA;AACJ;AACA;AACA,OAHIA,eAAA,uBAMA;AACJ;AACA;AACA,OAH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,KAAA,CAMA,SAAAyD,OAAOA,CAAA,CAAG,CACN,KAAM,IAAI,CAAArF,KAAK,CAAC,2BAA2B,CAC/C,CAEA;AACJ;AACA;AACA;AACA;AACA,OALI,GAAAS,GAAA,gBAAAmB,KAAA,CAMA,SAAA0D,YAAYA,CAAA,CAAG,CACX,KAAM,IAAI,CAAAtF,KAAK,CAAC,gCAAgC,CACpD,CAAC,WAAAuF,QAAA,CAAAC,OAAA,YAGU7F,QAAQ,CAAA8F,MAAA,CAAAD,OAAA,CAAAA,OAAA,CAAAE,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Resource.js","names":["validStates","VALID_STATES","exports","Object","keys","sort","isValidState","state","length","startsWith","contentAfterX","substring","trim","translationImportant","Resource","props","_classCallCheck","_defineProperty","constructor","Error","autoKey","project","context","undefined","sourceLocale","locale","targetLocale","reskey","key","pathName","id","formatted","comment","origin","dnt","datatype","sourceHash","localize","flavor","index","location","resfile","metadata","instances","dirty","_createClass","value","getProject","getKey","getSource","source","getTarget","target","getType","resType","getDataType","getAutoKey","getContext","getMetadata","setMetadata","data","getSourceLocale","setSourceLocale","getTargetLocale","setTargetLocale","getState","setProject","setState","concat","join","getPath","getComment","setComment","getDNT","setDNT","flag","TypeError","getId","getOrigin","getLocalize","getFlavor","getResFile","same","other","i","escapeText","str","_typeof","replace","toString","addInstance","resource","isInstance","unique","every","res","push","_this","prop","getInstances","isDirty","clearDirty","getLocation","_this$location","hashKey","cleanHashKey","_default"],"sources":["../src/Resource.js"],"sourcesContent":["/*\n * Resource.js - super class that represents a resource\n *\n * Copyright © 2022-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\nconst validStates = {\n // XLIFF 2.0 standard states\n // https://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html\n \"initial\": true,\n \"translated\": true,\n \"reviewed\": true,\n \"final\": true,\n\n // XLIFF 1.2 standard states\n // from https://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html\n \"new\": true,\n \"needs-translation\": true,\n \"needs-adaptation\": true,\n \"needs-l10n\": true,\n \"needs-review-translation\": true,\n \"needs-review-adaptation\": true,\n \"needs-review-l10n\": true,\n \"signed-off\": true,\n\n // Additional common states used in practice\n \"needs-review\": true,\n \"fuzzy\": true,\n \"accepted\": true,\n \"rejected\": true,\n \"approved\": true,\n \"needs-approval\": true\n};\n\n/**\n * Array of all valid state names that can be used with Resource objects.\n * This array is sorted alphabetically and includes states from:\n * - XLIFF 2.0 standard states\n * - XLIFF 1.2 standard states\n * - Additional common states used in practice\n *\n * Custom states with \"x-\" prefix are also valid but not included in this array.\n *\n * @example\n * // Check if a state is valid\n * if (VALID_STATES.includes(state)) {\n * console.log('Valid state');\n * }\n *\n * @type {string[]}\n * @since 1.19.0\n */\nexport const VALID_STATES = Object.keys(validStates).sort();\n\n/**\n * Check if a state is valid according to XLIFF 1.2 or 2.0 specification\n * or if the state is used with ilib projects.\n *\n * @param {string} state the state to validate\n * @returns {boolean} true if the state is valid, false otherwise\n * @since 1.19.0\n */\nfunction isValidState(state) {\n // Must be a string\n if (typeof state !== 'string') {\n return false;\n }\n\n // Empty string is invalid\n if (state.length === 0) {\n return false;\n }\n\n // Check predefined states first\n if (validStates[state]) {\n return true;\n }\n\n // Custom states must start with \"x-\" and have content after the hyphen\n if (state.startsWith('x-')) {\n // Must have non-whitespace content after \"x-\"\n const contentAfterX = state.substring(2);\n if (contentAfterX.trim().length > 0) {\n return true;\n }\n }\n\n return false;\n}\n\nexport { isValidState };\n\nconst translationImportant = [\n \"context\",\n \"datatype\",\n \"dnt\",\n \"flavor\",\n \"project\",\n \"reskey\",\n \"resType\",\n \"sourceLocale\",\n \"targetLocale\"\n];\n\n\n/**\n * @class Represents a resource from a resource file or\n * extracted from the code.\n * @abstract\n */\nclass Resource {\n /**\n * The type of this resource instance.\n * @type {String | undefined}\n */\n resType;\n\n /**\n * The source string or strings for the resource.\n * @type {String|Array.<String>|Object}\n */\n source;\n\n /**\n * The target string or strings for the resource.\n * @type {String|Array.<String>|Object}\n */\n target;\n\n /**\n * The resource file that this resource was loaded from.\n * @type {string|undefined}\n */\n resfile;\n\n /**\n * Construct a new Resource instance.\n * The props may contain any\n * of the following properties:\n *\n * <ul>\n * </ul>\n *\n * @constructor\n * @param {Object} props properties of the string, as defined above\n * @param {string} [props.project] the project that this resource is in\n * @param {string} [props.context] The context for this resource,\n * such as \"landscape mode\", or \"7200dp\", which differentiates it\n * from the base resource that has no special context. The default\n * if this property is not specified is undefined, meaning no\n * context.\n * @param {string} [props.sourceLocale] the locale of the source resource.\n * @param {string} [props.targetLocale] the locale of the target resource.\n * @param {string} [props.key] the unique key of this string, which should include the context\n * of the string\n * @param {string} [props.pathName] pathName to the file where the string was extracted from\n * @param {boolean} [props.autoKey] true if the key was generated based on the source text\n * @param {string} [props.state] current state of the resource (ie. \"new\", \"translated\", or \"accepted\")\n * @param {string} [props.id] the id of the current resource\n * @param {string} [props.comment] the comment (translator's note) of this resource\n * @param {boolean} [props.dnt] Do not translate this resource when this is set to true. Default: false\n * @param {string} [props.datatype] the type of file that this resource came from\n * @param {string} [props.flavor] the \"flavor\" of this string, if any. (Android)\n * @param {Location} [props.location] the location in the file given in pathName where this this resource\n * is located\n * @param {string | undefined} [props.resfile] if this resource was extracted from a resource file, this\n * is the path to the resource file that contains this resource. This is different from the pathName\n * property, which is the path to the source file that this resource was extracted from. This property\n * is only used for resources from resource files, such as Android string.xml files or xliff files.\n * Otherwise, the property is undefined.\n * @param {Object|undefined} [props.metadata] the metadata of the resource or undefined for no metadata.\n * This can be any arbitrary object of any depth, as long as the values of properties are all static.\n * It is up to the parsers to parse this and serializers to serialize this appropriately.\n */\n constructor(props) {\n if (this.constructor === Resource) {\n throw new Error(\"Cannot instantiate abstract class Resource!\");\n }\n\n this.autoKey = false;\n\n if (props) {\n this.project = props.project;\n this.context = props.context || undefined; // avoid the empty string\n this.sourceLocale = props.sourceLocale || props.locale;\n this.targetLocale = props.targetLocale;\n this.reskey = props.key || props.reskey;\n this.pathName = props.pathName;\n this.autoKey = typeof(props.autoKey) === \"boolean\" ? props.autoKey : false;\n this.state = props.state || undefined;\n this.id = props.id; // the database id\n this.formatted = props.formatted; // for Android layout resources\n this.comment = props.comment;\n this.origin = props.origin || \"source\";\n this.dnt = props.dnt;\n this.datatype = props.datatype;\n this.sourceHash = props.sourceHash;\n this.localize = typeof(props.localize) === \"boolean\" ? props.localize : true; // some files have resources we do not want to localize/translate\n this.flavor = props.flavor;\n this.index = props.index;\n this.location = props.location; // optional location of the transunits in the xml file\n this.resfile = props.resfile; // optional resource file path\n this.metadata = props.metadata || undefined;\n }\n\n this.instances = [];\n this.pathName = this.pathName || \"\";\n this.dirty = false;\n }\n\n /**\n * Return the project that this resource was found in.\n *\n * @returns {string} the project of this resource\n */\n getProject() {\n return this.project;\n }\n\n /**\n * Return the unique key of this resource.\n *\n * @returns {string} the unique key of this resource\n */\n getKey() {\n return this.reskey;\n }\n\n /**\n * Return the source string or strings for this resource.\n *\n * @returns {String|Array.<String>|Object} the source string or\n * strings of this resource\n */\n getSource() {\n return this.source;\n }\n\n /**\n * Return the target string or strings for this resource.\n *\n * @returns {String|Array.<String>|Object|undefined} the source string or\n * strings of this resource\n */\n getTarget() {\n return this.target;\n }\n\n /**\n * Return the resource type of this resource. This is one of\n * string, array, or plural.\n *\n * @returns {string} the resource type of this resource\n */\n getType() {\n return this.resType || \"string\";\n }\n\n /**\n * Return the data type of this resource.\n *\n * @returns {string} the data type of this resource\n */\n getDataType() {\n return this.datatype;\n }\n\n /**\n * Return true if the key of this resource was automatically generated,\n * and false if it was an explicit key.\n *\n * @returns {boolean} true if the key of this string was auto generated,\n * false otherwise\n */\n getAutoKey() {\n return this.autoKey;\n }\n\n /**\n * Return the context of this resource, or undefined if there\n * is no context.\n * @returns {String|undefined} the context of this resource, or undefined if there\n * is no context.\n */\n getContext() {\n return this.context;\n }\n\n /**\n * Get the metadata of this resource.\n *\n * @returns {Object|undefined} the metadata of this resource.\n */\n getMetadata() {\n return this.metadata;\n }\n\n /**\n * Set the metadata of this resource.\n * @param {Object|undefined} data the metadata of this resource.\n */\n setMetadata(data) {\n this.metadata = data;\n }\n\n /**\n * Return the source locale of this resource, or undefined if there\n * is no context or the locale is the same as the project's source locale.\n * @returns {String|undefined} the locale of this resource, or undefined if there\n * is no locale.\n */\n getSourceLocale() {\n return this.sourceLocale || \"en-US\";\n }\n\n /**\n * Set the source locale of this resource.\n * @param {string} locale the source locale of this resource\n */\n setSourceLocale(locale) {\n this.sourceLocale = locale || this.sourceLocale;\n this.dirty = true;\n }\n\n /**\n * Return the target locale of this resource, or undefined if the resource\n * is a source-only resource.\n * @returns {String|undefined} the locale of this resource, or undefined if there\n * is no locale.\n */\n getTargetLocale() {\n return this.targetLocale;\n }\n\n /**\n * Set the target locale of this resource.\n * @param {string} locale the target locale of this resource\n */\n setTargetLocale(locale) {\n this.targetLocale = locale || this.targetLocale;\n this.dirty = true;\n }\n\n /**\n * Return the state of this resource. This is a string that gives the\n * stage of life of this resource. Currently, it can be one of \"new\",\n * \"translated\", or \"accepted\".\n *\n * @returns {string} the state of this resource\n */\n getState() {\n return this.state;\n }\n\n /**\n * Set the project of this resource. This is a string that gives the\n * id of the project for this resource.\n *\n * @param {string} project the project name to set for this resource\n */\n setProject(project) {\n this.project = project;\n this.dirty = true;\n }\n\n /**\n * Set the state of this resource. This is a string that gives the\n * stage of life of this resource. Currently, it can be one of \"new\",\n * \"translated\", or \"accepted\".\n *\n * @param {string} state the state of this resource\n * @throws {Error} if the state is invalid\n */\n setState(state) {\n if (!isValidState(state)) {\n throw new Error(`Attempt to set an invalid state on a resource: \"${state}\". Valid states are: ${VALID_STATES.join(', ')}, or custom states starting with \"x-\"`);\n }\n this.state = state;\n this.dirty = true;\n }\n\n /**\n * Return the original path to the file from which this resource was\n * originally extracted.\n *\n * @returns {string} the path to the file containing this resource\n */\n getPath() {\n return this.pathName;\n }\n\n /**\n * Return the translator's comment for this resource if there is\n * one, or undefined if not.\n *\n * @returns {String|undefined} the translator's comment for this resource\n * if the engineer put one in the code\n */\n getComment() {\n return this.comment;\n }\n\n /**\n * Set the translator's comment for this resource.\n *\n * @param {String|undefined} comment the translator's comment to set. Use\n * undefined to clear the comment\n */\n setComment(comment) {\n this.comment = comment;\n this.dirty = true;\n }\n\n /**\n * Get the \"do not translate\" flag for this resource.\n *\n * @returns {boolean} true means that the current resource should not\n * be translated, and false means it will be translated.\n */\n getDNT() {\n return typeof(this.dnt) === 'boolean' ? this.dnt : false;\n }\n\n /**\n * Set the \"do not translate\" flag for this resource.\n *\n * @param {boolean} flag set the dnt flag to this value\n */\n setDNT(flag) {\n if (typeof(flag) !== 'boolean') {\n throw new TypeError('value must be boolean');\n }\n this.dnt = flag;\n this.dirty = true;\n }\n\n /**\n * Return the database id if this resource has previously been saved in the\n * database.\n *\n * @returns {number|undefined} the database id if this resource has previously\n * been saved in the database, or undefined if it is has not\n */\n getId() {\n return this.id;\n }\n\n /**\n * Return the origin of this resource. The origin may be either the string\n * \"source\" or \"target\". Source origin resources are ones that are extracted\n * from the source code, whereas target ones are translations from the\n * translators.\n *\n * @returns {string} the origin of this resource\n */\n getOrigin() {\n return this.origin;\n }\n\n /**\n * Return the localize flag of this resource.\n * This flag indicates whether we should look up a translation for this resource.\n * When false, we should simply substitute the source back\n *\n * @returns {Boolean} the localize flag of this resource\n */\n getLocalize() {\n return this.localize;\n }\n\n /**\n * Return the name of the flavor for this resource, or undefined\n * for the \"main\" or default flavor.\n *\n * @return {String|undefined} the name of the flavor for this\n * resource or undefined for the main or default flavor\n */\n getFlavor() {\n return this.flavor;\n }\n\n /**\n * Return the path to the resource file that contains this resource.\n * This is different from the pathName property, which is the path to\n * the source file that this resource was extracted from. This property\n * is only used for resources from resource files, such as Android\n * string.xml files or xliff files. Otherwise, the property is undefined.\n *\n * @returns {string|undefined} the path to the resource file that contains\n * this resource, or undefined if this resource was not extracted from\n * a resource file\n */\n getResFile() {\n return this.resfile;\n }\n\n /**\n * Return true if the other resource represents the same resource as\n * the current one. The project, context, locale, key, flavor, and type must\n * match. Other fields such as the pathName, state, and comment fields are\n * ignored as minor variations.\n *\n * @param {Resource} other another resource to test against the current one\n * @returns {boolean} true if these represent the same resource, false otherwise\n */\n same(other) {\n if (!other) return false;\n\n const props = [\"project\", \"context\", \"sourceLocale\", \"targetLocale\", \"reskey\", \"resType\", \"flavor\"];\n for (let i = 0; i < props.length; i++) {\n if (this[props[i]] !== other[props[i]]) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Escape text for writing to a database in a SQL command. This puts single\n * quotes around the string, and makes sure that all single quotes within\n * the string are escaped.\n *\n * @param {Object} str the item to escape\n * @returns {string} the escaped string\n */\n escapeText(str) {\n switch (typeof(str)) {\n case \"string\":\n // unescape first, then re-escape to make everything consistent\n return \"'\" + str.replace(/\\\\'/g, \"'\").replace(/'/g, \"\\\\'\") + \"'\";\n case \"undefined\":\n return \"NULL\";\n case \"boolean\":\n return str ? \"TRUE\" : \"FALSE\";\n default:\n if (str === null) {\n return \"NULL\";\n }\n return str.toString();\n }\n }\n\n /**\n * Add an instance of the same resource to the list of\n * instances. If the given resource matches the\n * current instance in all properties that affect the\n * possible translation, and differs from the current\n * instance by some property that does not affect\n * its translation, it will be added as an instance of\n * the same string. The following properties affect the\n * translation:\n *\n * <ul>\n * <li>context</li>\n * <li>datatype</li>\n * <li>dnt</li>\n * <li>flavor</li>\n * <li>project</li>\n * <li>reskey</li>\n * <li>resType</li>\n * <li>source</li>\n * <li>sourceHash</li>\n * <li>sourceArray</li>\n * <li>sourceLocale</li>\n * <li>targetLocale</li>\n * </ul>\n *\n * Differences in other properties, such as \"comment\" or\n * \"origin\" are considered instances of the same resource.\n *\n * If this method is given a resource that differs from\n * the current one by one of the above translation affecting\n * properties, it is not added to the list of instances. This\n * can be checked easily by calling the isInstance() method.\n *\n * @param {Resource} resource an instance of the current resource to\n * record\n * @returns {boolean} true if the instance was added, and\n * and false otherwise\n */\n addInstance(resource) {\n if (!this.isInstance(resource)) {\n return false;\n }\n const unique = this !== resource && this.instances.every(res => {\n return res !== resource;\n });\n if (!unique) {\n return false;\n }\n this.instances.push(resource);\n this.dirty = true;\n return true;\n }\n\n /**\n * Check if the given resource is an instance of the current\n * resource. This method returns true if all properties which\n * affect the possible translation match between the given and\n * the current resource.\n *\n * @param {Resource} resource a resource to check\n * @returns {boolean} true if this is an instance of\n * the current resource, false otherwise.\n */\n isInstance(resource) {\n if (typeof(resource) !== 'object' || !(resource instanceof Resource)) {\n return false;\n }\n\n return translationImportant.every(prop => {\n return this[prop] === resource[prop];\n });\n }\n\n /**\n * Return the list of instances of the current resource.\n *\n * @returns {Array.<Resource>} the list of instances of\n * the current resource\n */\n getInstances() {\n return this.instances;\n }\n\n /**\n * Return true if this instance has been modified since its creation, and false otherwise.\n */\n isDirty() {\n return this.dirty\n }\n\n /**\n * Clear the dirty flag. This is used for example when the Resource was\n * written to disk and the modifications are already recorded, allowing\n * new modifications later.\n */\n clearDirty() {\n this.dirty = false;\n }\n\n /**\n * Return the location of the resource instance in the original file where it was read\n * from. This is usually an object containing a line and a char property which gives the\n * line number and character within that line where the representation of the resource\n * instance starts.\n *\n * @returns {Location|undefined} the location information, or undefined if no location\n * information is available\n */\n getLocation() {\n return this.location?.getLocation();\n }\n\n /**\n * Return the a hash key that uniquely identifies this resource.\n *\n * @abstract\n * @returns {string} a unique hash key for this resource\n */\n hashKey() {\n throw new Error(\"hashKey() not implemented\");\n }\n\n /**\n * Return the a hash key that uniquely identifies this resource, but uses the cleaned version of the string\n *\n * @abstract\n * @returns {string} a unique hash key for this resource with a cleaned string\n */\n cleanHashKey() {\n throw new Error(\"cleanHashKey() not implemented\");\n }\n}\n\nexport default Resource;\n"],"mappings":"y3CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAEA,GAAM,CAAAA,WAAW,CAAG,CAChB;AACA;AACA,SAAS,CAAE,IAAI,CACf,YAAY,CAAE,IAAI,CAClB,UAAU,CAAE,IAAI,CAChB,OAAO,CAAE,IAAI,CAEb;AACA;AACA,KAAK,CAAE,IAAI,CACX,mBAAmB,CAAE,IAAI,CACzB,kBAAkB,CAAE,IAAI,CACxB,YAAY,CAAE,IAAI,CAClB,0BAA0B,CAAE,IAAI,CAChC,yBAAyB,CAAE,IAAI,CAC/B,mBAAmB,CAAE,IAAI,CACzB,YAAY,CAAE,IAAI,CAElB;AACA,cAAc,CAAE,IAAI,CACpB,OAAO,CAAE,IAAI,CACb,UAAU,CAAE,IAAI,CAChB,UAAU,CAAE,IAAI,CAChB,UAAU,CAAE,IAAI,CAChB,gBAAgB,CAAE,IACtB,CAAC,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACO,GAAM,CAAAC,YAAY,CAAAC,OAAA,CAAAD,YAAA,CAAGE,MAAM,CAACC,IAAI,CAACJ,WAAW,CAAC,CAACK,IAAI,CAAC,CAAC,CAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAC,YAAYA,CAACC,KAAK,CAAE,CACzB;AACA,GAAI,MAAO,CAAAA,KAAK,GAAK,QAAQ,CAAE,CAC3B,MAAO,MACX,CAEA;AACA,GAAIA,KAAK,CAACC,MAAM,GAAK,CAAC,CAAE,CACpB,MAAO,MACX,CAEA;AACA,GAAIR,WAAW,CAACO,KAAK,CAAC,CAAE,CACpB,MAAO,KACX,CAEA;AACA,GAAIA,KAAK,CAACE,UAAU,CAAC,IAAI,CAAC,CAAE,CACx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ralForm=form;json.pluralFormOther=res.getKey();retur
|
|
|
42
42
|
* @param {string} [options.version] The version of xliff that will be produced by this instance. This
|
|
43
43
|
* may be either "1.2" or "2.0"
|
|
44
44
|
* @param {Xliff} [options.xliff] The xliff instance to use for this resource xliff instance.
|
|
45
|
-
*/function ResourceXliff(options){var _options$xliff;_classCallCheck(this,ResourceXliff);if(options){this["tool-id"]=options["tool-id"];this["tool-name"]=options["tool-name"];this["tool-version"]=options["tool-version"];this["tool-company"]=options["tool-company"];this.copyright=options.copyright;this.path=options.path;this.sourceLocale=options.sourceLocale||"en-US";this.project=options.project;this.allowDups=options.allowDups;this.style=options.style||"standard";if(typeof options.version!=="undefined"){this.version=options.version}}this.sourceLocale=this.sourceLocale||"en-US";this.xliff=(_options$xliff=options===null||options===void 0?void 0:options.xliff)!==null&&_options$xliff!==void 0?_options$xliff:new _ilibXliff.Xliff(options);this.ts=new _TranslationSet["default"](this.sourceLocale)}/**
|
|
45
|
+
*/function ResourceXliff(options){var _options$xliff,_this=this;_classCallCheck(this,ResourceXliff);if(options){this["tool-id"]=options["tool-id"];this["tool-name"]=options["tool-name"];this["tool-version"]=options["tool-version"];this["tool-company"]=options["tool-company"];this.copyright=options.copyright;this.path=options.path;this.sourceLocale=options.sourceLocale||"en-US";this.project=options.project;this.allowDups=options.allowDups;this.style=options.style||"standard";if(typeof options.version!=="undefined"){this.version=options.version}}this.sourceLocale=this.sourceLocale||"en-US";this.xliff=(_options$xliff=options===null||options===void 0?void 0:options.xliff)!==null&&_options$xliff!==void 0?_options$xliff:new _ilibXliff.Xliff(options);this.ts=new _TranslationSet["default"](this.sourceLocale);if(this.xliff.getTranslationUnits().length){var translationUnits=this.xliff.getTranslationUnits();translationUnits.forEach(function(tu){_this.ts.add(_this.convertTransUnit(tu))})}}/**
|
|
46
46
|
* Convert a resource into one or more translation units.
|
|
47
47
|
*
|
|
48
48
|
* @private
|
|
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","copyright","path","sourceLocale","project","allowDups","style","version","xliff","Xliff","ts","TranslationSet","value","convertResource","units","tu","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","convertTransUnit","ResourceString","pathName","Location","resfile","setTarget","arr","ResourceArray","addTargetItem","strings","ResourcePlural","addTargetPlural","setDNT","setPath","newPath","xml","tuList","deserialize","add","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\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":"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,CAA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A,SAAAwE,IAAIA,CAAA,CAAG,CACH,MAAO,KAAI,CAAC1E,EAAE,CAAC0E,IAAI,CAAC,CACxB,CAEA;AACJ;AACA;AACA;AACA,OAJI,GAAA7G,GAAA,cAAAqC,KAAA,CAKA,SAAAsF,UAAUA,CAAA,CAAG,CACT,MAAO,KAAI,CAAC3F,OAChB,CAAC,WAAA4F,QAAA,CAAAC,OAAA,YAGUtG,aAAa,CAAAuG,MAAA,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,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,CAAC,CAClD,CACJ,CACJ,CAEA;AACA,IAAI,CAACsB,KAAK,CAAC0F,KAAK,CAAC,CAAC,CAClB,IAAI,CAAC1F,KAAK,CAAC2F,mBAAmB,CAAC/E,KAAK,CAAC,CAErC,MAAO,KAAI,CAACZ,KAAK,CAAC4F,SAAS,CAAC,IAAI,CACpC,CAEA;AACJ;AACA;AACA;AACA,OAJI,GAAA9H,GAAA,YAAA4C,KAAA,CAKA,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";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,"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,"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=
|
|
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","
|
|
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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":[]}
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.cleanString=cleanString;exports.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,EAA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AE,IAAI,CACzB,gBAAgB,CAAE,IACtB,CACJ,CAAC,CAED;AACA,GAAM,CAAAC,uBAAuB,CAAG,CAC5B,KAAK,CACL,OAAO,CACV,CAED;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,qBA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,mBAAA,CAAAC,qBAAA,CAClD;AACA,GAAM,CAAA9F,MAAM,CAAG,GAAI,CAAAE,sBAAM,CAACgC,QAAQ,CAAC,CACnC,GAAM,CAAA6D,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"
|
|
@@ -81,10 +81,10 @@
|
|
|
81
81
|
"ilib-xliff-webos": "^1.0.5",
|
|
82
82
|
"intl-messageformat": "^10.7.11",
|
|
83
83
|
"micromatch": "^4.0.8",
|
|
84
|
-
"ilib-xliff": "^1.4.1",
|
|
85
|
-
"ilib-locale": "^1.2.4",
|
|
86
84
|
"ilib-ctype": "^1.3.0",
|
|
87
|
-
"ilib-istring": "^1.1.1"
|
|
85
|
+
"ilib-istring": "^1.1.1",
|
|
86
|
+
"ilib-locale": "^1.3.0",
|
|
87
|
+
"ilib-xliff": "^1.4.1"
|
|
88
88
|
},
|
|
89
89
|
"scripts": {
|
|
90
90
|
"build": "pnpm build:data ; pnpm build:prod",
|
|
@@ -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/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
|
};
|