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

feat: new internal Translation

parent 794d42b2
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,4 @@
commit = "cbc74f88e513f20e72635f63627bffbcbe69d607";
name = "Monster";
mnemonic = "monster";
}
\ No newline at end of file
}
......@@ -19,6 +19,7 @@ import { Server } from "../server.mjs";
import { WriteError } from "./restapi/writeerror.mjs";
import { DataFetchError } from "./restapi/data-fetch-error.mjs";
import { clone } from "../../../util/clone.mjs";
import {getInternalLocalizationMessage} from "../../../i18n/internal.mjs";
export { RestAPI };
......@@ -224,7 +225,9 @@ function fetchData(init, key, callback) {
if (acceptedStatus.indexOf(resp.status) === -1) {
throw new DataFetchError(
`the response does not contain an accepted status (actual: ${resp.status}).`,
getInternalLocalizationMessage(
`i18n{the-response-does-not-contain-an-accepted-status::status=${resp.status}}`
),
response,
);
}
......@@ -244,7 +247,9 @@ function fetchData(init, key, callback) {
}
throw new DataFetchError(
`the response does not contain a valid json (actual: ${body}).`,
getInternalLocalizationMessage(
`i18n{the-response-does-not-contain-a-valid-json::actual=${body}}`
),
response,
);
}
......
......@@ -39,6 +39,8 @@ class Formatter extends TextFormatter {
* Default values for the markers are `${` and `}`
*
* @param {object} object
* @param {Translations} translation
* @param {object} [options]
* @throws {TypeError} value is not a object
*/
constructor(object, translation, options) {
......
/**
* Copyright © schukai GmbH and all contributing authors, {{copyRightYear}}. All rights reserved.
* Node module: @schukai/monster
*
* This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
* The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
*
* For those who do not wish to adhere to the AGPLv3, a commercial license is available.
* Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
* For more information about purchasing a commercial license, please contact schukai GmbH.
*
* SPDX-License-Identifier: AGPL-3.0
*/
import {Formatter} from "./formatter.mjs";
import {getLocaleOfDocument} from "../dom/locale.mjs";
import {Translations} from "./translations.mjs";
export {getInternalLocalizationMessage};
let internalTranslations = null;
getInternalTranslations();
function getInternalTranslations() {
if (internalTranslations) {
return internalTranslations;
}
let locale = "en";
try {
let locale = getLocaleOfDocument();
} catch (error) {
}
let messages = {};
switch (locale.language) {
case "de":
messages = {
"the-response-does-not-contain-an-accepted-status": `Der Server hat die Anfrage nicht akzeptiert (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `Die Antwort des Servers ist kein gültiges JSON (actual=\${actual}).`,
};
break;
case "es":
messages = {
"the-response-does-not-contain-an-accepted-status": `El servidor no ha aceptado la solicitud (Estado \${status}).`,
"the-response-does-not-contain-a-valid-json": `La respuesta del servidor no es un JSON válido (actual=\${actual}).`,
};
break;
case "zh":
messages = {
"the-response-does-not-contain-an-accepted-status": `服务器未接受请求(状态 \${status})。`,
"the-response-does-not-contain-a-valid-json": `服务器响应不是有效的JSON(实际=\${actual})。`,
};
break;
case "fr":
messages = {
"the-response-does-not-contain-an-accepted-status": `Le serveur n'a pas accepté la demande (Statut \${status}).`,
"the-response-does-not-contain-a-valid-json": `La réponse du serveur n'est pas un JSON valide (actuel=\${actual}).`,
};
break;
case "it":
messages = {
"the-response-does-not-contain-an-accepted-status": `Il server non ha accettato la richiesta (Stato \${status}).`,
"the-response-does-not-contain-a-valid-json": `La risposta del server non è un JSON valido (attuale=\${actual}).`,
};
break;
case "nl":
messages = {
"the-response-does-not-contain-an-accepted-status": `De server heeft het verzoek niet geaccepteerd (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `De serverrespons is geen geldige JSON (actueel=\${actual}).`,
};
break;
case "sv":
messages = {
"the-response-does-not-contain-an-accepted-status": `Servern accepterade inte begäran (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `Serverns svar är inte en giltig JSON (faktisk=\${actual}).`,
};
break;
case "pl":
messages = {
"the-response-does-not-contain-an-accepted-status": `Serwer nie zaakceptował żądania (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `Odpowiedź serwera nie jest prawidłowym JSON-em (aktualne=\${actual}).`,
};
break;
case "da":
messages = {
"the-response-does-not-contain-an-accepted-status": `Serveren accepterede ikke forespørgslen (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `Serverens svar er ikke en gyldig JSON (aktuel=\${actual}).`,
};
break;
case "fi":
messages = {
"the-response-does-not-contain-an-accepted-status": `Palvelin ei hyväksynyt pyyntöä (Tila \${status}).`,
"the-response-does-not-contain-a-valid-json": `Palvelimen vastaus ei ole kelvollinen JSON (todellinen=\${actual}).`,
};
break;
case "no":
messages = {
"the-response-does-not-contain-an-accepted-status": `Serveren aksepterte ikke forespørselen (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `Serverens respons er ikke en gyldig JSON (faktisk=\${actual}).`,
};
break;
case "cs":
messages = {
"the-response-does-not-contain-an-accepted-status": `Server nepřijal požadavek (Stav \${status}).`,
"the-response-does-not-contain-a-valid-json": `Odpověď serveru není platný JSON (skutečný=\${actual}).`,
};
break;
default: // English
messages = {
"the-response-does-not-contain-an-accepted-status": `The server did not accept the request (Status \${status}).`,
"the-response-does-not-contain-a-valid-json": `The server response is not a valid JSON (actual=\${actual}).`,
};
}
const translation = new Translations(locale);
translation.assignTranslations(messages);
internalTranslations = translation;
return translation
}
/**
* Returns the internal localization message.
* @param message
* @returns {string}
*/
function getInternalLocalizationMessage(message) {
const formatter = new Formatter({}, getInternalTranslations());
return formatter.format(message);
}
......@@ -12,6 +12,35 @@
* SPDX-License-Identifier: AGPL-3.0
*/
/**
* Curretnly from Monster supported languages.
* @type {string[]}
*/
export const currentSupportedLanguages = [
"en", // English
"de", // German
"es", // Spanish
"zh", // Mandarin
"hi", // Hindi
"bn", // Bengali
"pt", // Portuguese
"ru", // Russian
"ja", // Japanese
"pa", // Western Punjabi
"mr", // Marathi
"fr", // French
"it", // Italian
"nl", // Dutch
"sv", // Swedish
"pl", // Polish
"da", // Danish
"fi", // Finnish
"no", // Norwegian
"cs" // Czech
];
export const languages = {
en: "English",
"en-GB": "English (United Kingdom)",
......
......@@ -13,12 +13,12 @@
*/
import {
validateFunction,
validateObject,
validateString,
validateFunction,
validateObject,
validateString,
} from "./validate.mjs";
export { getGlobal, getGlobalObject, getGlobalFunction };
export {getGlobal, getGlobalObject, getGlobalFunction};
/**
* @type {object}
......@@ -31,39 +31,40 @@ let globalReference;
* @throws {Error} unsupported environment.
*/
(function () {
if (typeof globalThis === "object") {
globalReference = globalThis;
return;
}
if (typeof globalThis === "object") {
globalReference = globalThis;
return;
}
if (typeof self !== "undefined") {
globalReference = self;
return;
} else if (typeof window !== "undefined") {
globalReference = window;
return;
}
if (typeof self !== "undefined") {
globalReference = self;
return;
} else if (typeof window !== "undefined") {
globalReference = window;
return;
}
Object.defineProperty(Object.prototype, "__monster__", {
get: function () {
return this;
},
configurable: true,
});
Object.defineProperty(Object.prototype, "__monster__", {
get: function () {
return this;
},
configurable: true,
});
if (typeof __monster__ === "object") {
__monster__.globalThis = __monster__;
delete Object.prototype.__monster__;
if (typeof __monster__ === "object") {
__monster__.globalThis = __monster__;
delete Object.prototype.__monster__;
globalReference = globalThis;
return;
}
globalReference = globalThis;
return;
}
try {
globalReference = Function("return this")();
} catch (e) {}
try {
globalReference = Function("return this")();
} catch (e) {
}
throw new Error("unsupported environment.");
throw new Error("unsupported environment.");
})();
/**
......@@ -76,7 +77,7 @@ let globalReference;
* @return {object} globalThis
*/
function getGlobal() {
return globalReference;
return globalReference;
}
/**
......@@ -111,12 +112,12 @@ function getGlobal() {
* @throws {TypeError} value is not a string
*/
function getGlobalObject(name) {
validateString(name);
const o = globalReference?.[name];
if (typeof o === "undefined")
throw new Error(`the object ${name} is not defined`);
validateObject(o);
return o;
validateString(name);
const o = globalReference?.[name];
if (typeof o === "undefined")
throw new Error(`the object ${name} is not defined`);
validateObject(o);
return o;
}
/**
......@@ -149,10 +150,11 @@ function getGlobalObject(name) {
* @throws {TypeError} value is not a string
*/
function getGlobalFunction(name) {
validateString(name);
const f = globalReference?.[name];
if (typeof f === "undefined")
throw new Error(`the function ${name} is not defined`);
validateFunction(f);
return f;
validateString(name);
const f = globalReference?.[name];
if (typeof f === "undefined") {
throw new Error(`the function ${name} is not defined`);
}
validateFunction(f);
return f;
}
......@@ -156,7 +156,7 @@ function getMonsterVersion() {
}
/** don't touch, replaced by make with package.json version */
monsterVersion = new Version("3.102.6");
monsterVersion = new Version("3.104.1");
return monsterVersion;
}
......@@ -7,7 +7,7 @@ describe('Monster', function () {
let monsterVersion
/** don´t touch, replaced by make with package.json version */
monsterVersion = new Version("3.102.6")
monsterVersion = new Version("3.104.1")
let m = getMonsterVersion();
......
......@@ -9,8 +9,8 @@
</head>
<body>
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
<h1 style='margin-bottom: 0.1em;'>Monster 3.102.6</h1>
<div id="lastupdate" style='font-size:0.7em'>last update So 2. Feb 23:18:18 CET 2025</div>
<h1 style='margin-bottom: 0.1em;'>Monster 3.104.1</h1>
<div id="lastupdate" style='font-size:0.7em'>last update Mi 5. Feb 19:28:33 CET 2025</div>
</div>
<div id="mocha-errors"
style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment