Skip to content
Snippets Groups Projects
Verified Commit 8537a716 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: add instance getter

parent 1095b776
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import { internalSymbol } from "../constants.mjs"; import {instanceSymbol, internalSymbol} from "../constants.mjs";
import {extend} from "../data/extend.mjs"; import {extend} from "../data/extend.mjs";
import {Formatter as TextFormatter} from "../text/formatter.mjs"; import {Formatter as TextFormatter} from "../text/formatter.mjs";
...@@ -41,6 +41,15 @@ class Formatter extends TextFormatter { ...@@ -41,6 +41,15 @@ class Formatter extends TextFormatter {
this[internalTranslationSymbol] = validateInstance(translation, Translations); this[internalTranslationSymbol] = validateInstance(translation, Translations);
} }
/**
* This method is called by the `instanceof` operator.
* @returns {symbol}
* @since 3.27.0
*/
static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/i18n/formatter@@instance");
}
/** /**
* @property {object} marker * @property {object} marker
* @property {array} marker.open=["i18n{","${"] * @property {array} marker.open=["i18n{","${"]
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import {instanceSymbol} from "../constants.mjs";
import { Base } from "../types/base.mjs"; import { Base } from "../types/base.mjs";
import { validateString } from "../types/validate.mjs"; import { validateString } from "../types/validate.mjs";
import { clone } from "../util/clone.mjs"; import { clone } from "../util/clone.mjs";
...@@ -100,6 +101,15 @@ class Locale extends Base { ...@@ -100,6 +101,15 @@ class Locale extends Base {
this[localeStringSymbol] = s.join("-"); this[localeStringSymbol] = s.join("-");
} }
/**
* This method is called by the `instanceof` operator.
* @returns {symbol}
* @since 3.27.0
*/
static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/i18n/locale@@instance");
}
/** /**
* @return {string} * @return {string}
*/ */
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import {instanceSymbol} from "../constants.mjs";
import {hasObjectLink, getLinkedObjects,addToObjectLink} from "../dom/attributes.mjs"; import {hasObjectLink, getLinkedObjects,addToObjectLink} from "../dom/attributes.mjs";
import {getLocaleOfDocument} from "../dom/locale.mjs"; import {getLocaleOfDocument} from "../dom/locale.mjs";
import {BaseWithOptions} from "../types/basewithoptions.mjs"; import {BaseWithOptions} from "../types/basewithoptions.mjs";
...@@ -32,6 +33,16 @@ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@l ...@@ -32,6 +33,16 @@ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@l
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066} * @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
*/ */
class Provider extends BaseWithOptions { class Provider extends BaseWithOptions {
/**
* This method is called by the `instanceof` operator.
* @returns {symbol}
* @since 3.27.0
*/
static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/i18n/provider@@instance");
}
/** /**
* @param {Locale|string} locale * @param {Locale|string} locale
* @return {Promise} * @return {Promise}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/ */
import {instanceSymbol} from "../constants.mjs";
import {getLinkedObjects, hasObjectLink} from "../dom/attributes.mjs"; import {getLinkedObjects, hasObjectLink} from "../dom/attributes.mjs";
import {ATTRIBUTE_OBJECTLINK} from "../dom/constants.mjs"; import {ATTRIBUTE_OBJECTLINK} from "../dom/constants.mjs";
import {getDocument} from "../dom/util.mjs"; import {getDocument} from "../dom/util.mjs";
...@@ -44,6 +45,15 @@ class Translations extends Base { ...@@ -44,6 +45,15 @@ class Translations extends Base {
this.storage = new Map(); this.storage = new Map();
} }
/**
* This method is called by the `instanceof` operator.
* @returns {symbol}
* @since 3.27.0
*/
static get [instanceSymbol]() {
return Symbol.for("@schukai/monster/i18n/translations@@instance");
}
/** /**
* Fetches a text using the specified key. * Fetches a text using the specified key.
* If no suitable key is found, `defaultText` is taken. * If no suitable key is found, `defaultText` is taken.
...@@ -107,9 +117,11 @@ class Translations extends Base { ...@@ -107,9 +117,11 @@ class Translations extends Base {
return validateString(r[keyword]); return validateString(r[keyword]);
} }
if (r.hasOwnProperty(DEFAULT_KEY)) { // @deprecated since 2023-03-14
return validateString(r[DEFAULT_KEY]); // DEFAULT_KEY is undefined
} // if (r.hasOwnProperty(DEFAULT_KEY)) {
// return validateString(r[DEFAULT_KEY]);
// }
return validateString(defaultText); return validateString(defaultText);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment