smartloc 2.0.2 → 2.0.4
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/adapters/adapter-base.d.ts +12 -0
- package/adapters/adapter-base.js +56 -0
- package/adapters/adapter-base.js.map +1 -0
- package/adapters/index.d.ts +4 -0
- package/adapters/index.js +32 -0
- package/adapters/index.js.map +1 -0
- package/adapters/json.d.ts +6 -0
- package/adapters/json.js +23 -0
- package/adapters/json.js.map +1 -0
- package/adapters/xliff.d.ts +6 -0
- package/adapters/xliff.js +35 -0
- package/adapters/xliff.js.map +1 -0
- package/cli/cli.d.ts +2 -0
- package/cli/cli.js +129 -0
- package/cli/cli.js.map +1 -0
- package/cli/collect.d.ts +14 -0
- package/{src/cli/collect.ts → cli/collect.js} +59 -75
- package/cli/collect.js.map +1 -0
- package/cli/interfaces.js +3 -0
- package/cli/interfaces.js.map +1 -0
- package/cli/reconciliate.d.ts +6 -0
- package/{src/cli/reconciliate.ts → cli/reconciliate.js} +35 -40
- package/cli/reconciliate.js.map +1 -0
- package/cli/utils.d.ts +6 -0
- package/{src/cli/utils.ts → cli/utils.js} +16 -12
- package/cli/utils.js.map +1 -0
- package/core/default-locale.d.ts +10 -0
- package/{src/core/default-locale.tsx → core/default-locale.js} +23 -28
- package/core/default-locale.js.map +1 -0
- package/{src/core/interfaces.ts → core/interfaces.d.ts} +15 -20
- package/core/interfaces.js +3 -0
- package/core/interfaces.js.map +1 -0
- package/core/json-utils.d.ts +19 -0
- package/{src/core/json-utils.ts → core/json-utils.js} +27 -33
- package/core/json-utils.js.map +1 -0
- package/core/literal.d.ts +13 -0
- package/{src/core/literal.ts → core/literal.js} +20 -19
- package/core/literal.js.map +1 -0
- package/core/load.d.ts +32 -0
- package/core/load.js +50 -0
- package/core/load.js.map +1 -0
- package/core/locale-list.d.ts +27 -0
- package/{src/core/locale-list.ts → core/locale-list.js} +35 -38
- package/core/locale-list.js.map +1 -0
- package/core/locale.d.ts +15 -0
- package/{src/core/locale.tsx → core/locale.js} +29 -28
- package/core/locale.js.map +1 -0
- package/core/smartloc.d.ts +39 -0
- package/{src/core/smartloc.tsx → core/smartloc.js} +104 -122
- package/core/smartloc.js.map +1 -0
- package/core/tag.d.ts +13 -0
- package/core/tag.js +26 -0
- package/core/tag.js.map +1 -0
- package/core/utils.d.ts +4 -0
- package/core/utils.js +30 -0
- package/core/utils.js.map +1 -0
- package/express.d.ts +12 -0
- package/{src/express.ts → express.js} +33 -41
- package/express.js.map +1 -0
- package/graphql.d.ts +13 -0
- package/{src/graphql.ts → graphql.js} +62 -74
- package/graphql.js.map +1 -0
- package/index.js +30 -1
- package/index.js.map +1 -0
- package/node/index.d.ts +1 -0
- package/node/index.js +18 -0
- package/node/index.js.map +1 -0
- package/node/load.d.ts +12 -0
- package/node/load.js +37 -0
- package/node/load.js.map +1 -0
- package/package.json +3 -22
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/.vscode/launch.json +0 -65
- package/.vscode/settings.json +0 -14
- package/.vscode/tasks.json +0 -27
- package/build/README.md +0 -225
- package/build/package.json +0 -60
- package/bun.lock +0 -310
- package/samples/express/main.ts +0 -37
- package/samples/express/package.json +0 -10
- package/samples/graphql/main.ts +0 -73
- package/samples/graphql/package.json +0 -15
- package/src/adapters/adapter-base.ts +0 -58
- package/src/adapters/index.ts +0 -31
- package/src/adapters/json.ts +0 -18
- package/src/adapters/xliff.ts +0 -30
- package/src/cli/cli.ts +0 -137
- package/src/core/load.ts +0 -82
- package/src/core/tag.ts +0 -48
- package/src/core/utils.tsx +0 -24
- package/src/node/index.ts +0 -1
- package/src/node/load.ts +0 -32
- package/test/collect.spec.ts +0 -45
- package/test/reconciliation.spec.ts +0 -132
- package/test/serialization.spec.ts +0 -162
- package/test/translation.spec.ts +0 -61
- package/tsconfig.json +0 -37
- package/tslint.json +0 -103
- /package/{src/cli/interfaces.ts → cli/interfaces.d.ts} +0 -0
- /package/{src/index.ts → index.d.ts} +0 -0
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiteralLocalizer = void 0;
|
|
4
|
+
exports.isLocStr = isLocStr;
|
|
5
|
+
exports.setIsLoc = setIsLoc;
|
|
4
6
|
const locTag = Symbol('_localizable');
|
|
5
|
-
|
|
7
|
+
function isLocStr(data) {
|
|
6
8
|
return data && typeof data === 'object' && data[locTag];
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
export function setIsLoc(data: any) {
|
|
10
|
+
function setIsLoc(data) {
|
|
10
11
|
data[locTag] = true;
|
|
11
12
|
Object.freeze(data);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
class LiteralLocalizer {
|
|
15
|
+
locale;
|
|
16
|
+
numbers;
|
|
17
|
+
dateTimeFormat;
|
|
18
|
+
dateFormat;
|
|
19
|
+
constructor(locale) {
|
|
20
|
+
this.locale = locale;
|
|
20
21
|
this.numbers = new Intl.NumberFormat(locale.id);
|
|
21
22
|
// Format for dates with time (equivalent to moment's 'LLL')
|
|
22
23
|
this.dateTimeFormat = new Intl.DateTimeFormat(locale.id, {
|
|
@@ -33,10 +34,7 @@ export class LiteralLocalizer implements ILiteralLocalizer {
|
|
|
33
34
|
day: 'numeric'
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
localize(data: LocLiteral, react: false): string;
|
|
38
|
-
localize(data: LocLiteral, react: true): React.ReactNode;
|
|
39
|
-
localize(data: LocLiteral, react: boolean): string | React.ReactNode {
|
|
37
|
+
localize(data, react) {
|
|
40
38
|
if (typeof data === 'string') {
|
|
41
39
|
return data;
|
|
42
40
|
}
|
|
@@ -54,8 +52,9 @@ export class LiteralLocalizer implements ILiteralLocalizer {
|
|
|
54
52
|
return data.toString(this.locale);
|
|
55
53
|
}
|
|
56
54
|
if (react) {
|
|
57
|
-
return data
|
|
58
|
-
}
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
59
58
|
if (isLocStr(data)) {
|
|
60
59
|
return data.toString(this.locale);
|
|
61
60
|
}
|
|
@@ -64,3 +63,5 @@ export class LiteralLocalizer implements ILiteralLocalizer {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
}
|
|
66
|
+
exports.LiteralLocalizer = LiteralLocalizer;
|
|
67
|
+
//# sourceMappingURL=literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../src/core/literal.ts"],"names":[],"mappings":";;;AAIA,4BAEC;AAED,4BAGC;AARD,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,SAAgB,QAAQ,CAAC,IAAS;IAC9B,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,QAAQ,CAAC,IAAS;IAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,MAAa,gBAAgB;IAKL;IAJZ,OAAO,CAAoB;IAC3B,cAAc,CAAsB;IACpC,UAAU,CAAsB;IAExC,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChD,4DAA4D;QAC5D,IAAI,CAAC,cAAc,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE;YACrD,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,GAAG,EAAE,SAAS;YAC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AC;QACd,CAAC;IACL,CAAC;CACJ;AApDD,4CAoDC"}
|
package/core/load.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TranslationTarget } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Loads a locale generated from CLI
|
|
4
|
+
* @param filePath The file path to load
|
|
5
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadJsonLocale(obj: GroupedTranslation, merge?: boolean): void;
|
|
8
|
+
export declare function loadJsonLocale(url: string, merge?: boolean): Promise<void>;
|
|
9
|
+
export interface CollectItem {
|
|
10
|
+
source?: TranslationTarget;
|
|
11
|
+
target?: TranslationTarget | null;
|
|
12
|
+
dirty?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface CollectResult {
|
|
15
|
+
[id: string]: CollectItem;
|
|
16
|
+
}
|
|
17
|
+
export interface Translation {
|
|
18
|
+
resources: CollectResult;
|
|
19
|
+
sourceLanguage?: string;
|
|
20
|
+
targetLanguage: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GroupedTranslation {
|
|
23
|
+
resources: {
|
|
24
|
+
[namespace: string]: CollectResult;
|
|
25
|
+
};
|
|
26
|
+
sourceLanguage?: string;
|
|
27
|
+
targetLanguage: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function ungroupTranslation(translation: GroupedTranslation): Translation;
|
|
30
|
+
export declare function convertLocale(locale: Translation): {
|
|
31
|
+
[key: string]: TranslationTarget;
|
|
32
|
+
};
|
package/core/load.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadJsonLocale = loadJsonLocale;
|
|
4
|
+
exports.ungroupTranslation = ungroupTranslation;
|
|
5
|
+
exports.convertLocale = convertLocale;
|
|
6
|
+
const locale_list_1 = require("./locale-list");
|
|
7
|
+
function loadJsonLocale(urlOrObj, merge) {
|
|
8
|
+
if (typeof urlOrObj === 'string') {
|
|
9
|
+
return fetch(urlOrObj).then(async (response) => {
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
throw new Error(`Failed to fetch ${urlOrObj}: ${response.statusText}`);
|
|
12
|
+
}
|
|
13
|
+
const text = await response.json();
|
|
14
|
+
if (typeof text !== 'object') {
|
|
15
|
+
throw new Error(`Expecting ${urlOrObj} to be a JSON object`);
|
|
16
|
+
}
|
|
17
|
+
return loadJsonLocale(text, merge);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const transformed = convertLocale(ungroupTranslation(urlOrObj));
|
|
21
|
+
(0, locale_list_1.addLocale)(urlOrObj.targetLanguage, transformed, merge);
|
|
22
|
+
}
|
|
23
|
+
function ungroupTranslation(translation) {
|
|
24
|
+
const result = {
|
|
25
|
+
targetLanguage: translation.targetLanguage,
|
|
26
|
+
sourceLanguage: translation.sourceLanguage,
|
|
27
|
+
resources: {},
|
|
28
|
+
};
|
|
29
|
+
for (const [namespace, data] of Object.entries(translation.resources)) {
|
|
30
|
+
for (const [id, val] of Object.entries(data ?? {})) {
|
|
31
|
+
if (namespace === '$default') {
|
|
32
|
+
result.resources[id] = val;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result.resources[`${namespace}.${id}`] = val;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function convertLocale(locale) {
|
|
42
|
+
const ret = {};
|
|
43
|
+
for (const [k, v] of Object.entries(locale.resources)) {
|
|
44
|
+
if (v.target) {
|
|
45
|
+
ret[k] = v.target;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return ret;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=load.js.map
|
package/core/load.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/core/load.ts"],"names":[],"mappings":";;AAUA,wCAg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,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,SAAS,CAAC,GAAG,SAAS,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;YACjD,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAID,SAAgB,aAAa,CAAC,MAAmB;IAC7C,MAAM,GAAG,GAAyC,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QACtB,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ILocaleDef, TranslationTarget } from './interfaces';
|
|
2
|
+
/** Defines the locale used in code */
|
|
3
|
+
export declare function setDefaultLocale(localeId: string): void;
|
|
4
|
+
export declare function changeLocale(locale: ILocaleDef | string, throwIfNotFound?: boolean): "not found" | "unchanged" | "changed";
|
|
5
|
+
export declare function subscribeToLocaleChange(callback: () => void): () => void;
|
|
6
|
+
export declare namespace subscribeToLocaleChange {
|
|
7
|
+
var count: () => number;
|
|
8
|
+
}
|
|
9
|
+
export declare function getCurrentLocale(noDefault?: false): ILocaleDef;
|
|
10
|
+
export declare function getCurrentLocale(noDefault: true): ILocaleDef | null;
|
|
11
|
+
export declare function getDefaultLocale(): ILocaleDef;
|
|
12
|
+
/** Resets all locales */
|
|
13
|
+
export declare function clearLocales(): void;
|
|
14
|
+
/** Remove a locale */
|
|
15
|
+
export declare function removeLocale(id: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Adds translations
|
|
18
|
+
* @param id Locale ID (ex: 'en', or 'en-US')
|
|
19
|
+
* @param localeDef Translations (string id as key, formatted string as values - ex : {myId: 'Translated {0} text {1}'})
|
|
20
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
21
|
+
*/
|
|
22
|
+
export declare function addLocale(id: string, localeDef: {
|
|
23
|
+
[id: string]: TranslationTarget;
|
|
24
|
+
}, merge?: boolean): void;
|
|
25
|
+
export declare function getLocale(id: string): ILocaleDef | null;
|
|
26
|
+
export declare function listLocales(): Generator<string, void, unknown>;
|
|
27
|
+
export declare function listLocaleDefs(): IterableIterator<ILocaleDef>;
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDefaultLocale = setDefaultLocale;
|
|
4
|
+
exports.changeLocale = changeLocale;
|
|
5
|
+
exports.subscribeToLocaleChange = subscribeToLocaleChange;
|
|
6
|
+
exports.getCurrentLocale = getCurrentLocale;
|
|
7
|
+
exports.getDefaultLocale = getDefaultLocale;
|
|
8
|
+
exports.clearLocales = clearLocales;
|
|
9
|
+
exports.removeLocale = removeLocale;
|
|
10
|
+
exports.addLocale = addLocale;
|
|
11
|
+
exports.getLocale = getLocale;
|
|
12
|
+
exports.listLocales = listLocales;
|
|
13
|
+
exports.listLocaleDefs = listLocaleDefs;
|
|
14
|
+
const default_locale_1 = require("./default-locale");
|
|
15
|
+
const locale_1 = require("./locale");
|
|
16
|
+
let locales = {};
|
|
17
|
+
let defaultLocale = null;
|
|
18
|
+
let currentLocale = null;
|
|
10
19
|
/** Defines the locale used in code */
|
|
11
|
-
|
|
12
|
-
defaultLocale = new DefaultLocale(localeId);
|
|
20
|
+
function setDefaultLocale(localeId) {
|
|
21
|
+
defaultLocale = new default_locale_1.DefaultLocale(localeId);
|
|
13
22
|
currentLocale = defaultLocale;
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
export function changeLocale(locale: ILocaleDef | string, throwIfNotFound = true) {
|
|
24
|
+
function changeLocale(locale, throwIfNotFound = true) {
|
|
17
25
|
const loc = typeof locale === 'string' ? getLocale(locale) : locale;
|
|
18
26
|
if (!loc) {
|
|
19
27
|
if (!throwIfNotFound) {
|
|
@@ -28,37 +36,30 @@ export function changeLocale(locale: ILocaleDef | string, throwIfNotFound = true
|
|
|
28
36
|
subs.forEach(sub => sub());
|
|
29
37
|
return 'changed';
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export function subscribeToLocaleChange(callback: () => void) {
|
|
39
|
+
const subs = new Set();
|
|
40
|
+
function subscribeToLocaleChange(callback) {
|
|
34
41
|
subs.add(callback);
|
|
35
42
|
return () => { subs.delete(callback); };
|
|
36
43
|
}
|
|
37
44
|
subscribeToLocaleChange.count = () => subs.size;
|
|
38
|
-
|
|
39
|
-
export function getCurrentLocale(noDefault?: false): ILocaleDef;
|
|
40
|
-
export function getCurrentLocale(noDefault: true): ILocaleDef | null;
|
|
41
|
-
export function getCurrentLocale(noDefault = false) {
|
|
45
|
+
function getCurrentLocale(noDefault = false) {
|
|
42
46
|
if (currentLocale || noDefault) {
|
|
43
47
|
return currentLocale ?? null;
|
|
44
48
|
}
|
|
45
49
|
return getDefaultLocale();
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
export function getDefaultLocale() {
|
|
51
|
+
function getDefaultLocale() {
|
|
49
52
|
if (!defaultLocale) {
|
|
50
53
|
throw new Error('You must specify default locale via setDefaultLocale() before using localization');
|
|
51
54
|
}
|
|
52
55
|
return defaultLocale;
|
|
53
56
|
}
|
|
54
|
-
|
|
55
57
|
/** Resets all locales */
|
|
56
|
-
|
|
58
|
+
function clearLocales() {
|
|
57
59
|
locales = {};
|
|
58
60
|
}
|
|
59
|
-
|
|
60
61
|
/** Remove a locale */
|
|
61
|
-
|
|
62
|
+
function removeLocale(id) {
|
|
62
63
|
id = id.toLowerCase();
|
|
63
64
|
const existing = locales[id];
|
|
64
65
|
if (!existing) {
|
|
@@ -70,14 +71,13 @@ export function removeLocale(id: string) {
|
|
|
70
71
|
delete locales[bl];
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
|
|
74
74
|
/**
|
|
75
75
|
* Adds translations
|
|
76
76
|
* @param id Locale ID (ex: 'en', or 'en-US')
|
|
77
77
|
* @param localeDef Translations (string id as key, formatted string as values - ex : {myId: 'Translated {0} text {1}'})
|
|
78
78
|
* @param merge If true, then the translations will be merged with already existing translations.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
function addLocale(id, localeDef, merge) {
|
|
81
81
|
id = id.toLowerCase();
|
|
82
82
|
let loc = locales[id];
|
|
83
83
|
if (loc) {
|
|
@@ -90,14 +90,13 @@ export function addLocale(id: string, localeDef: { [id: string]: TranslationTarg
|
|
|
90
90
|
};
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
loc = locales[id] = new Locale(id, localeDef);
|
|
93
|
+
loc = locales[id] = new locale_1.Locale(id, localeDef);
|
|
94
94
|
const bl = baseLocale(id);
|
|
95
95
|
if (bl && !locales[bl]) {
|
|
96
96
|
locales[bl] = loc;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
export function getLocale(id: string): ILocaleDef | null {
|
|
99
|
+
function getLocale(id) {
|
|
101
100
|
if (!id) {
|
|
102
101
|
return null;
|
|
103
102
|
}
|
|
@@ -109,22 +108,20 @@ export function getLocale(id: string): ILocaleDef | null {
|
|
|
109
108
|
const bl = baseLocale(id);
|
|
110
109
|
return bl && locales[bl] || null;
|
|
111
110
|
}
|
|
112
|
-
|
|
113
|
-
function baseLocale(l: string) {
|
|
111
|
+
function baseLocale(l) {
|
|
114
112
|
const m = /^([a-zA-Z]+)\-[a-zA-Z]+$/.exec(l);
|
|
115
113
|
return m?.[1] || null;
|
|
116
114
|
}
|
|
117
|
-
|
|
118
|
-
export function* listLocales() {
|
|
115
|
+
function* listLocales() {
|
|
119
116
|
yield* Object.keys(locales);
|
|
120
117
|
if (defaultLocale) {
|
|
121
118
|
yield defaultLocale.id;
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
|
-
|
|
125
|
-
export function* listLocaleDefs(): IterableIterator<ILocaleDef> {
|
|
121
|
+
function* listLocaleDefs() {
|
|
126
122
|
yield* Object.values(locales);
|
|
127
123
|
if (defaultLocale) {
|
|
128
124
|
yield defaultLocale;
|
|
129
125
|
}
|
|
130
|
-
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=locale-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-list.js","sourceRoot":"","sources":["../../src/core/locale-list.ts"],"names":[],"mappings":";;AAUA,4CAGC;AAED,oCAcC;AAGD,0DAGC;AAKD,4CAKC;AAED,4CAKC;AAGD,oCAEC;AAGD,oCAWC;AAQD,8BAkBC;AAED,8BAWC;AAOD,kCAKC;AAED,wCAKC;AAhID,qDAAiD;AACjD,qCAAkC;AAElC,IAAI,OAAO,GAA8B,EAAE,CAAC;AAE5C,IAAI,aAAa,GAAsB,IAAI,CAAC;AAC5C,IAAI,aAAa,GAAsB,IAAI,CAAC;AAE5C,sCAAsC;AACtC,SAAgB,gBAAgB,CAAC,QAAgB;IAC7C,aAAa,GAAG,IAAI,8BAAa,CAAC,QAAQ,CAAC,CAAC;IAC5C,aAAa,GAAG,aAAa,CAAC;AAClC,CAAC;AAED,SAAgB,YAAY,CAAC,MAA2B,EAAE,eAAe,GAAG,IAAI;IAC5E,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACpE,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,IAAI,CAAC,eAAe,EAAE,CAAC;YACn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G,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IACzB,MAAM,CAAC,GAAG,0BAA0B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1B,CAAC;AAED,QAAe,CAAC,CAAC,WAAW;IACxB,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,IAAI,aAAa,EAAE,CAAC;QAChB,MAAM,aAAa,CAAC,EAAE,CAAC;IAC3B,CAAC;AACL,CAAC;AAED,QAAe,CAAC,CAAC,cAAc;IAC3B,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,aAAa,EAAE,CAAC;QAChB,MAAM,aAAa,CAAC;IACxB,CAAC;AACL,CAAC"}
|
package/core/locale.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ILocaleDef, ILiteralLocalizer, LocLiteral, TranslationTarget } from './interfaces';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare class Locale implements ILocaleDef {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
localeDef: {
|
|
6
|
+
[id: string]: TranslationTarget;
|
|
7
|
+
};
|
|
8
|
+
readonly literals: ILiteralLocalizer;
|
|
9
|
+
readonly code: string | undefined;
|
|
10
|
+
constructor(id: string, localeDef: {
|
|
11
|
+
[id: string]: TranslationTarget;
|
|
12
|
+
});
|
|
13
|
+
localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react?: false): string | null;
|
|
14
|
+
localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: true): React.ReactNode | null;
|
|
15
|
+
}
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Locale = void 0;
|
|
4
|
+
const literal_1 = require("./literal");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
class Locale {
|
|
7
|
+
id;
|
|
8
|
+
localeDef;
|
|
9
|
+
literals;
|
|
10
|
+
code;
|
|
11
|
+
constructor(id, localeDef) {
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.localeDef = localeDef;
|
|
14
|
+
this.literals = new literal_1.LiteralLocalizer(this);
|
|
15
|
+
this.code = (0, utils_1.getLocaleCode)(id);
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react?: false): string | null;
|
|
16
|
-
localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: true): React.ReactNode | null;
|
|
17
|
-
localize(id: string, count: number | null, _parts: TemplateStringsArray, placeholders: LocLiteral[], react?: boolean): string | React.ReactNode | null {
|
|
17
|
+
localize(id, count, _parts, placeholders, react) {
|
|
18
18
|
const templateObj = this.localeDef[id];
|
|
19
19
|
if (!templateObj) {
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
let template
|
|
22
|
+
let template = undefined;
|
|
23
23
|
if (typeof templateObj === 'string') {
|
|
24
24
|
template = templateObj;
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
26
27
|
if (count === 1 && templateObj.singular) {
|
|
27
28
|
template = templateObj.singular;
|
|
28
|
-
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
29
31
|
template = templateObj.plural;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -34,9 +36,7 @@ export class Locale implements ILocaleDef {
|
|
|
34
36
|
const literals = placeholders?.map(x => this.literals.localize(x, false));
|
|
35
37
|
return format(template, literals);
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const ret: React.ReactNode[] = [];
|
|
39
|
+
const ret = [];
|
|
40
40
|
// match all {N} in the template and replace them with the corresponding literal
|
|
41
41
|
const matches = template.matchAll(/\{(\d+)\}/g);
|
|
42
42
|
let currentIndex = 0;
|
|
@@ -49,7 +49,8 @@ export class Locale implements ILocaleDef {
|
|
|
49
49
|
const p = placeholders[i];
|
|
50
50
|
if (p) {
|
|
51
51
|
ret.push(this.literals.localize(p, true));
|
|
52
|
-
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
53
54
|
console.warn(`Placeholder {${i}} in template of ${id} for locale ${this.id} does not exist`);
|
|
54
55
|
}
|
|
55
56
|
currentIndex = match.index + match[0].length;
|
|
@@ -58,18 +59,18 @@ export class Locale implements ILocaleDef {
|
|
|
58
59
|
if (fromLast) {
|
|
59
60
|
ret.push(fromLast);
|
|
60
61
|
}
|
|
61
|
-
return asFragment(ret);
|
|
62
|
+
return (0, utils_1.asFragment)(ret);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
function format(str
|
|
65
|
+
exports.Locale = Locale;
|
|
66
|
+
function format(str, args) {
|
|
66
67
|
if (!args || !args.length) {
|
|
67
68
|
return str;
|
|
68
69
|
}
|
|
69
70
|
return str.replace(/{(\d+)}/g, function (match, number) {
|
|
70
71
|
return typeof args[number] !== 'undefined'
|
|
71
72
|
? args[number]
|
|
72
|
-
: match
|
|
73
|
-
;
|
|
73
|
+
: match;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/core/locale.tsx"],"names":[],"mappings":";;;AACA,uCAA6C;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AC,OAAO,CAAC,UAAU,EAAE,UAAU,KAAK,EAAE,MAAM;QAClD,OAAO,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,WAAW;YACtC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;YACd,CAAC,CAAC,KAAK,CACN;IACT,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { InternalLocStr, LocLiteral, LocStr } from './interfaces';
|
|
2
|
+
export declare function useAsString(loc: LocStr | string | null): string | null;
|
|
3
|
+
export declare function useAsString(loc: LocStr | string | undefined): string | undefined;
|
|
4
|
+
export declare function useAsString(loc: LocStr | string | undefined): string | undefined;
|
|
5
|
+
export interface SerializationContextOptions {
|
|
6
|
+
/** HOw non self-descriptive (MultiLoc, SingleLoc, ...) will be transformed. Defaults to 'id'.
|
|
7
|
+
*
|
|
8
|
+
* id => will serialize its ID ... the context of deserialization will be required to have the given translation
|
|
9
|
+
* skip => will be left as it (=> serialization will translate it)
|
|
10
|
+
* toMulti => translates to all registered languages, and serializes as a 'multi'
|
|
11
|
+
*/
|
|
12
|
+
nonSelfDescriptive?: 'skip' | 'toMulti' | 'id';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Execute something in the given locales context.
|
|
16
|
+
* @param acceptLanguages The accepted languages, by order of preference
|
|
17
|
+
* @param action Action to perform (usually a JSON.serialize() or a .toString() operation)
|
|
18
|
+
**/
|
|
19
|
+
export declare function withLocales<T = void>(acceptLanguages: string[], action: () => T): T;
|
|
20
|
+
/**
|
|
21
|
+
* Execute something in a context where .toJson() loc strings
|
|
22
|
+
* will be serialized into a form that is parsable via jsonParseLocalized()
|
|
23
|
+
*/
|
|
24
|
+
export declare function withSerializationContext<T = void>(action: () => T, options?: SerializationContextOptions): T;
|
|
25
|
+
interface SmartlocProps {
|
|
26
|
+
id: string;
|
|
27
|
+
literals: TemplateStringsArray | null;
|
|
28
|
+
placeholders: LocLiteral[] | null;
|
|
29
|
+
count: number | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare const smartLoc: (props: SmartlocProps) => LocStr;
|
|
32
|
+
export declare const transformed: (props: {
|
|
33
|
+
parent: InternalLocStr;
|
|
34
|
+
transformer: (x: string) => string;
|
|
35
|
+
}) => LocStr;
|
|
36
|
+
export declare function singleLoc(text: string): LocStr;
|
|
37
|
+
export declare const multiLoc: (props: Record<string, string>) => LocStr;
|
|
38
|
+
export declare function joinArray(separator: string | LocStr, items: (string | LocStr)[]): LocStr;
|
|
39
|
+
export {};
|