ilib-tools-common 1.2.0 → 1.4.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/README.md +16 -1
- package/docs/Resource.html +260 -279
- package/docs/Resource.js.html +5 -2
- package/docs/ResourceArray.html +488 -512
- package/docs/ResourceArray.js.html +5 -2
- package/docs/ResourcePlural.html +518 -545
- package/docs/ResourcePlural.js.html +5 -2
- package/docs/ResourceString.html +1066 -1077
- package/docs/ResourceString.js.html +5 -2
- package/docs/ResourceXliff.html +34 -30
- package/docs/ResourceXliff.js.html +5 -2
- package/docs/TranslationSet.html +157 -160
- package/docs/TranslationSet.js.html +5 -2
- package/docs/TranslationUnit.html +1132 -0
- package/docs/TranslationUnit.js.html +249 -0
- package/docs/TranslationVariant.html +363 -0
- package/docs/TranslationVariant.js.html +122 -0
- package/docs/global.html +545 -36
- package/docs/index.html +5 -2
- package/docs/scripts/collapse.js +19 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/search.js +16 -0
- package/docs/styles/jsdoc.css +13 -2
- package/docs/styles/prettify.css +1 -0
- package/docs/utils.js.html +96 -3
- package/package.json +5 -4
- package/src/TranslationUnit.js +178 -0
- package/src/TranslationVariant.js +51 -0
- package/src/index.js +19 -2
- package/src/utils.js +91 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>TranslationUnit.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Resource.html">Resource</a><ul class='methods'><li data-type='method'><a href="Resource.html#addInstance">addInstance</a></li><li data-type='method'><a href="Resource.html#escapeText">escapeText</a></li><li data-type='method'><a href="Resource.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="Resource.html#getComment">getComment</a></li><li data-type='method'><a href="Resource.html#getContext">getContext</a></li><li data-type='method'><a href="Resource.html#getDataType">getDataType</a></li><li data-type='method'><a href="Resource.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="Resource.html#getId">getId</a></li><li data-type='method'><a href="Resource.html#getInstances">getInstances</a></li><li data-type='method'><a href="Resource.html#getKey">getKey</a></li><li data-type='method'><a href="Resource.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="Resource.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="Resource.html#getPath">getPath</a></li><li data-type='method'><a href="Resource.html#getProject">getProject</a></li><li data-type='method'><a href="Resource.html#getSource">getSource</a></li><li data-type='method'><a href="Resource.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="Resource.html#getState">getState</a></li><li data-type='method'><a href="Resource.html#getTarget">getTarget</a></li><li data-type='method'><a href="Resource.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="Resource.html#getType">getType</a></li><li data-type='method'><a href="Resource.html#isInstance">isInstance</a></li><li data-type='method'><a href="Resource.html#same">same</a></li><li data-type='method'><a href="Resource.html#setComment">setComment</a></li><li data-type='method'><a href="Resource.html#setProject">setProject</a></li><li data-type='method'><a href="Resource.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="Resource.html#setState">setState</a></li><li data-type='method'><a href="Resource.html#setTargetLocale">setTargetLocale</a></li></ul></li><li><a href="ResourceArray.html">ResourceArray</a><ul class='methods'><li data-type='method'><a href="ResourceArray.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourceArray.html#addSourceItem">addSourceItem</a></li><li data-type='method'><a href="ResourceArray.html#addTargetItem">addTargetItem</a></li><li data-type='method'><a href="ResourceArray.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceArray.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourceArray.html#clone">clone</a></li><li data-type='method'><a href="ResourceArray.html#equals">equals</a></li><li data-type='method'><a href="ResourceArray.html#equals">equals</a></li><li data-type='method'><a href="ResourceArray.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourceArray.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourceArray.html#getComment">getComment</a></li><li data-type='method'><a href="ResourceArray.html#getContext">getContext</a></li><li data-type='method'><a href="ResourceArray.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourceArray.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourceArray.html#getId">getId</a></li><li data-type='method'><a href="ResourceArray.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourceArray.html#getKey">getKey</a></li><li data-type='method'><a href="ResourceArray.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourceArray.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourceArray.html#getPath">getPath</a></li><li data-type='method'><a href="ResourceArray.html#getProject">getProject</a></li><li data-type='method'><a href="ResourceArray.html#getSource">getSource</a></li><li data-type='method'><a href="ResourceArray.html#getSourceArray">getSourceArray</a></li><li data-type='method'><a href="ResourceArray.html#getSourceItem">getSourceItem</a></li><li data-type='method'><a href="ResourceArray.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourceArray.html#getState">getState</a></li><li data-type='method'><a href="ResourceArray.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourceArray.html#getTargetArray">getTargetArray</a></li><li data-type='method'><a href="ResourceArray.html#getTargetItem">getTargetItem</a></li><li data-type='method'><a href="ResourceArray.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourceArray.html#getType">getType</a></li><li data-type='method'><a href="ResourceArray.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourceArray.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourceArray.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourceArray.html#same">same</a></li><li data-type='method'><a href="ResourceArray.html#setComment">setComment</a></li><li data-type='method'><a href="ResourceArray.html#setProject">setProject</a></li><li data-type='method'><a href="ResourceArray.html#setSource">setSource</a></li><li data-type='method'><a href="ResourceArray.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourceArray.html#setState">setState</a></li><li data-type='method'><a href="ResourceArray.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourceArray.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourceArray.html#size">size</a></li><li data-type='method'><a href="ResourceArray.html#.hashKey">hashKey</a></li></ul></li><li><a href="ResourcePlural.html">ResourcePlural</a><ul class='methods'><li data-type='method'><a href="ResourcePlural.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourcePlural.html#addSourcePlural">addSourcePlural</a></li><li data-type='method'><a href="ResourcePlural.html#addTargetPlural">addTargetPlural</a></li><li data-type='method'><a href="ResourcePlural.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourcePlural.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourcePlural.html#clone">clone</a></li><li data-type='method'><a href="ResourcePlural.html#equals">equals</a></li><li data-type='method'><a href="ResourcePlural.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourcePlural.html#getAllValidCategories">getAllValidCategories</a></li><li data-type='method'><a href="ResourcePlural.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourcePlural.html#getCategories">getCategories</a></li><li data-type='method'><a href="ResourcePlural.html#getClasses">getClasses</a></li><li data-type='method'><a href="ResourcePlural.html#getComment">getComment</a></li><li data-type='method'><a href="ResourcePlural.html#getContext">getContext</a></li><li data-type='method'><a href="ResourcePlural.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourcePlural.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourcePlural.html#getId">getId</a></li><li data-type='method'><a href="ResourcePlural.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourcePlural.html#getKey">getKey</a></li><li data-type='method'><a href="ResourcePlural.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourcePlural.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourcePlural.html#getPath">getPath</a></li><li data-type='method'><a href="ResourcePlural.html#getProject">getProject</a></li><li data-type='method'><a href="ResourcePlural.html#getSource">getSource</a></li><li data-type='method'><a href="ResourcePlural.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourcePlural.html#getSourcePlural">getSourcePlural</a></li><li data-type='method'><a href="ResourcePlural.html#getSourcePlurals">getSourcePlurals</a></li><li data-type='method'><a href="ResourcePlural.html#getSourceStrings">getSourceStrings</a></li><li data-type='method'><a href="ResourcePlural.html#getState">getState</a></li><li data-type='method'><a href="ResourcePlural.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetPlural">getTargetPlural</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetPlurals">getTargetPlurals</a></li><li data-type='method'><a href="ResourcePlural.html#getTargetStrings">getTargetStrings</a></li><li data-type='method'><a href="ResourcePlural.html#getType">getType</a></li><li data-type='method'><a href="ResourcePlural.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourcePlural.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourcePlural.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourcePlural.html#same">same</a></li><li data-type='method'><a href="ResourcePlural.html#setComment">setComment</a></li><li data-type='method'><a href="ResourcePlural.html#setProject">setProject</a></li><li data-type='method'><a href="ResourcePlural.html#setSource">setSource</a></li><li data-type='method'><a href="ResourcePlural.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourcePlural.html#setState">setState</a></li><li data-type='method'><a href="ResourcePlural.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourcePlural.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourcePlural.html#size">size</a></li><li data-type='method'><a href="ResourcePlural.html#.hashKey">hashKey</a></li></ul></li><li><a href="ResourceString.html">ResourceString</a><ul class='methods'><li data-type='method'><a href="ResourceString.html#addInstance">addInstance</a></li><li data-type='method'><a href="ResourceString.html#cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceString.html#cleanHashKeyForTranslation">cleanHashKeyForTranslation</a></li><li data-type='method'><a href="ResourceString.html#clone">clone</a></li><li data-type='method'><a href="ResourceString.html#equals">equals</a></li><li data-type='method'><a href="ResourceString.html#escapeText">escapeText</a></li><li data-type='method'><a href="ResourceString.html#getAutoKey">getAutoKey</a></li><li data-type='method'><a href="ResourceString.html#getComment">getComment</a></li><li data-type='method'><a href="ResourceString.html#getContext">getContext</a></li><li data-type='method'><a href="ResourceString.html#getDataType">getDataType</a></li><li data-type='method'><a href="ResourceString.html#getFlavor">getFlavor</a></li><li data-type='method'><a href="ResourceString.html#getId">getId</a></li><li data-type='method'><a href="ResourceString.html#getInstances">getInstances</a></li><li data-type='method'><a href="ResourceString.html#getKey">getKey</a></li><li data-type='method'><a href="ResourceString.html#getLocalize">getLocalize</a></li><li data-type='method'><a href="ResourceString.html#getOrigin">getOrigin</a></li><li data-type='method'><a href="ResourceString.html#getPath">getPath</a></li><li data-type='method'><a href="ResourceString.html#getProject">getProject</a></li><li data-type='method'><a href="ResourceString.html#getSource">getSource</a></li><li data-type='method'><a href="ResourceString.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="ResourceString.html#getState">getState</a></li><li data-type='method'><a href="ResourceString.html#getTarget">getTarget</a></li><li data-type='method'><a href="ResourceString.html#getTargetLocale">getTargetLocale</a></li><li data-type='method'><a href="ResourceString.html#getType">getType</a></li><li data-type='method'><a href="ResourceString.html#hashKey">hashKey</a></li><li data-type='method'><a href="ResourceString.html#hashKeyForTranslation">hashKeyForTranslation</a></li><li data-type='method'><a href="ResourceString.html#isInstance">isInstance</a></li><li data-type='method'><a href="ResourceString.html#same">same</a></li><li data-type='method'><a href="ResourceString.html#setComment">setComment</a></li><li data-type='method'><a href="ResourceString.html#setProject">setProject</a></li><li data-type='method'><a href="ResourceString.html#setSource">setSource</a></li><li data-type='method'><a href="ResourceString.html#setSourceLocale">setSourceLocale</a></li><li data-type='method'><a href="ResourceString.html#setState">setState</a></li><li data-type='method'><a href="ResourceString.html#setTarget">setTarget</a></li><li data-type='method'><a href="ResourceString.html#setTargetLocale">setTargetLocale</a></li><li data-type='method'><a href="ResourceString.html#size">size</a></li><li data-type='method'><a href="ResourceString.html#.cleanHashKey">cleanHashKey</a></li><li data-type='method'><a href="ResourceString.html#.hashKey">hashKey</a></li></ul></li><li><a href="ResourceXliff.html">ResourceXliff</a></li><li><a href="TranslationSet.html">TranslationSet</a><ul class='methods'><li data-type='method'><a href="TranslationSet.html#add">add</a></li><li data-type='method'><a href="TranslationSet.html#addAll">addAll</a></li><li data-type='method'><a href="TranslationSet.html#addSet">addSet</a></li><li data-type='method'><a href="TranslationSet.html#clear">clear</a></li><li data-type='method'><a href="TranslationSet.html#diff">diff</a></li><li data-type='method'><a href="TranslationSet.html#get">get</a></li><li data-type='method'><a href="TranslationSet.html#getAll">getAll</a></li><li data-type='method'><a href="TranslationSet.html#getBy">getBy</a></li><li data-type='method'><a href="TranslationSet.html#getBySource">getBySource</a></li><li data-type='method'><a href="TranslationSet.html#getClean">getClean</a></li><li data-type='method'><a href="TranslationSet.html#getContexts">getContexts</a></li><li data-type='method'><a href="TranslationSet.html#getLocales">getLocales</a></li><li data-type='method'><a href="TranslationSet.html#getProjects">getProjects</a></li><li data-type='method'><a href="TranslationSet.html#isDirty">isDirty</a></li><li data-type='method'><a href="TranslationSet.html#remove">remove</a></li><li data-type='method'><a href="TranslationSet.html#setClean">setClean</a></li><li data-type='method'><a href="TranslationSet.html#size">size</a></li></ul></li><li><a href="TranslationUnit.html">TranslationUnit</a><ul class='methods'><li data-type='method'><a href="TranslationUnit.html#addProperties">addProperties</a></li><li data-type='method'><a href="TranslationUnit.html#addVariant">addVariant</a></li><li data-type='method'><a href="TranslationUnit.html#addVariants">addVariants</a></li><li data-type='method'><a href="TranslationUnit.html#clone">clone</a></li><li data-type='method'><a href="TranslationUnit.html#getProperties">getProperties</a></li><li data-type='method'><a href="TranslationUnit.html#getVariants">getVariants</a></li><li data-type='method'><a href="TranslationUnit.html#hashKey">hashKey</a></li></ul></li><li><a href="TranslationVariant.html">TranslationVariant</a><ul class='methods'><li data-type='method'><a href="TranslationVariant.html#hashKey">hashKey</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#cleanString">cleanString</a></li><li><a href="global.html#containsActualText">containsActualText</a></li><li><a href="global.html#formatPath">formatPath</a></li><li><a href="global.html#getLocaleFromPath">getLocaleFromPath</a></li><li><a href="global.html#hashKey">hashKey</a></li><li><a href="global.html#isEmpty">isEmpty</a></li><li><a href="global.html#objectMap">objectMap</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">TranslationUnit.js</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>/*
|
|
49
|
+
* TranslationUnit.js - model a translation unit in a translation file
|
|
50
|
+
*
|
|
51
|
+
* Copyright © 2023 JEDLSoft
|
|
52
|
+
*
|
|
53
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
54
|
+
* you may not use this file except in compliance with the License.
|
|
55
|
+
* You may obtain a copy of the License at
|
|
56
|
+
*
|
|
57
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
58
|
+
*
|
|
59
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
60
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
61
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
62
|
+
*
|
|
63
|
+
* See the License for the specific language governing permissions and
|
|
64
|
+
* limitations under the License.
|
|
65
|
+
*/
|
|
66
|
+
import log4js from "@log4js-node/log4js-api";
|
|
67
|
+
|
|
68
|
+
import TranslationVariant from './TranslationVariant.js';
|
|
69
|
+
import { hashKey } from './utils.js';
|
|
70
|
+
|
|
71
|
+
const logger = log4js.getLogger("tools-common.TranslationUnit");
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @class Represent a translation unit. A translation unit is
|
|
75
|
+
* a segment in the source language, along with one or
|
|
76
|
+
* more variants, which are translations to various
|
|
77
|
+
* target languages. A translation unit may contain more
|
|
78
|
+
* than one translation for a particular locale, as there
|
|
79
|
+
* are sometimes more than one translation for a particular
|
|
80
|
+
* phrase in the source language, depending on the context.
|
|
81
|
+
*/
|
|
82
|
+
class TranslationUnit {
|
|
83
|
+
/**
|
|
84
|
+
* Create a new translation unit.
|
|
85
|
+
*
|
|
86
|
+
* The options may be undefined, which represents
|
|
87
|
+
* a new, clean TranslationUnit instance. The options object may also
|
|
88
|
+
* be an object with the following properties:
|
|
89
|
+
*
|
|
90
|
+
* <ul>
|
|
91
|
+
* <li><i>source</i> - source text for this unit (required)
|
|
92
|
+
* <li><i>sourceLocale</i> - the source locale spec for this unit (required)
|
|
93
|
+
* <li><i>target</i> - target text for this unit (optional)
|
|
94
|
+
* <li><i>targetLocale</i> - the target locale spec for this unit (optional)
|
|
95
|
+
* <li><i>key</i> - the unique resource key for this translation unit (required)
|
|
96
|
+
* <li><i>file</i> - path to the original source code file that contains the
|
|
97
|
+
* source text of this translation unit (required)
|
|
98
|
+
* <li><i>project</i> - the project that this string/unit is part of
|
|
99
|
+
* <li><i>resType</i> - type of this resource (string, array, plural) (optional)
|
|
100
|
+
* <li><i>state</i> - the state of the current unit (optional)
|
|
101
|
+
* <li><i>comment</i> - the translator's comment for this unit (optional)
|
|
102
|
+
* <li><i>datatype</i> - the source of the data of this unit (optional)
|
|
103
|
+
* <li><i>flavor</i> - the flavor that this string comes from(optional)
|
|
104
|
+
* </ul>
|
|
105
|
+
*
|
|
106
|
+
* If the required properties are not given, the constructor throws an exception.<p>
|
|
107
|
+
*
|
|
108
|
+
* For newly extracted strings, there is no target text yet. There must be a target
|
|
109
|
+
* locale for the translators to use when creating new target text, however. This
|
|
110
|
+
* means that there may be multiple translation units in a file with the same
|
|
111
|
+
* source locale and no target text, but different target locales.
|
|
112
|
+
*
|
|
113
|
+
* @param {Object} options options for this unit
|
|
114
|
+
*/
|
|
115
|
+
constructor(options) {
|
|
116
|
+
// this.locale = options.locale; -> sourceLocale
|
|
117
|
+
// this.string = options.string; -> source
|
|
118
|
+
// this.datatype = options.datatype; -> datatype
|
|
119
|
+
|
|
120
|
+
this.variants = [];
|
|
121
|
+
this.variantHash = {};
|
|
122
|
+
this.properties = {};
|
|
123
|
+
|
|
124
|
+
if (options) {
|
|
125
|
+
const requiredFields = ["source", "sourceLocale"];
|
|
126
|
+
const missing = requiredFields.filter(p => {
|
|
127
|
+
if (typeof(options[p]) !== "undefined") {
|
|
128
|
+
this[p] = options[p];
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
133
|
+
// logger.trace("options is " + JSON.stringify(options));
|
|
134
|
+
if (missing.length) {
|
|
135
|
+
throw new Error("Missing required parameters in the TranslationUnit constructor: " + missing.join(", "));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const otherFields = ["key", "file", "project", "target", "targetLocale", "resType", "state", "comment", "datatype", "flavor"];
|
|
139
|
+
for (var p of otherFields) {
|
|
140
|
+
this[p] = options[p];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Clone the current unit and return the clone.
|
|
147
|
+
* @returns {TranslationUnit} a clone of the current unit.
|
|
148
|
+
*/
|
|
149
|
+
clone() {
|
|
150
|
+
return new TranslationUnit(this);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Return a unique hash key for this translation unit. The
|
|
155
|
+
* hash key is calculated from the source string and locale
|
|
156
|
+
* and does not depend on the properties or variants in
|
|
157
|
+
* the unit.
|
|
158
|
+
*
|
|
159
|
+
* @returns {string} the unique hash key
|
|
160
|
+
*/
|
|
161
|
+
hashKey() {
|
|
162
|
+
return [hashKey(this.source), this.sourceLocale, this.datatype].join("_");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Return the list of variants for this translation unit.
|
|
167
|
+
* @returns {Array.<TranslationVariant>} the variants for
|
|
168
|
+
* this translation unit
|
|
169
|
+
*/
|
|
170
|
+
getVariants() {
|
|
171
|
+
return this.variants;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Add a single variant to this translation unit. This variant
|
|
176
|
+
* is only added if it is unique in this translation unit. That is,
|
|
177
|
+
* No other variant exists in this unit with the same locale and
|
|
178
|
+
* string.
|
|
179
|
+
*
|
|
180
|
+
* @param {TranslationVariant} variant the variant to add
|
|
181
|
+
*/
|
|
182
|
+
addVariant(variant) {
|
|
183
|
+
var key = variant.hashKey();
|
|
184
|
+
if (!this.variantHash[key]) {
|
|
185
|
+
this.variants.push(variant);
|
|
186
|
+
this.variantHash[key] = variant;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Add an array of variants to this translation unit. This only
|
|
192
|
+
* adds a variant if it is unique. That is, the unit is not
|
|
193
|
+
* added if the locale and string are the same as an existing
|
|
194
|
+
* variant.
|
|
195
|
+
*
|
|
196
|
+
* @param {Array.<TranslationVariant>} variants the array of variants to add
|
|
197
|
+
*/
|
|
198
|
+
addVariants(variants) {
|
|
199
|
+
variants.forEach(variant => {
|
|
200
|
+
this.addVariant(variant);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Return the list of properties and their values for this translation unit.
|
|
206
|
+
* @returns {Object} an object mapping properties to values
|
|
207
|
+
*/
|
|
208
|
+
getProperties() {
|
|
209
|
+
return this.properties;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Add a property to this translation unit.
|
|
214
|
+
* @param {Object} properties an object that maps properties to values
|
|
215
|
+
*/
|
|
216
|
+
addProperties(properties) {
|
|
217
|
+
for (let p in properties) {
|
|
218
|
+
if (properties[p]) {
|
|
219
|
+
this.properties[p] = properties[p];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export default TranslationUnit;</code></pre>
|
|
226
|
+
</article>
|
|
227
|
+
</section>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<br class="clear">
|
|
237
|
+
|
|
238
|
+
<footer>
|
|
239
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.0</a> on Tue Jan 24 2023 22:21:49 GMT-0800 (Pacific Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
240
|
+
</footer>
|
|
241
|
+
|
|
242
|
+
<script>prettyPrint();</script>
|
|
243
|
+
<script src="scripts/polyfill.js"></script>
|
|
244
|
+
<script src="scripts/linenumber.js"></script>
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
</body>
|
|
249
|
+
</html>
|