@prosopo/locale 3.6.0 → 3.6.1

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.
@@ -5,7 +5,7 @@
5
5
  "JSON_LOAD_FAILED": "Laden van JSON-bestand mislukt",
6
6
  "MNEMONIC_UNDEFINED": "Mnemonic Undefined. Stel de mnemonic in omgevingsvariabelen in",
7
7
  "NO_MNEMONIC_OR_SEED": "Geen mnemonic of seed opgegeven",
8
- "CANT_FIND_KEYRINGPAIR": "Kan het sleutelhangerpaar niet vinden voor {{adres}}",
8
+ "CANT_FIND_KEYRINGPAIR": "Kan het sleutelhangerpaar niet vinden voor {{address}}",
9
9
  "ENVIRONMENT_NOT_READY": "Omgeving is niet gereed",
10
10
  "INVALID_SIGNATURE": "Ongeldige handtekening",
11
11
  "SITE_KEY_MISSING": "SITE KEY ontbreekt",
@@ -0,0 +1,81 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+ import { describe, expect, it } from "vitest";
18
+ import { Languages } from "../index.js";
19
+
20
+ type TranslationTree = { [key: string]: string | TranslationTree };
21
+
22
+ const readLocale = (locale: string): TranslationTree =>
23
+ JSON.parse(
24
+ fs.readFileSync(
25
+ path.resolve(`./src/locales/${locale}/translation.json`),
26
+ "utf8",
27
+ ),
28
+ );
29
+
30
+ const flatten = (tree: TranslationTree, prefix = ""): Array<[string, string]> =>
31
+ Object.entries(tree).flatMap(
32
+ ([key, value]): Array<[string, string]> =>
33
+ typeof value === "string"
34
+ ? [[`${prefix}${key}`, value]]
35
+ : flatten(value, `${prefix}${key}.`),
36
+ );
37
+
38
+ const placeholders = (text: string): string[] =>
39
+ (text.match(/\{\{[^}]*\}\}/g) ?? [])
40
+ .map((token: string) => token.replace(/\s+/g, ""))
41
+ .sort();
42
+
43
+ const en = new Map<string, string>(flatten(readLocale("en")));
44
+ const locales: string[] = Object.values(Languages).filter(
45
+ (locale: string) => locale !== "en",
46
+ );
47
+
48
+ describe("locale interpolation placeholders", () => {
49
+ it.each(locales)(
50
+ "%s keeps every {{placeholder}} of the en source",
51
+ (locale: string) => {
52
+ const mismatches: string[] = flatten(readLocale(locale))
53
+ .filter(
54
+ ([key, value]: [string, string]) =>
55
+ en.has(key) &&
56
+ placeholders(value).join() !==
57
+ placeholders(en.get(key) ?? "").join(),
58
+ )
59
+ .map(([key, value]: [string, string]) => `${key}: ${value}`);
60
+ expect(mismatches).toEqual([]);
61
+ },
62
+ );
63
+ });
64
+
65
+ // A tool once stripped every Devanagari vowel sign and virama from the Hindi
66
+ // file ("मैं मनुष्य हूँ" became "म मनषय ह"), which the key and placeholder
67
+ // checks cannot see.
68
+ describe("hi translations", () => {
69
+ it("keep their Devanagari vowel signs", () => {
70
+ const devanagariLetter = /[ऄ-हक़-ॡ]/gu;
71
+ const sign = /[ऀ-ःऺ-ॏॕ-ॗॢॣ]/u;
72
+ const stripped: string[] = flatten(readLocale("hi"))
73
+ .filter(
74
+ ([, value]: [string, string]) =>
75
+ (value.match(devanagariLetter) ?? []).length >= 4 &&
76
+ !sign.test(value),
77
+ )
78
+ .map(([key, value]: [string, string]) => `${key}: ${value}`);
79
+ expect(stripped).toEqual([]);
80
+ });
81
+ });