@appsemble/node-utils 0.36.6 → 0.36.7-test.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/README.md +3 -3
- package/getAppsembleMessages.js +26 -13
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Node Utilities
|
|
2
2
|
|
|
3
3
|
> NodeJS utilities used by Appsemble internally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/node-utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.36.7-test.0)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ compatibility is not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.36.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.36.7-test.0/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/getAppsembleMessages.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
-
import { defaultLocale } from '@appsemble/utils';
|
|
2
|
+
import { defaultLocale, normalizeLocale } from '@appsemble/utils';
|
|
3
|
+
import { AppsembleError } from './AppsembleError.js';
|
|
3
4
|
const translationsDir = new URL('../../i18n/', import.meta.url);
|
|
4
|
-
|
|
5
|
+
async function getLanguageFiles() {
|
|
5
6
|
const files = await readdir(translationsDir);
|
|
6
|
-
|
|
7
|
+
const result = new Map();
|
|
8
|
+
for (const file of files) {
|
|
9
|
+
if (!file.endsWith('.json')) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const language = normalizeLocale(file.slice(0, -'.json'.length));
|
|
13
|
+
if (result.has(language)) {
|
|
14
|
+
throw new AppsembleError(`Found duplicate language codes: ‘${language}’`);
|
|
15
|
+
}
|
|
16
|
+
result.set(language, file);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
export async function getSupportedLanguages() {
|
|
21
|
+
return new Set((await getLanguageFiles()).keys());
|
|
7
22
|
}
|
|
8
23
|
/**
|
|
9
24
|
* Fetch and merge the Appsemble core messages based on a language and a base language.
|
|
@@ -13,21 +28,19 @@ export async function getSupportedLanguages() {
|
|
|
13
28
|
* @returns The Appsemble core messages.
|
|
14
29
|
*/
|
|
15
30
|
export async function getAppsembleMessages(language, baseLanguage) {
|
|
16
|
-
const lang = language
|
|
17
|
-
const baseLang = baseLanguage
|
|
18
|
-
const languages = await
|
|
31
|
+
const lang = normalizeLocale(language);
|
|
32
|
+
const baseLang = baseLanguage ? normalizeLocale(baseLanguage) : undefined;
|
|
33
|
+
const languages = await getLanguageFiles();
|
|
19
34
|
const messages = {};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (baseLang && languages.has(baseLanguage)) {
|
|
23
|
-
Object.assign(messages, JSON.parse(await readFile(new URL(`${baseLang}.json`, translationsDir), 'utf8')));
|
|
35
|
+
if (baseLang && languages.has(baseLang)) {
|
|
36
|
+
Object.assign(messages, JSON.parse(await readFile(new URL(languages.get(baseLang), translationsDir), 'utf8')));
|
|
24
37
|
}
|
|
25
38
|
if (languages.has(lang)) {
|
|
26
|
-
Object.assign(messages, Object.fromEntries(Object.entries(JSON.parse(await readFile(new URL(
|
|
39
|
+
Object.assign(messages, Object.fromEntries(Object.entries(JSON.parse(await readFile(new URL(languages.get(lang), translationsDir), 'utf8'))).filter(([, value]) => Boolean(value))));
|
|
27
40
|
}
|
|
28
|
-
// Fall back to reading the default locale’s messages if no core messages were found.
|
|
29
41
|
if (!languages.has(lang) && (!baseLang || !languages.has(baseLang))) {
|
|
30
|
-
|
|
42
|
+
const defaultLanguage = normalizeLocale(defaultLocale);
|
|
43
|
+
Object.assign(messages, JSON.parse(await readFile(new URL(languages.get(defaultLanguage), translationsDir), 'utf8')));
|
|
31
44
|
}
|
|
32
45
|
return messages;
|
|
33
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.7-test.0",
|
|
4
4
|
"description": "NodeJS utilities used by Appsemble internally.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"test": "vitest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@appsemble/lang-sdk": "0.36.
|
|
44
|
-
"@appsemble/types": "0.36.
|
|
45
|
-
"@appsemble/utils": "0.36.
|
|
43
|
+
"@appsemble/lang-sdk": "0.36.7-test.0",
|
|
44
|
+
"@appsemble/types": "0.36.7-test.0",
|
|
45
|
+
"@appsemble/utils": "0.36.7-test.0",
|
|
46
46
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
47
47
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
48
48
|
"@kubernetes/client-node": "1.4.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/koa": "^2.0.0",
|
|
51
51
|
"axios": "^1.0.0",
|
|
52
52
|
"bcrypt": "^5.1.1",
|
|
53
|
-
"bulma": "=0.9.
|
|
53
|
+
"bulma": "=0.9.4",
|
|
54
54
|
"bulma-checkradio": "=2.1.1",
|
|
55
55
|
"bulma-slider": "=2.0.4",
|
|
56
56
|
"bulma-switch": "^2.0.0",
|