@schukai/monster 3.26.0 → 3.27.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/package.json
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { internalSymbol
|
|
9
|
-
import {
|
|
8
|
+
import {instanceSymbol, internalSymbol} from "../constants.mjs";
|
|
9
|
+
import {extend} from "../data/extend.mjs";
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import {Formatter as TextFormatter} from "../text/formatter.mjs";
|
|
12
|
+
import {validateInstance, validateString} from "../types/validate.mjs";
|
|
13
|
+
import {Translations} from "./translations.mjs";
|
|
14
14
|
|
|
15
|
-
export {
|
|
15
|
+
export {Formatter};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @private
|
|
@@ -41,6 +41,15 @@ class Formatter extends TextFormatter {
|
|
|
41
41
|
this[internalTranslationSymbol] = validateInstance(translation, Translations);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* This method is called by the `instanceof` operator.
|
|
46
|
+
* @returns {symbol}
|
|
47
|
+
* @since 3.27.0
|
|
48
|
+
*/
|
|
49
|
+
static get [instanceSymbol]() {
|
|
50
|
+
return Symbol.for("@schukai/monster/i18n/formatter@@instance");
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
/**
|
|
45
54
|
* @property {object} marker
|
|
46
55
|
* @property {array} marker.open=["i18n{","${"]
|
package/source/i18n/locale.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {instanceSymbol} from "../constants.mjs";
|
|
8
9
|
import { Base } from "../types/base.mjs";
|
|
9
10
|
import { validateString } from "../types/validate.mjs";
|
|
10
11
|
import { clone } from "../util/clone.mjs";
|
|
@@ -100,6 +101,15 @@ class Locale extends Base {
|
|
|
100
101
|
this[localeStringSymbol] = s.join("-");
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
/**
|
|
105
|
+
* This method is called by the `instanceof` operator.
|
|
106
|
+
* @returns {symbol}
|
|
107
|
+
* @since 3.27.0
|
|
108
|
+
*/
|
|
109
|
+
static get [instanceSymbol]() {
|
|
110
|
+
return Symbol.for("@schukai/monster/i18n/locale@@instance");
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
/**
|
|
104
114
|
* @return {string}
|
|
105
115
|
*/
|
package/source/i18n/provider.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {instanceSymbol} from "../constants.mjs";
|
|
8
9
|
import {hasObjectLink, getLinkedObjects,addToObjectLink} from "../dom/attributes.mjs";
|
|
9
10
|
import {getLocaleOfDocument} from "../dom/locale.mjs";
|
|
10
11
|
import {BaseWithOptions} from "../types/basewithoptions.mjs";
|
|
@@ -32,6 +33,16 @@ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@l
|
|
|
32
33
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
|
|
33
34
|
*/
|
|
34
35
|
class Provider extends BaseWithOptions {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This method is called by the `instanceof` operator.
|
|
39
|
+
* @returns {symbol}
|
|
40
|
+
* @since 3.27.0
|
|
41
|
+
*/
|
|
42
|
+
static get [instanceSymbol]() {
|
|
43
|
+
return Symbol.for("@schukai/monster/i18n/provider@@instance");
|
|
44
|
+
}
|
|
45
|
+
|
|
35
46
|
/**
|
|
36
47
|
* @param {Locale|string} locale
|
|
37
48
|
* @return {Promise}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {instanceSymbol} from "../constants.mjs";
|
|
9
|
+
import {getLinkedObjects, hasObjectLink} from "../dom/attributes.mjs";
|
|
9
10
|
import {ATTRIBUTE_OBJECTLINK} from "../dom/constants.mjs";
|
|
10
11
|
import {getDocument} from "../dom/util.mjs";
|
|
11
12
|
import {Base} from "../types/base.mjs";
|
|
@@ -44,6 +45,15 @@ class Translations extends Base {
|
|
|
44
45
|
this.storage = new Map();
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* This method is called by the `instanceof` operator.
|
|
50
|
+
* @returns {symbol}
|
|
51
|
+
* @since 3.27.0
|
|
52
|
+
*/
|
|
53
|
+
static get [instanceSymbol]() {
|
|
54
|
+
return Symbol.for("@schukai/monster/i18n/translations@@instance");
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
/**
|
|
48
58
|
* Fetches a text using the specified key.
|
|
49
59
|
* If no suitable key is found, `defaultText` is taken.
|
|
@@ -107,9 +117,11 @@ class Translations extends Base {
|
|
|
107
117
|
return validateString(r[keyword]);
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
// @deprecated since 2023-03-14
|
|
121
|
+
// DEFAULT_KEY is undefined
|
|
122
|
+
// if (r.hasOwnProperty(DEFAULT_KEY)) {
|
|
123
|
+
// return validateString(r[DEFAULT_KEY]);
|
|
124
|
+
// }
|
|
113
125
|
|
|
114
126
|
return validateString(defaultText);
|
|
115
127
|
}
|
|
@@ -171,7 +183,7 @@ class Translations extends Base {
|
|
|
171
183
|
*/
|
|
172
184
|
assignTranslations(translations) {
|
|
173
185
|
validateObject(translations);
|
|
174
|
-
|
|
186
|
+
|
|
175
187
|
if (translations instanceof Translations) {
|
|
176
188
|
translations.storage.forEach((v, k) => {
|
|
177
189
|
this.setText(k, v);
|
|
@@ -202,7 +214,7 @@ function getDocumentTranslations(element) {
|
|
|
202
214
|
const d = getDocument()
|
|
203
215
|
|
|
204
216
|
if (!(element instanceof HTMLElement)) {
|
|
205
|
-
element = d.querySelector('['+ATTRIBUTE_OBJECTLINK+'~="' + translationsLinkSymbol.toString() + '"]');
|
|
217
|
+
element = d.querySelector('[' + ATTRIBUTE_OBJECTLINK + '~="' + translationsLinkSymbol.toString() + '"]');
|
|
206
218
|
if (element === null) {
|
|
207
219
|
throw new Error("Cannot find element with translations. Add a translations object to the document.");
|
|
208
220
|
}
|
|
@@ -215,9 +227,9 @@ function getDocumentTranslations(element) {
|
|
|
215
227
|
if (!hasObjectLink(element, translationsLinkSymbol)) {
|
|
216
228
|
throw new Error("This element has no translations.");
|
|
217
229
|
}
|
|
218
|
-
|
|
230
|
+
|
|
219
231
|
let obj = getLinkedObjects(element, translationsLinkSymbol);
|
|
220
|
-
|
|
232
|
+
|
|
221
233
|
for (const t of obj) {
|
|
222
234
|
if (t instanceof Translations) {
|
|
223
235
|
return t;
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED