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

chore: commit save point

parent 11736bbc
No related branches found
No related tags found
No related merge requests found
import {Formatter} from '@schukai/monster/source/i18n/formatter.mjs';
import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
const translations = new Translations('en')
.assignTranslations({
thekey: "${animal} has eaten the ${food}!"
});
new Formatter({}, translations).format("thekey:animal=dog::food=cake")
// ↦ dog has eaten the cake!
import {Fetch} from '@schukai/monster/source/i18n/providers/fetch.mjs';
// fetch from API
const translation = new Fetch('https://example.com/${language}.json').getTranslation('en-GB');
// ↦ https://example.com/en.json
import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
import {parseLocale} from '@schukai/monster/source/i18n/locale.mjs';
const translation = new Translations(parseLocale('en-GB'));
translation.assignTranslations({
text1: "click",
text2: {
'one': 'click once',
'other': 'click n times'
}
});
console.log(translation.getText('text1'));
// ↦ click
console.log(translation.getPluralRuleText('text2', 1));
// -> click once
console.log(translation.getPluralRuleText('text2', 2));
// -> click n times
/** /**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster * Node module: @schukai/monster
...@@ -7,8 +5,6 @@ ...@@ -7,8 +5,6 @@
* 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 {internalSymbol} from "../constants.mjs";
import {extend} from "../data/extend.mjs"; import {extend} from "../data/extend.mjs";
...@@ -27,26 +23,7 @@ const internalTranslationSymbol = Symbol('internalTranslation') ...@@ -27,26 +23,7 @@ const internalTranslationSymbol = Symbol('internalTranslation')
/** /**
* The Formatter extends the Text.Formatter with the possibility to replace the key by a translation. * The Formatter extends the Text.Formatter with the possibility to replace the key by a translation.
* *
* ``` * @externalExample ../../example/i18n/formatter.mjs
* <script type="module">
* import {Formatter} from '@schukai/monster/source/i18n/formatter.mjs';
* new Formatter()
* </script>
* ```
*
* @example
*
* import {Formatter} from '@schukai/monster/source/i18n/formatter.mjs';
* import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
*
* const translations = new Translations('en')
* .assignTranslations({
* thekey: "${animal} has eaten the ${food}!"
* });
*
* new Formatter({}, translations).format("thekey:animal=dog::food=cake")
* // ↦ dog has eaten the cake!
*
* @license AGPLv3 * @license AGPLv3
* @since 1.26.0 * @since 1.26.0
* @copyright schukai GmbH * @copyright schukai GmbH
...@@ -115,7 +92,6 @@ class Formatter extends TextFormatter { ...@@ -115,7 +92,6 @@ class Formatter extends TextFormatter {
} }
} }
const parts = validateString(text).split('::') const parts = validateString(text).split('::')
const translationKey = parts.shift().trim(); // key value delimiter const translationKey = parts.shift().trim(); // key value delimiter
const parameter = parts.join('::').trim(); const parameter = parts.join('::').trim();
......
/** /**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster * Node module: @schukai/monster
...@@ -7,7 +5,6 @@ ...@@ -7,7 +5,6 @@
* 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 {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";
...@@ -29,13 +26,6 @@ const localeStringSymbol = Symbol('localeString'); ...@@ -29,13 +26,6 @@ const localeStringSymbol = Symbol('localeString');
/** /**
* The Locale class is a base class for the language classes. * The Locale class is a base class for the language classes.
* *
* ```
* <script type="module">
* import {Locale} from '@schukai/monster/source/i18n/locale.mjs';
* new Locale()
* </script>
* ```
*
* RFC * RFC
* *
* ``` * ```
......
/** /**
* In this namespace you will find classes and methods for handling locale and localized texts. * In this namespace you will find classes and methods for handling locale and localized texts.
* *
......
/** /**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster * Node module: @schukai/monster
...@@ -7,7 +5,6 @@ ...@@ -7,7 +5,6 @@
* 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 {BaseWithOptions} from "../types/basewithoptions.mjs"; import {BaseWithOptions} from "../types/basewithoptions.mjs";
import {Locale} from "./locale.mjs" import {Locale} from "./locale.mjs"
import {Translations} from "./translations.mjs" import {Translations} from "./translations.mjs"
...@@ -17,13 +14,6 @@ export {Provider} ...@@ -17,13 +14,6 @@ export {Provider}
/** /**
* A provider makes a translation object available. * A provider makes a translation object available.
* *
* ```
* <script type="module">
* import {Provider} from '@schukai/monster/source/i18n/provider.mjs';
* new Provider()
* </script>
* ```
*
* @license AGPLv3 * @license AGPLv3
* @since 1.13.0 * @since 1.13.0
* @copyright schukai GmbH * @copyright schukai GmbH
......
/** /**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster * Node module: @schukai/monster
...@@ -7,7 +5,6 @@ ...@@ -7,7 +5,6 @@
* 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 {internalSymbol} from "../../constants.mjs";
import {extend} from "../../data/extend.mjs"; import {extend} from "../../data/extend.mjs";
import {Formatter} from "../../text/formatter.mjs"; import {Formatter} from "../../text/formatter.mjs";
...@@ -23,21 +20,7 @@ export {Fetch} ...@@ -23,21 +20,7 @@ export {Fetch}
/** /**
* The fetch provider retrieves a JSON file from the given URL and returns a translation object. * The fetch provider retrieves a JSON file from the given URL and returns a translation object.
* *
* ``` * @externalExample ../../example/i18n/providers/fetch.mjs
* <script type="module">
* import {Fetch} from '@schukai/monster/source/i18n/providers/fetch.mjs';
* new Fetch()
* </script>
* ```
*
* @example <caption>das ist ein test</caption>
*
* import {Fetch} from '@schukai/monster/source/i18n/providers/fetch.mjs';
*
* // fetch from API
* const translation = new Fetch('https://example.com/${language}.json').getTranslation('en-GB');
* // ↦ https://example.com/en.json
*
* @license AGPLv3 * @license AGPLv3
* @since 1.13.0 * @since 1.13.0
* @copyright schukai GmbH * @copyright schukai GmbH
......
/** /**
* In this namespace you will find classes and methods for handling locale and localized texts. * In this namespace you will find classes and methods for handling locale and localized texts.
* *
......
/** /**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster * Node module: @schukai/monster
...@@ -7,7 +5,6 @@ ...@@ -7,7 +5,6 @@
* 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 {Base} from "../types/base.mjs"; import {Base} from "../types/base.mjs";
import {isObject, isString} from "../types/is.mjs"; import {isObject, isString} from "../types/is.mjs";
import {validateInstance, validateInteger, validateObject, validateString} from "../types/validate.mjs"; import {validateInstance, validateInteger, validateObject, validateString} from "../types/validate.mjs";
...@@ -18,36 +15,7 @@ export {Translations} ...@@ -18,36 +15,7 @@ export {Translations}
/** /**
* With this class you can manage translations and access the keys. * With this class you can manage translations and access the keys.
* *
* ``` * @externalExample ../../example/i18n/translations.mjs
* <script type="module">
* import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
* new Translations()
* </script>
* ```
*
* @example
*
* import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
* import {parseLocale} from '@schukai/monster/source/i18n/locale.mjs';
*
* const translation = new Translations(parseLocale('en-GB'));
*
* translation.assignTranslations({
* text1: "click",
* text2: {
* 'one': 'click once',
* 'other': 'click n times'
* }
* });
*
* console.log(translation.getText('text1'));
* // ↦ click
*
* console.log(translation.getPluralRuleText('text2',1));
* // -> click once
* console.log(translation.getPluralRuleText('text2',2));
* // -> click n times
*
* @license AGPLv3 * @license AGPLv3
* @since 1.13.0 * @since 1.13.0
* @copyright schukai GmbH * @copyright schukai GmbH
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment