@omegagrid/localize 0.10.2 → 0.10.5
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/dist/codes.d.ts +3 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/codes.js +107 -0
- package/dist/codes.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/cs-cz.d.ts +4 -0
- package/dist/locales/cs-cz.d.ts.map +1 -0
- package/dist/locales/cs-cz.js +13 -0
- package/dist/locales/cs-cz.js.map +1 -0
- package/dist/locales/en-us.d.ts +4 -0
- package/dist/locales/en-us.d.ts.map +1 -0
- package/dist/locales/en-us.js +13 -0
- package/dist/locales/en-us.js.map +1 -0
- package/dist/locales/index.d.ts +4 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +10 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/localization.d.ts +36 -0
- package/dist/localization.d.ts.map +1 -0
- package/dist/localization.js +111 -0
- package/dist/localization.js.map +1 -0
- package/package.json +1 -1
package/dist/codes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAqFA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAWtC;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAK5C"}
|
package/dist/codes.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const languages = {
|
|
2
|
+
af: ["af-ZA"],
|
|
3
|
+
ar: ["ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-YE"],
|
|
4
|
+
az: ["az-AZ"],
|
|
5
|
+
be: ["be-BY"],
|
|
6
|
+
bg: ["bg-BG"],
|
|
7
|
+
ca: ["ca-ES"],
|
|
8
|
+
cs: ["cs-CZ"],
|
|
9
|
+
cy: ["cy-GB"],
|
|
10
|
+
da: ["da-DK"],
|
|
11
|
+
de: ["de-DE", "de-AT", "de-CH", "de-LI", "de-LU"],
|
|
12
|
+
dv: ["dv-MV"],
|
|
13
|
+
el: ["el-GR"],
|
|
14
|
+
en: ["en-US", "en-AU", "en-BZ", "en-CA", "en-CB", "en-GB", "en-IE", "en-JM", "en-NZ", "en-PH", "en-TT", "en-ZA", "en-ZW"],
|
|
15
|
+
eo: ["eo"],
|
|
16
|
+
es: ["es-ES", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-UY", "es-VE"],
|
|
17
|
+
et: ["et-EE"],
|
|
18
|
+
eu: ["eu-ES"],
|
|
19
|
+
fa: ["fa-IR"],
|
|
20
|
+
fi: ["fi-FI"],
|
|
21
|
+
fo: ["fo-FO"],
|
|
22
|
+
fr: ["fr-BE", "fr-CA", "fr-CH", "fr-FR", "fr-LU", "fr-MC"],
|
|
23
|
+
gl: ["gl-ES"],
|
|
24
|
+
gu: ["gu-IN"],
|
|
25
|
+
he: ["he-IL"],
|
|
26
|
+
hi: ["hi-IN"],
|
|
27
|
+
hr: ["hr-BA", "hr-HR"],
|
|
28
|
+
hu: ["hu-HU"],
|
|
29
|
+
hy: ["hy-AM"],
|
|
30
|
+
id: ["id-ID"],
|
|
31
|
+
is: ["is-IS"],
|
|
32
|
+
it: ["it-CH", "it-IT"],
|
|
33
|
+
ja: ["ja-JP"],
|
|
34
|
+
ka: ["ka-GE"],
|
|
35
|
+
kk: ["kk-KZ"],
|
|
36
|
+
kn: ["kn-IN"],
|
|
37
|
+
ko: ["ko-KR"],
|
|
38
|
+
kok: ["kok-IN"],
|
|
39
|
+
ky: ["ky-KG"],
|
|
40
|
+
lt: ["lt-LT"],
|
|
41
|
+
lv: ["lv-LV"],
|
|
42
|
+
mi: ["mi-NZ"],
|
|
43
|
+
mk: ["mk-MK"],
|
|
44
|
+
mn: ["mn-MN"],
|
|
45
|
+
mr: ["mr-IN"],
|
|
46
|
+
ms: ["ms-BN", "ms-MY"],
|
|
47
|
+
mt: ["mt-MT"],
|
|
48
|
+
nb: ["nb-NO"],
|
|
49
|
+
nl: ["nl-BE", "nl-NL"],
|
|
50
|
+
nn: ["nn-NO"],
|
|
51
|
+
ns: ["ns-ZA"],
|
|
52
|
+
pa: ["pa-IN"],
|
|
53
|
+
pl: ["pl-PL"],
|
|
54
|
+
ps: ["ps-AR"],
|
|
55
|
+
pt: ["pt-BR", "pt-PT"],
|
|
56
|
+
qu: ["qu-BO", "qu-EC", "qu-PE"],
|
|
57
|
+
ro: ["ro-RO"],
|
|
58
|
+
ru: ["ru-RU"],
|
|
59
|
+
sa: ["sa-IN"],
|
|
60
|
+
se: ["se-FI", "se-NO", "se-SE"],
|
|
61
|
+
sk: ["sk-SK"],
|
|
62
|
+
sl: ["sl-SI"],
|
|
63
|
+
sq: ["sq-AL"],
|
|
64
|
+
sr: ["sr-BA", "sr-SP"],
|
|
65
|
+
sv: ["sv-FI", "sv-SE"],
|
|
66
|
+
sw: ["sw-KE"],
|
|
67
|
+
syr: ["syr-SY"],
|
|
68
|
+
ta: ["ta-IN"],
|
|
69
|
+
te: ["te-IN"],
|
|
70
|
+
th: ["th-TH"],
|
|
71
|
+
tl: ["tl-PH"],
|
|
72
|
+
tn: ["tn-ZA"],
|
|
73
|
+
tr: ["tr-TR"],
|
|
74
|
+
tt: ["tt-RU"],
|
|
75
|
+
ts: ["ts"],
|
|
76
|
+
uk: ["uk-UA"],
|
|
77
|
+
ur: ["ur-PK"],
|
|
78
|
+
uz: ["uz-UZ"],
|
|
79
|
+
vi: ["vi-VN"],
|
|
80
|
+
xh: ["xh-ZA"],
|
|
81
|
+
zh: ["zh-CN", "zh-HK", "zh-MO", "zh-SG", "zh-TW"],
|
|
82
|
+
zu: ["zu-ZA"]
|
|
83
|
+
};
|
|
84
|
+
let map;
|
|
85
|
+
export function getISOCode(code) {
|
|
86
|
+
if (languages[code])
|
|
87
|
+
return code;
|
|
88
|
+
if (map && map.has(code))
|
|
89
|
+
return map.get(code);
|
|
90
|
+
for (const key in languages) {
|
|
91
|
+
if (languages[key].includes(code)) {
|
|
92
|
+
map = map ?? new Map();
|
|
93
|
+
map.set(code, key);
|
|
94
|
+
return key;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
export function getRegionISOCode(code) {
|
|
100
|
+
const isoCode = getISOCode(code);
|
|
101
|
+
if (!isoCode)
|
|
102
|
+
return null;
|
|
103
|
+
if (languages[isoCode])
|
|
104
|
+
return languages[isoCode][0];
|
|
105
|
+
return code;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG;IACjB,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;IACpJ,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,C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AAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,SAAS,CAAC,OAAiC,CAAC;QAAE,OAAO,SAAS,CAAC,OAAiC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzG,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["const languages = {\n\taf: [\"af-ZA\"],\n\tar: [\"ar-AE\", \"ar-BH\", \"ar-DZ\", \"ar-EG\", \"ar-IQ\", \"ar-JO\", \"ar-KW\", \"ar-LB\", \"ar-LY\", \"ar-MA\", \"ar-OM\", \"ar-QA\", \"ar-SA\", \"ar-SY\", \"ar-TN\", \"ar-YE\"],\n\taz: [\"az-AZ\"],\n\tbe: [\"be-BY\"],\n\tbg: [\"bg-BG\"],\n\tca: [\"ca-ES\"],\n\tcs: [\"cs-CZ\"],\n\tcy: [\"cy-GB\"],\n\tda: [\"da-DK\"],\n\tde: [\"de-DE\", \"de-AT\", \"de-CH\", \"de-LI\", \"de-LU\"],\n\tdv: [\"dv-MV\"],\n\tel: [\"el-GR\"],\n\ten: [\"en-US\", \"en-AU\", \"en-BZ\", \"en-CA\", \"en-CB\", \"en-GB\", \"en-IE\", \"en-JM\", \"en-NZ\", \"en-PH\", \"en-TT\", \"en-ZA\", \"en-ZW\"],\n\teo: [\"eo\"],\n\tes: [\"es-ES\", \"es-AR\", \"es-BO\", \"es-CL\", \"es-CO\", \"es-CR\", \"es-DO\", \"es-EC\", \"es-GT\", \"es-HN\", \"es-MX\", \"es-NI\", \"es-PA\", \"es-PE\", \"es-PR\", \"es-PY\", \"es-SV\", \"es-UY\", \"es-VE\"],\n\tet: [\"et-EE\"],\n\teu: [\"eu-ES\"],\n\tfa: [\"fa-IR\"],\n\tfi: [\"fi-FI\"],\n\tfo: [\"fo-FO\"],\n\tfr: [\"fr-BE\", \"fr-CA\", \"fr-CH\", \"fr-FR\", \"fr-LU\", \"fr-MC\"],\n\tgl: [\"gl-ES\"],\n\tgu: [\"gu-IN\"],\n\the: [\"he-IL\"],\n\thi: [\"hi-IN\"],\n\thr: [\"hr-BA\", \"hr-HR\"],\n\thu: [\"hu-HU\"],\n\thy: [\"hy-AM\"],\n\tid: [\"id-ID\"],\n\tis: [\"is-IS\"],\n\tit: [\"it-CH\", \"it-IT\"],\n\tja: [\"ja-JP\"],\n\tka: [\"ka-GE\"],\n\tkk: [\"kk-KZ\"],\n\tkn: [\"kn-IN\"],\n\tko: [\"ko-KR\"],\n\tkok: [\"kok-IN\"],\n\tky: [\"ky-KG\"],\n\tlt: [\"lt-LT\"],\n\tlv: [\"lv-LV\"],\n\tmi: [\"mi-NZ\"],\n\tmk: [\"mk-MK\"],\n\tmn: [\"mn-MN\"],\n\tmr: [\"mr-IN\"],\n\tms: [\"ms-BN\", \"ms-MY\"],\n\tmt: [\"mt-MT\"],\n\tnb: [\"nb-NO\"],\n\tnl: [\"nl-BE\", \"nl-NL\"],\n\tnn: [\"nn-NO\"],\n\tns: [\"ns-ZA\"],\n\tpa: [\"pa-IN\"],\n\tpl: [\"pl-PL\"],\n\tps: [\"ps-AR\"],\n\tpt: [\"pt-BR\", \"pt-PT\"],\n\tqu: [\"qu-BO\", \"qu-EC\", \"qu-PE\"],\n\tro: [\"ro-RO\"],\n\tru: [\"ru-RU\"],\n\tsa: [\"sa-IN\"],\n\tse: [\"se-FI\", \"se-NO\", \"se-SE\"],\n\tsk: [\"sk-SK\"],\n\tsl: [\"sl-SI\"],\n\tsq: [\"sq-AL\"],\n\tsr: [\"sr-BA\", \"sr-SP\"],\n\tsv: [\"sv-FI\", \"sv-SE\"],\n\tsw: [\"sw-KE\"],\n\tsyr: [\"syr-SY\"],\n\tta: [\"ta-IN\"],\n\tte: [\"te-IN\"],\n\tth: [\"th-TH\"],\n\ttl: [\"tl-PH\"],\n\ttn: [\"tn-ZA\"],\n\ttr: [\"tr-TR\"],\n\ttt: [\"tt-RU\"],\n\tts: [\"ts\"],\n\tuk: [\"uk-UA\"],\n\tur: [\"ur-PK\"],\n\tuz: [\"uz-UZ\"],\n\tvi: [\"vi-VN\"],\n\txh: [\"xh-ZA\"],\n\tzh: [\"zh-CN\", \"zh-HK\", \"zh-MO\", \"zh-SG\", \"zh-TW\"],\n\tzu: [\"zu-ZA\"]\n};\n\nlet map: Map<string, string>;\nexport function getISOCode(code: string) {\n\tif (languages[code as keyof typeof languages]) return code;\n\tif (map && map.has(code)) return map.get(code);\n\tfor (const key in languages) {\n\t\tif (languages[key as keyof typeof languages].includes(code)) {\n\t\t\tmap = map ?? new Map();\n\t\t\tmap.set(code, key);\n\t\t\treturn key;\n\t\t}\n\t}\n\treturn null;\n}\n\nexport function getRegionISOCode(code: string) {\n\tconst isoCode = getISOCode(code);\n\tif (!isoCode) return null;\n\tif (languages[isoCode as keyof typeof languages]) return languages[isoCode as keyof typeof languages][0];\n\treturn code;\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC","sourcesContent":["export * from './localization';\nexport * from './codes';\n\nimport { registerLocale } from './localization';\nimport locales from './locales';\n\nlocales.forEach(([locale, items]) => registerLocale(locale, items));"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cs-cz.d.ts","sourceRoot":"","sources":["../../src/locales/cs-cz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;wBAa7B,YAAY,EAAE;AAXnB,wBAWoB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{ id: null, source: "copied", target: "zkopírováno" },
|
|
3
|
+
{ id: null, source: "close", target: "zavřít" },
|
|
4
|
+
{ id: null, source: "headers", target: "hlavičky" },
|
|
5
|
+
{ id: null, source: "conditional formatting", target: "podmíněné formátování" },
|
|
6
|
+
{ id: null, source: "sparklines", target: "mikrografy" },
|
|
7
|
+
{ id: null, source: "charts", target: "grafy" },
|
|
8
|
+
{ id: null, source: "named ranges", target: "pojmenované rozsahy" },
|
|
9
|
+
{ id: null, source: "search", target: "hledat" },
|
|
10
|
+
{ id: null, source: "load more", target: "načíst další" },
|
|
11
|
+
{ id: null, source: "today", target: "dnes" }
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=cs-cz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cs-cz.js","sourceRoot":"","sources":["../../src/locales/cs-cz.ts"],"names":[],"mappings":"AAEA,eAAe;IACd,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAC;IACnD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC;IAC7C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAC;IACjD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,uBAAuB,EAAC;IAC7E,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAC;IACtD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAC;IAC7C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,qBAAqB,EAAC;IACjE,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC;IAC9C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAC;IACvD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAC;CACzB,CAAC","sourcesContent":["import { LocalizeItem } from \"..\";\n\nexport default [\n\t{id: null, source: \"copied\", target: \"zkopírováno\"},\n\t{id: null, source: \"close\", target: \"zavřít\"},\n\t{id: null, source: \"headers\", target: \"hlavičky\"},\n\t{id: null, source: \"conditional formatting\", target: \"podmíněné formátování\"},\n\t{id: null, source: \"sparklines\", target: \"mikrografy\"},\n\t{id: null, source: \"charts\", target: \"grafy\"},\n\t{id: null, source: \"named ranges\", target: \"pojmenované rozsahy\"},\n\t{id: null, source: \"search\", target: \"hledat\"},\n\t{id: null, source: \"load more\", target: \"načíst další\"},\n\t{id: null, source: \"today\", target: \"dnes\"}\n] as LocalizeItem[];"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-us.d.ts","sourceRoot":"","sources":["../../src/locales/en-us.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;wBAa7B,YAAY,EAAE;AAXnB,wBAWoB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{ id: null, source: "copied", target: "copied" },
|
|
3
|
+
{ id: null, source: "close", target: "close" },
|
|
4
|
+
{ id: null, source: "headers", target: "headers" },
|
|
5
|
+
{ id: null, source: "conditional formatting", target: "conditional formatting" },
|
|
6
|
+
{ id: null, source: "sparklines", target: "sparklines" },
|
|
7
|
+
{ id: null, source: "charts", target: "charts" },
|
|
8
|
+
{ id: null, source: "named ranges", target: "named ranges" },
|
|
9
|
+
{ id: null, source: "search", target: "search" },
|
|
10
|
+
{ id: null, source: "load more", target: "load more" },
|
|
11
|
+
{ id: null, source: "today", target: "today" }
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=en-us.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-us.js","sourceRoot":"","sources":["../../src/locales/en-us.ts"],"names":[],"mappings":"AAEA,eAAe;IACd,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC;IAC9C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAC;IAC5C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAC;IAChD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,wBAAwB,EAAC;IAC9E,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAC;IACtD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC;IAC9C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAC;IAC1D,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC;IAC9C,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAC;IACpD,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAC;CAC1B,CAAC","sourcesContent":["import { LocalizeItem } from \"..\";\n\nexport default [\n\t{id: null, source: \"copied\", target: \"copied\"},\n\t{id: null, source: \"close\", target: \"close\"},\n\t{id: null, source: \"headers\", target: \"headers\"},\n\t{id: null, source: \"conditional formatting\", target: \"conditional formatting\"},\n\t{id: null, source: \"sparklines\", target: \"sparklines\"},\n\t{id: null, source: \"charts\", target: \"charts\"},\n\t{id: null, source: \"named ranges\", target: \"named ranges\"},\n\t{id: null, source: \"search\", target: \"search\"},\n\t{id: null, source: \"load more\", target: \"load more\"},\n\t{id: null, source: \"today\", target: \"today\"}\n] as LocalizeItem[];"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/locales/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;wBAQvC,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC,EAAE;AANjC,wBAMkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/locales/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAG3B,eAAe;IACd,CAAC,OAAO,EAAE,IAAI,CAAC;IACf,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,OAAO,EAAE,IAAI,CAAC;IACf,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;CACoB,CAAC","sourcesContent":["import enUs from './en-us';\nimport csCZ from './cs-cz';\nimport { LocaleId, LocalizeItem } from '..';\n\nexport default [\n\t['en-US', enUs],\n\t['en', enUs],\n\t['cs-CZ', csCZ],\n\t['cs', csCZ],\n\t['sk', csCZ],\n] as [LocaleId, LocalizeItem[]][];"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type LocaleId = string;
|
|
2
|
+
export type MsgData = Record<string, string | number>;
|
|
3
|
+
export type MsgOptions = {
|
|
4
|
+
/** Unique message id */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Description of this message */
|
|
7
|
+
desc?: string;
|
|
8
|
+
/** word separator */
|
|
9
|
+
separator?: string;
|
|
10
|
+
/** replacable message data */
|
|
11
|
+
data?: MsgData;
|
|
12
|
+
};
|
|
13
|
+
export type LocalizeItem = {
|
|
14
|
+
id: string;
|
|
15
|
+
source: string;
|
|
16
|
+
target: string;
|
|
17
|
+
translate?: (data: MsgData) => string;
|
|
18
|
+
};
|
|
19
|
+
export declare class LocaleChangeEvent extends Event {
|
|
20
|
+
locale: string;
|
|
21
|
+
constructor(locale: string);
|
|
22
|
+
}
|
|
23
|
+
export declare function getSystemLocale(): string;
|
|
24
|
+
export declare function registerLocale(locale: LocaleId | LocaleId[], items: LocalizeItem[]): void;
|
|
25
|
+
export declare function getLocale(): string;
|
|
26
|
+
export declare function hasLocale(locale: LocaleId): boolean;
|
|
27
|
+
export declare function setLocale(locale: LocaleId): void;
|
|
28
|
+
export declare function createTranslateFunction(template: string): (data?: MsgData) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Translate a message to the current locale
|
|
31
|
+
* @param message source message
|
|
32
|
+
* @param options translation options
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export declare function msg(message: string | string[], options?: MsgOptions): string;
|
|
36
|
+
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MA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
|
|
6
|
+
}
|
|
7
|
+
export function getSystemLocale() {
|
|
8
|
+
return typeof navigator !== 'undefined' ? (navigator.languages && navigator.languages.length
|
|
9
|
+
? navigator.languages[0]
|
|
10
|
+
: navigator.language) : 'en';
|
|
11
|
+
}
|
|
12
|
+
const locales = new Map();
|
|
13
|
+
const localeSourceMap = new Map();
|
|
14
|
+
let currentLocale = getSystemLocale();
|
|
15
|
+
export function registerLocale(locale, items) {
|
|
16
|
+
(Array.isArray(locale) ? locale : [locale]).forEach(l => locales.set(l, items));
|
|
17
|
+
}
|
|
18
|
+
export function getLocale() {
|
|
19
|
+
return currentLocale;
|
|
20
|
+
}
|
|
21
|
+
export function hasLocale(locale) {
|
|
22
|
+
return locales.has(locale);
|
|
23
|
+
}
|
|
24
|
+
export function setLocale(locale) {
|
|
25
|
+
if (!locales.has(locale)) {
|
|
26
|
+
let newLocale = currentLocale;
|
|
27
|
+
if (newLocale == null) {
|
|
28
|
+
if (locales.has('en'))
|
|
29
|
+
newLocale = 'en';
|
|
30
|
+
else if (locales.size > 0)
|
|
31
|
+
newLocale = locales.keys().next().value;
|
|
32
|
+
}
|
|
33
|
+
// log.getLogger().warn(`Locale ${locale} is not registered.${newLocale ? ` Switching to ${newLocale}.` : ''}`);
|
|
34
|
+
}
|
|
35
|
+
if (!localeSourceMap.has(locale))
|
|
36
|
+
localeSourceMap.set(locale, new Map());
|
|
37
|
+
const map = localeSourceMap.get(locale);
|
|
38
|
+
locales.get(locale)?.forEach(i => map.set(i.source, i));
|
|
39
|
+
if (currentLocale !== locale) {
|
|
40
|
+
currentLocale = locale;
|
|
41
|
+
document.dispatchEvent(new LocaleChangeEvent(locale));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function createTranslateFunction(template) {
|
|
45
|
+
const regex = /\{([^}]+)\}/g;
|
|
46
|
+
const matches = Array.from(template.matchAll(regex));
|
|
47
|
+
const placeholders = matches.map(match => ({
|
|
48
|
+
name: match[1],
|
|
49
|
+
start: match.index,
|
|
50
|
+
end: match.index + match[0].length
|
|
51
|
+
}));
|
|
52
|
+
return (data) => {
|
|
53
|
+
if (!data)
|
|
54
|
+
return template;
|
|
55
|
+
let result = '';
|
|
56
|
+
let lastIndex = 0;
|
|
57
|
+
for (const placeholder of placeholders) {
|
|
58
|
+
// Add text before placeholder
|
|
59
|
+
result += template.slice(lastIndex, placeholder.start);
|
|
60
|
+
// Add placeholder value
|
|
61
|
+
const value = data[placeholder.name];
|
|
62
|
+
result += value != null ? String(value) : '';
|
|
63
|
+
lastIndex = placeholder.end;
|
|
64
|
+
}
|
|
65
|
+
// Add remaining text after last placeholder
|
|
66
|
+
return result + template.slice(lastIndex);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Translate a message to the current locale
|
|
71
|
+
* @param message source message
|
|
72
|
+
* @param options translation options
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
export function msg(message, options) {
|
|
76
|
+
if (Array.isArray(message)) {
|
|
77
|
+
return message.map(m => msg(m, options)).join(options?.separator ?? ' ');
|
|
78
|
+
}
|
|
79
|
+
if (message == null || message === '')
|
|
80
|
+
return '';
|
|
81
|
+
const source = message.toLowerCase();
|
|
82
|
+
let locale = localeSourceMap.get(currentLocale);
|
|
83
|
+
if (!locale) {
|
|
84
|
+
locale = new Map();
|
|
85
|
+
localeSourceMap.set(currentLocale, locale);
|
|
86
|
+
}
|
|
87
|
+
let localeItem = locale.get(source);
|
|
88
|
+
if (!localeItem) {
|
|
89
|
+
localeItem = {
|
|
90
|
+
id: options?.id ?? null,
|
|
91
|
+
source: source,
|
|
92
|
+
target: message
|
|
93
|
+
};
|
|
94
|
+
locale.set(source, localeItem);
|
|
95
|
+
}
|
|
96
|
+
// create translate function if not exists
|
|
97
|
+
if (options?.data && !localeItem.translate) {
|
|
98
|
+
localeItem.translate = createTranslateFunction(localeItem.target);
|
|
99
|
+
}
|
|
100
|
+
if (!localeItem)
|
|
101
|
+
return message;
|
|
102
|
+
let target = localeItem.translate ? localeItem.translate(options?.data) : localeItem.target;
|
|
103
|
+
if (target == null || target === '')
|
|
104
|
+
return '';
|
|
105
|
+
// Capitalize the first letter if the source message first letter is capitalized
|
|
106
|
+
if (message.length > 0 && message[0] === message[0].toUpperCase()) {
|
|
107
|
+
target = target[0].toUpperCase() + target.slice(1);
|
|
108
|
+
}
|
|
109
|
+
return target;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAsBA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAE3C,YAAY,MAAc;QACzB,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD;AAED,MAAM,UAAU,eAAe;IAC9B,OAAO,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,CACzC,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM;QAChD,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;QACxB,CAAC,CAAC,SAAS,CAAC,QAAQ,CACrB,CAAC,CAAC,CAAC,IAAI,CAAC;AACV,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;AACpD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAuC,CAAC;AAEvE,IAAI,aAAa,GAAW,eAAe,EAAE,CAAC;AAE9C,MAAM,UAAU,cAAc,CAAC,MAA2B,EAAE,KAAqB;IAChF,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC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AAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACnE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["export type LocaleId = string;\n\nexport type MsgData = Record<string, string|number>;\n\nexport type MsgOptions = {\n /** Unique message id */\n id?: string;\n /** Description of this message */\n desc?: string;\n\t/** word separator */\n\tseparator?: string;\n\t/** replacable message data */\n\tdata?: MsgData;\n}\n\nexport type LocalizeItem = {\n\tid: string;\n\tsource: string;\n\ttarget: string;\n\ttranslate?: (data: MsgData) => string\n}\n\nexport class LocaleChangeEvent extends Event {\n\tlocale: string;\n\tconstructor(locale: string) {\n\t\tsuper('localechange');\n\t\tthis.locale = locale;\n\t}\n}\n\nexport function getSystemLocale(): string {\n\treturn typeof navigator !== 'undefined' ? (\n\t\tnavigator.languages && navigator.languages.length\n\t\t\t? navigator.languages[0]\n\t\t\t: navigator.language\n\t) : 'en';\n}\n\nconst locales = new Map<LocaleId, LocalizeItem[]>();\nconst localeSourceMap = new Map<LocaleId, Map<string, LocalizeItem>>();\n\nlet currentLocale: string = getSystemLocale();\n\nexport function registerLocale(locale: LocaleId|LocaleId[], items: LocalizeItem[]) {\n\t(Array.isArray(locale) ? locale : [locale]).forEach(l => locales.set(l, items));\n}\n\nexport function getLocale() {\n\treturn currentLocale;\n}\n\nexport function hasLocale(locale: LocaleId) {\n\treturn locales.has(locale);\n}\n\nexport function setLocale(locale: LocaleId): void {\n\tif (!locales.has(locale)) {\n\t\tlet newLocale = currentLocale;\n\t\tif (newLocale == null) {\n\t\t\tif (locales.has('en')) newLocale = 'en';\t\n\t\t\telse if (locales.size > 0) newLocale = locales.keys().next().value;\n\t\t}\n\t\t// log.getLogger().warn(`Locale ${locale} is not registered.${newLocale ? ` Switching to ${newLocale}.` : ''}`);\n\t}\n\n\tif (!localeSourceMap.has(locale)) localeSourceMap.set(locale, new Map());\n\tconst map = localeSourceMap.get(locale);\n\tlocales.get(locale)?.forEach(i => map.set(i.source, i));\n\n\tif (currentLocale !== locale) {\n\t\tcurrentLocale = locale;\n\t\tdocument.dispatchEvent(new LocaleChangeEvent(locale));\n\t}\n}\n\nexport function createTranslateFunction(template: string): (data?: MsgData) => string {\n\tconst regex = /\\{([^}]+)\\}/g;\n\tconst matches = Array.from(template.matchAll(regex));\n\tconst placeholders = matches.map(match => ({\n\t\tname: match[1],\n\t\tstart: match.index!,\n\t\tend: match.index! + match[0].length\n\t}));\n\n\treturn (data?: MsgData): string => {\n\t\tif (!data) return template;\n\t\t\n\t\tlet result = '';\n\t\tlet lastIndex = 0;\n\t\t\n\t\tfor (const placeholder of placeholders) {\n\t\t\t// Add text before placeholder\n\t\t\tresult += template.slice(lastIndex, placeholder.start);\n\t\t\t\n\t\t\t// Add placeholder value\n\t\t\tconst value = data[placeholder.name];\n\t\t\tresult += value != null ? String(value) : '';\n\t\t\t\n\t\t\tlastIndex = placeholder.end;\n\t\t}\n\t\t\n\t\t// Add remaining text after last placeholder\n\t\treturn result + template.slice(lastIndex);\n\t};\n}\n\n/**\n * Translate a message to the current locale\n * @param message source message\n * @param options translation options\n * @returns \n */\nexport function msg(message: string|string[], options?: MsgOptions): string {\n\tif (Array.isArray(message)) {\n\t\treturn message.map(m => msg(m, options)).join(options?.separator ?? ' ');\n\t}\n\n\tif (message == null || message === '') return '';\n\t\n\tconst source = message.toLowerCase();\n\tlet locale = localeSourceMap.get(currentLocale);\n\tif (!locale) {\n\t\tlocale = new Map<string, LocalizeItem>();\n\t\tlocaleSourceMap.set(currentLocale, locale);\n\t}\n\n\tlet localeItem = locale.get(source);\n\tif (!localeItem) {\n\t\tlocaleItem = {\n\t\t\tid: options?.id ?? null,\n\t\t\tsource: source,\n\t\t\ttarget: message\n\t\t};\n\t\tlocale.set(source, localeItem);\n\t}\n\n\t// create translate function if not exists\t\t\n\tif (options?.data && !localeItem.translate) {\n\t\tlocaleItem.translate = createTranslateFunction(localeItem.target);\n\t}\n\n\tif (!localeItem) return message;\n\n\tlet target = localeItem.translate ? localeItem.translate(options?.data) : localeItem.target;\n\tif (target == null || target === '') return '';\n\n\t// Capitalize the first letter if the source message first letter is capitalized\n\tif (message.length > 0 && message[0] === message[0].toUpperCase()) {\n\t\ttarget = target[0].toUpperCase() + target.slice(1);\n\t}\n\n\treturn target;\n}"]}
|