Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
Loading items
Show changes
Commits on Source (9)
Showing
with 608 additions and 426 deletions
<a name="v3.5.0"></a>
## [v3.5.0] - 2023-01-23
### Add Features
- check the navigator languages too
- new embed i18n provider
### Bug Fixes
- doc
### Changes
- update packages
- update makefiles
- move tutorials to monsterjs-org
<a name="v3.4.2"></a>
## [v3.4.2] - 2023-01-15
### Bug Fixes
......@@ -188,6 +203,7 @@
<a name="1.8.0"></a>
## 1.8.0 - 2021-08-15
[v3.5.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.4.2...v3.5.0
[v3.4.2]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.4.1...v3.4.2
[v3.4.1]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.4.0...v3.4.1
[v3.4.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.3.0...v3.4.0
......
import {Embed} from '@schukai/monster/source/i18n/providers/embed.mjs';
// read from scritp tag with id i18n
const translation = new Embed('i18n');
{
"name": "@schukai/monster",
"version": "3.4.1",
"version": "3.4.2",
"description": "Monster is a simple library for creating fast, robust and lightweight websites.",
"keywords": [
"framework",
......
......@@ -81,7 +81,7 @@ class Server extends Datasource {
/**
*
* @private
* @param self
* @param obj
* @returns {*}
......
......@@ -6,8 +6,8 @@
*/
import {parseLocale} from "../i18n/locale.mjs";
import {getDocument} from "./util.mjs";
import {getGlobalObject} from "../types/global.mjs";
export {getLocaleOfDocument}
......@@ -47,5 +47,39 @@ function getLocaleOfDocument() {
}
}
let navigatorLanguage = getNavigatorLanguage();
if (navigatorLanguage) {
return parseLocale(navigatorLanguage);
}
return parseLocale(DEFAULT_LANGUAGE);
}
/**
* @private
* @returns {string|undefined|*}
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages
*/
const getNavigatorLanguage = () => {
const navigator = getGlobalObject('navigator');
if (navigator === undefined) {
return undefined;
}
if (navigator.hasOwnProperty('language')) {
const language = navigator.language;
if (typeof language === 'string' && language.length > 0) {
return language;
}
}
const languages = navigator?.languages;
if (Array.isArray(languages) && languages.length>0) {
return languages[0];
}
return undefined;
}
/**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster
* This file is licensed under the AGPLv3 License.
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/
import {internalSymbol} from "../../constants.mjs";
import {extend} from "../../data/extend.mjs";
import { getGlobalObject} from "../../types/global.mjs";
import {isString} from "../../types/is.mjs";
import {validateObject, validateString} from "../../types/validate.mjs";
import {parseLocale} from "../locale.mjs";
import {Provider} from "../provider.mjs";
import {Translations} from "../translations.mjs";
export {Embed}
/**
* The Embed provider retrieves a JSON file from the given Script Tag.
*
* @externalExample ../../../example/i18n/providers/embed.mjs
* @license AGPLv3
* @since 1.13.0
* @copyright schukai GmbH
* @memberOf Monster.I18n.Providers
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
* @tutorial i18n-locale-and-formatter
*/
class Embed extends Provider {
/**
* ```html
* <script id="translations" type="application/json">
* {
* "hello": "Hallo"
* }
* </script>
* ```
*
*
* ```javascript
* new Embed('translations')
* ```
*
* @param {string} id
* @param {Object} options
*/
constructor(id, options) {
super(options);
if (options === undefined) {
options = {};
}
validateString(id);
/**
* @property {string}
*/
this.textId = id;
/**
* @private
* @property {Object} options
*/
this[internalSymbol] = extend({}, super.defaults, this.defaults, validateObject(options));
}
/**
* Defaults
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
*/
get defaults() {
return extend({}, super.defaults);
}
/**
*
* @param {Locale|string} locale
* @return {Promise}
*/
getTranslations(locale) {
if (isString(locale)) {
locale = parseLocale(locale);
}
return new Promise((resolve, reject) => {
let text = getGlobalObject('document').getElementById(this.textId);
if (text === null) {
reject(new Error('Text not found'));
return;
}
let translations = null;
try {
translations = JSON.parse(text.innerHTML);
} catch (e) {
reject(e);
return;
}
if (translations === null) {
reject(new Error('Translations not found or invalid'));
return;
}
const t = new Translations(locale);
t.assignTranslations(translations)
resolve(t);
});
}
}
......@@ -84,7 +84,8 @@ export {Fetch}
*/
get defaults() {
return {
return extend(
{
fetch: {
method: 'GET', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
......@@ -93,7 +94,7 @@ export {Fetch}
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
}
}
}, super.defaults);
}
......
......@@ -142,13 +142,16 @@ class Translations extends Base {
}
/**
* This method can be used to transfer overlays from an object. The keys are transferred and the values are entered as text.
* This method can be used to transfer overlays from an object. The keys are transferred, and the values are entered
* as text.
*
* The values can either be character strings or, in the case of texts with plural forms, objects. The plural forms must be stored as text via a standard key "zero", "one", "two", "few", "many" and "other".
* The values can either be character strings or, in the case of texts with plural forms, objects. The plural forms
* must be stored as text via a standard key "zero", "one", "two", "few", "many" and "other".
*
* Additionally, the key default can be specified, which will be used if no other key fits.
*
* In some languages, like for example in german, there is no own more number at the value 0. In these languages the function applies additionally zero.
* In some languages, like for example in German, there is no own more number at the value 0. In these languages,
* the function applies additionally zero.
*
* ```
* translations.assignTranslations({
......
......@@ -149,7 +149,7 @@ function getMonsterVersion() {
}
/** don't touch, replaced by make with package.json version */
monsterVersion = new Version('3.4.1')
monsterVersion = new Version('3.4.2')
return monsterVersion;
......
......@@ -49,3 +49,9 @@ export CONANEXAMPLECONF
$(CONAN_CONFIG):
$(QUIET) $(ECHO) "$$CONANEXAMPLECONF" >> $@
$(CONAN_BIN):
$(QUIET) $(MKDIR) -p $(VENDOR_PATH)
$(QUIET) $(WGET) -O $(CONAN_BIN) http://download.schukai.com/tools/conan/conan-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`)
$(QUIET) $(CHMOD) u+x $(CONAN_BIN)
......@@ -10,6 +10,7 @@ APPLICATION_PATH ?= $(PROJECT_ROOT)
DEPLOYMENT_PATH ?= $(PROJECT_ROOT)
DEVELOPMENT_PATH ?= $(PROJECT_ROOT)
DOCUMENTATION_PATH ?= $(PROJECT_ROOT)
DOCUMENTATION_CONFIG_PATH ?= $(DOCUMENTATION_PATH)config/
RESOURCE_PATH ?= $(APPLICATION_PATH)
SOURCE_PATH ?= $(APPLICATION_PATH)
......
......@@ -10,6 +10,7 @@ APPLICATION_PATH ?= $(PROJECT_ROOT)application/
DEPLOYMENT_PATH ?= $(PROJECT_ROOT)deployment/
DEVELOPMENT_PATH ?= $(PROJECT_ROOT)development/
DOCUMENTATION_PATH ?= $(PROJECT_ROOT)documentation/
DOCUMENTATION_CONFIG_PATH ?= $(DOCUMENTATION_PATH)config/
RESOURCE_PATH ?= $(APPLICATION_PATH)resource/
SOURCE_PATH ?= $(APPLICATION_PATH)source/
......
......@@ -8,3 +8,12 @@
DOCMAN_BIN ?= $(VENDOR_PATH)docman
DOCMAN_CONFIG_PATH ?= $(DOCUMENTATION_CONFIG_PATH)docman.yaml
DOCMAN_HTML_ARTEFACT ?= $(PROJECT_ROOT)deployment/build/manual.html
DOCMAN_PDF_ARTEFACT ?= $(PROJECT_ROOT)deployment/build/manual.pdf
DOCMAN_SOURCE ?= $(shell find $(DOCUMENTATION_PATH) -type f)
$(DOCMAN_BIN):
$(QUIET) $(MKDIR) -p $(VENDOR_PATH)
$(QUIET) $(WGET) -O $(DOCMAN_BIN) http://download.schukai.com/tools/docman/docman-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`)
$(QUIET) $(CHMOD) u+x $(DOCMAN_BIN)
......@@ -19,5 +19,6 @@ $(CADDY_BIN):
.PHONY: run-caddy
## run caddy webserver
run-caddy: $(CADDY_BIN)
$(ECHOMARKER) "Run Caddy"
$(QUIET) $(CADDY_BIN) run -config $(CADDY_CONFIG) -pidfile $(CADDY_PIDFILE) -watch
......@@ -10,13 +10,8 @@ ifeq ($(CONAN_BIN),)
$(error $(ERRORMARKER) Conan is not defined, check your Makefile if conan.mk is included)
endif
$(CONAN_BIN):
$(QUIET) $(MKDIR) -p $(VENDOR_PATH)
$(QUIET) $(WGET) -O $(CONAN_BIN) http://download.schukai.com/tools/conan/conan-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`)
$(QUIET) $(CHMOD) u+x $(CONAN_BIN)
.PHONY: run-conan
## run conan webserver
run-conan: $(CONAN_BIN) $(CONAN_CONFIG)
$(ECHOMARKER) "Run Conan"
$(QUIET) $(CONAN_BIN) server serve --config $(CONAN_CONFIG)
......@@ -17,6 +17,7 @@ deploy: compile
.PHONY: overview-to-s3
## overview-to-s3
overview-to-s3:
$(ECHOMARKER) "Deploy to aws"
$(QUIET) AWS_PROFILE=$(AWS_PROFILE) $(AWS) s3 cp $(WEB_PATH)/index.html $(UPLOAD_TOOL_URL)
$(QUIET) AWS_PROFILE=$(AWS_PROFILE) $(AWS) s3 cp $(WEB_PATH)/index.css $(UPLOAD_TOOL_URL)
$(QUIET) AWS_PROFILE=$(AWS_PROFILE) $(AWS) s3 cp $(WEB_PATH)/index.js $(UPLOAD_TOOL_URL)
#############################################################################################
#############################################################################################
##
......@@ -11,28 +10,27 @@ ifeq ($(DOCMAN_BIN),)
$(error "$(DOCMAN_BIN) is not installed. Please check your makefile and include the docman.mk")
endif
$(DOCMAN_BIN):
$(QUIET) $(MKDIR) -p $(VENDOR_PATH)
$(QUIET) $(WGET) -O $(DOCMAN_BIN) http://download.schukai.com/tools/docman/docman-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`)
$(QUIET) $(CHMOD) u+x $(DOCMAN_BIN)
$(PROJECT_ROOT)deployment/build/manual.html: $(DOCMAN_BIN)
$(DOCMAN_BIN) document html --config $(PROJECT_ROOT)documentation/config.yaml
$(DOCMAN_HTML_ARTEFACT): $(DOCMAN_BIN) $(DOCMAN_SOURCE)
$(ECHOMARKER) "Build HTML Documentation"
$(QUIET) $(DOCMAN_BIN) document html --config $(DOCMAN_CONFIG_PATH)
$(PROJECT_ROOT)deployment/build/manual.pdf: $(DOCMAN_BIN)
$(DOCMAN_BIN) document pdf --config $(PROJECT_ROOT)documentation/config.yaml
$(DOCMAN_PDF_ARTEFACT): $(DOCMAN_BIN) $(DOCMAN_SOURCE)
$(ECHOMARKER) "Build PDF Documentation"
$(QUIET) $(DOCMAN_BIN) document pdf --config $(DOCMAN_CONFIG_PATH)
.PHONY: build-doc-pdf
## creating the documentation in pdf format
build-doc-pdf: $(PROJECT_ROOT)deployment/build/manual.pdf
build-doc-pdf: $(DOCMAN_PDF_ARTEFACT)
.PHONY: build-doc-html
## creating the documentation in html format
build-doc-html: $(PROJECT_ROOT)deployment/build/manual.html
build-doc-html: $(DOCMAN_HTML_ARTEFACT)
.PHONY: build-doc
## creating the documentation in pdf and html format
build-doc: build-doc-pdf build-doc-html
{
"name": "monster",
"version": "3.4.1",
"version": "3.4.2",
"description": "monster",
"repository": {
"type": "git",
......@@ -25,24 +25,24 @@
"c8": "^7.12.0",
"chai": "^4.3.7",
"chai-dom": "^1.11.0",
"clean-jsdoc-theme": "^4.2.2",
"clean-jsdoc-theme": "^4.2.3",
"create-polyfill-service-url": "^2.2.6",
"crypt": "^0.0.2",
"esbuild": "^0.14.54",
"flow-bin": "^0.184.0",
"esbuild": "^0.17.4",
"flow-bin": "^0.198.1",
"fs": "0.0.1-security",
"graphviz": "^0.0.9",
"jsdoc": "^3.6.11",
"jsdoc": "^4.0.0",
"jsdoc-external-example": "github:volker-schukai/jsdoc-external-example",
"jsdoc-plantuml": "^1.0.2",
"jsdom": "^19.0.0",
"jsdom": "^21.1.0",
"jsdom-global": "^3.0.2",
"mocha": "^10.2.0",
"node-plantuml": "^0.9.0",
"sinon": "^14.0.2",
"sinon": "^15.0.1",
"url": "^0.11.0",
"url-exist": "3.0.0",
"url-exist": "3.0.1",
"util": "^0.12.5",
"ws": "^8.11.0"
"ws": "^8.12.0"
}
}
This diff is collapsed.