@koine/i18n 2.0.0-beta.164 → 2.0.0-beta.166
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/adapter-js/generators/createT.cjs.js +22 -29
- package/adapter-js/generators/createT.esm.js +22 -29
- package/adapter-js/generators/formatTo.cjs.js +2 -2
- package/adapter-js/generators/formatTo.esm.js +2 -2
- package/adapter-js/generators/formatUrl.cjs.js +2 -2
- package/adapter-js/generators/formatUrl.esm.js +2 -2
- package/adapter-js/generators/getI18nDictionaries.cjs.js +6 -5
- package/adapter-js/generators/getI18nDictionaries.esm.js +6 -5
- package/adapter-js/generators/getI18nMetadata.cjs.js +5 -5
- package/adapter-js/generators/getI18nMetadata.esm.js +5 -5
- package/adapter-js/generators/getT.cjs.js +5 -5
- package/adapter-js/generators/getT.esm.js +5 -5
- package/adapter-js/generators/isLocale.cjs.js +2 -2
- package/adapter-js/generators/isLocale.esm.js +2 -2
- package/adapter-js/generators/loadTranslations.cjs.js +3 -3
- package/adapter-js/generators/loadTranslations.esm.js +3 -3
- package/adapter-js/generators/pathnameToRouteId.cjs.js +2 -2
- package/adapter-js/generators/pathnameToRouteId.esm.js +2 -2
- package/adapter-js/generators/routes.cjs.js +2 -2
- package/adapter-js/generators/routes.esm.js +2 -2
- package/adapter-js/generators/setLocale.cjs.js +2 -2
- package/adapter-js/generators/setLocale.esm.js +2 -2
- package/adapter-js/generators/t.cjs.js +27 -27
- package/adapter-js/generators/t.esm.js +27 -27
- package/adapter-js/generators/tInterpolateParams.cjs.js +8 -7
- package/adapter-js/generators/tInterpolateParams.d.ts +1 -0
- package/adapter-js/generators/tInterpolateParams.esm.js +8 -7
- package/adapter-js/generators/tInterpolateParamsDeep.cjs.js +3 -2
- package/adapter-js/generators/tInterpolateParamsDeep.d.ts +1 -0
- package/adapter-js/generators/tInterpolateParamsDeep.esm.js +3 -2
- package/adapter-js/generators/to.cjs.js +2 -2
- package/adapter-js/generators/to.esm.js +2 -2
- package/adapter-js/generators/types.cjs.js +137 -231
- package/adapter-js/generators/types.esm.js +137 -231
- package/adapter-js/index.cjs.js +0 -2
- package/adapter-js/index.d.ts +2 -7
- package/adapter-js/index.esm.js +19 -21
- package/adapter-next/generators/router-app/I18nLayout.cjs.js +1 -1
- package/adapter-next/generators/router-app/I18nLayout.esm.js +1 -1
- package/adapter-next/generators/router-app/I18nLayoutRoot.cjs.js +2 -2
- package/adapter-next/generators/router-app/I18nLayoutRoot.esm.js +2 -2
- package/adapter-next/generators/router-app/I18nPage.cjs.js +2 -2
- package/adapter-next/generators/router-app/I18nPage.esm.js +2 -2
- package/adapter-next/generators/router-pages/I18nApp.cjs.js +5 -5
- package/adapter-next/generators/router-pages/I18nApp.esm.js +5 -5
- package/adapter-next/generators/router-pages/I18nHead.cjs.js +2 -2
- package/adapter-next/generators/router-pages/I18nHead.esm.js +2 -2
- package/adapter-next/generators/router-pages/i18nGet.cjs.js +3 -3
- package/adapter-next/generators/router-pages/i18nGet.esm.js +3 -3
- package/adapter-next/generators/webpack-define.cjs.js +23 -23
- package/adapter-next/generators/webpack-define.esm.js +23 -23
- package/adapter-react/generators/I18nHeadTags.cjs.js +3 -4
- package/adapter-react/generators/I18nHeadTags.esm.js +3 -4
- package/adapter-react/generators/I18nMetadata.cjs.js +11 -12
- package/adapter-react/generators/I18nMetadata.esm.js +11 -12
- package/adapter-react/generators/I18nTranslate.cjs.js +5 -4
- package/adapter-react/generators/I18nTranslate.esm.js +5 -4
- package/adapter-react/generators/Trans.cjs.js +14 -10
- package/adapter-react/generators/Trans.esm.js +14 -10
- package/adapter-react/generators/getT.cjs.js +6 -6
- package/adapter-react/generators/getT.esm.js +6 -6
- package/compiler/api.cjs.js +8 -10
- package/compiler/api.esm.js +8 -10
- package/compiler/code/adapters.cjs.js +12 -13
- package/compiler/code/adapters.d.ts +1 -1
- package/compiler/code/adapters.esm.js +12 -13
- package/compiler/code/data-translations.cjs.js +1 -1
- package/compiler/code/data-translations.esm.js +1 -1
- package/compiler/code/write.cjs.js +38 -38
- package/compiler/code/write.esm.js +39 -39
- package/compiler/types.d.ts +1 -1
- package/i18nDefaultMetadata.cjs.d.ts +1 -0
- package/i18nDefaultMetadata.cjs.default.js +1 -0
- package/i18nDefaultMetadata.cjs.js +8 -0
- package/i18nDefaultMetadata.cjs.mjs +2 -0
- package/i18nDefaultMetadata.d.ts +5 -0
- package/i18nDefaultMetadata.esm.d.ts +1 -0
- package/i18nDefaultMetadata.esm.js +6 -0
- package/i18nInterpolateParams.cjs.js +8 -0
- package/i18nInterpolateParams.d.ts +1 -0
- package/i18nInterpolateParams.esm.js +3 -0
- package/i18nInterpolateParamsDeep.cjs.js +15 -0
- package/i18nInterpolateParamsDeep.d.ts +8 -0
- package/i18nInterpolateParamsDeep.esm.js +10 -0
- package/i18nPluralise.d.ts +1 -0
- package/index.cjs.js +6 -0
- package/index.d.ts +3 -0
- package/index.esm.js +3 -0
- package/package.json +9 -3
- package/types.d.ts +49 -1
- package/adapter-js/generators/defaultI18nMetadata.cjs.js +0 -25
- package/adapter-js/generators/defaultI18nMetadata.d.ts +0 -10
- package/adapter-js/generators/defaultI18nMetadata.esm.js +0 -23
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var e = createAdapter.createGenerator("js", (e)=>{
|
|
6
6
|
let { config: { single: t }, options: { translations: { fallbackDefaultStrategy: a, tokens: { keyDelimiter: n, namespaceDelimiter: l } } } } = e;
|
|
7
7
|
return {
|
|
8
8
|
createT: {
|
|
@@ -11,42 +11,36 @@ var t = createAdapter.createGenerator("js", (e)=>{
|
|
|
11
11
|
ext: "ts",
|
|
12
12
|
index: !0,
|
|
13
13
|
content: ()=>`
|
|
14
|
-
import type { I18nUtils } from "
|
|
14
|
+
import type { I18nUtils } from "@koine/i18n";
|
|
15
15
|
import type { I18n } from "./types";${t ? "" : `
|
|
16
16
|
import { defaultLocale } from "./defaultLocale";`}
|
|
17
17
|
import { tInterpolateParamsDeep } from "./internal/tInterpolateParamsDeep";
|
|
18
18
|
|
|
19
|
-
// An optional parameter allowEmptyStrings - true as default.
|
|
20
|
-
// If allowEmptyStrings parameter is marked as false,
|
|
21
|
-
// it should log an error when an empty string is attempted to be translated
|
|
22
|
-
// and return the namespace and key as result of the translation.
|
|
23
|
-
const allowEmptyStrings = true;
|
|
24
|
-
|
|
25
19
|
/**
|
|
26
20
|
* Create \`t\` function based on given dictionary/dictionaries and given locale
|
|
27
21
|
*/
|
|
28
|
-
export function createT<TDictionary extends
|
|
22
|
+
export function createT<TDictionary extends I18nUtils.TranslationsDictionaryLoose>(
|
|
29
23
|
dictionaries: TDictionary,
|
|
30
24
|
${t ? "locale: I18n.Locale = defaultLocale" : "locale: I18n.Locale"},
|
|
31
25
|
pluralRules?: Intl.PluralRules,
|
|
32
26
|
) {
|
|
33
27
|
pluralRules = pluralRules || new Intl.PluralRules(locale);
|
|
34
28
|
return <
|
|
35
|
-
|
|
36
|
-
TFallback extends I18nUtils.Get<TDictionary,
|
|
37
|
-
TReturn = I18nUtils.Get<TDictionary,
|
|
29
|
+
TTrace extends I18nUtils.Paths<TDictionary>,
|
|
30
|
+
TFallback extends I18nUtils.Get<TDictionary, TTrace>,
|
|
31
|
+
TReturn = I18nUtils.Get<TDictionary, TTrace>,
|
|
38
32
|
>(
|
|
39
|
-
|
|
40
|
-
query?:
|
|
33
|
+
trace: TTrace,
|
|
34
|
+
query?: I18nUtils.TranslateQuery,
|
|
41
35
|
fallback?: TFallback
|
|
42
36
|
): TReturn => {
|
|
43
|
-
let [namespaceOrPath, maybePath] =
|
|
37
|
+
let [namespaceOrPath, maybePath] = trace.split("${l}");
|
|
44
38
|
// namespace is optional, so in case there is no delimiter we just have the path
|
|
45
39
|
const namespace = namespaceOrPath && maybePath ? namespaceOrPath : "";
|
|
46
40
|
const path = namespaceOrPath && maybePath ? maybePath : namespaceOrPath;
|
|
47
41
|
const dic = (namespace && dictionaries[namespace]) || dictionaries || {};
|
|
48
42
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, path, query);
|
|
49
|
-
const value =
|
|
43
|
+
const value = getValue(dic, pluralisedKey);
|
|
50
44
|
|
|
51
45
|
// check if value is empty
|
|
52
46
|
if (
|
|
@@ -58,7 +52,7 @@ export function createT<TDictionary extends I18n.TranslationsDictionaryLoose>(
|
|
|
58
52
|
) {
|
|
59
53
|
return typeof fallback !== "undefined"
|
|
60
54
|
? fallback
|
|
61
|
-
: ${"key" === a ? "
|
|
55
|
+
: ${"key" === a ? "trace" : '""'} as TReturn;
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
return (query ? tInterpolateParamsDeep(value, query) : value) as TReturn;
|
|
@@ -68,15 +62,14 @@ export function createT<TDictionary extends I18n.TranslationsDictionaryLoose>(
|
|
|
68
62
|
/**
|
|
69
63
|
* Get value from key (allow nested keys as parent.children)
|
|
70
64
|
*/
|
|
71
|
-
function
|
|
72
|
-
dic:
|
|
65
|
+
function getValue(
|
|
66
|
+
dic: I18nUtils.TranslationsDictionaryLoose,
|
|
73
67
|
key: string = "",
|
|
74
68
|
): unknown | undefined {
|
|
75
|
-
const
|
|
76
|
-
const keyParts = keyDelimiter ? key.split(keyDelimiter) : [key];
|
|
69
|
+
const keyParts = key.split("${n}");
|
|
77
70
|
|
|
78
71
|
return keyParts.reduce(
|
|
79
|
-
(val:
|
|
72
|
+
(val: I18nUtils.TranslationsDictionaryLoose | string, key: string) => {
|
|
80
73
|
return val?.[key as keyof typeof val] ?? {};
|
|
81
74
|
},
|
|
82
75
|
dic,
|
|
@@ -88,29 +81,29 @@ function getDicValue(
|
|
|
88
81
|
*/
|
|
89
82
|
function getPluralisedKey(
|
|
90
83
|
pluralRules: Intl.PluralRules,
|
|
91
|
-
dic:
|
|
84
|
+
dic: I18nUtils.TranslationsDictionaryLoose,
|
|
92
85
|
key: string,
|
|
93
|
-
query?:
|
|
86
|
+
query?: I18nUtils.TranslateQuery
|
|
94
87
|
): string {
|
|
95
88
|
const count = query instanceof Object ? query["count"] : null;
|
|
96
89
|
|
|
97
90
|
if (!query || typeof count !== "number") return key;
|
|
98
91
|
|
|
99
|
-
if (
|
|
92
|
+
if (getValue(dic, key + "_" + count) !== undefined) {
|
|
100
93
|
return key + "_" + count;
|
|
101
94
|
}
|
|
102
95
|
|
|
103
96
|
const pluralKey = key + "_" + pluralRules.select(count);
|
|
104
|
-
if (
|
|
97
|
+
if (getValue(dic, pluralKey) !== undefined) {
|
|
105
98
|
return pluralKey;
|
|
106
99
|
}
|
|
107
100
|
|
|
108
|
-
if (
|
|
101
|
+
if (getValue(dic, key + "${n}" + count) !== undefined) {
|
|
109
102
|
return key + "." + count;
|
|
110
103
|
}
|
|
111
104
|
|
|
112
105
|
const nestedKey = key + "${n}" + pluralRules.select(count);
|
|
113
|
-
if (
|
|
106
|
+
if (getValue(dic, nestedKey) !== undefined) {
|
|
114
107
|
return nestedKey;
|
|
115
108
|
}
|
|
116
109
|
|
|
@@ -123,4 +116,4 @@ export default createT;
|
|
|
123
116
|
};
|
|
124
117
|
});
|
|
125
118
|
|
|
126
|
-
module.exports =
|
|
119
|
+
module.exports = e;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var e = createGenerator("js", (e)=>{
|
|
4
4
|
let { config: { single: t }, options: { translations: { fallbackDefaultStrategy: a, tokens: { keyDelimiter: n, namespaceDelimiter: l } } } } = e;
|
|
5
5
|
return {
|
|
6
6
|
createT: {
|
|
@@ -9,42 +9,36 @@ var t = createGenerator("js", (e)=>{
|
|
|
9
9
|
ext: "ts",
|
|
10
10
|
index: !0,
|
|
11
11
|
content: ()=>`
|
|
12
|
-
import type { I18nUtils } from "
|
|
12
|
+
import type { I18nUtils } from "@koine/i18n";
|
|
13
13
|
import type { I18n } from "./types";${t ? "" : `
|
|
14
14
|
import { defaultLocale } from "./defaultLocale";`}
|
|
15
15
|
import { tInterpolateParamsDeep } from "./internal/tInterpolateParamsDeep";
|
|
16
16
|
|
|
17
|
-
// An optional parameter allowEmptyStrings - true as default.
|
|
18
|
-
// If allowEmptyStrings parameter is marked as false,
|
|
19
|
-
// it should log an error when an empty string is attempted to be translated
|
|
20
|
-
// and return the namespace and key as result of the translation.
|
|
21
|
-
const allowEmptyStrings = true;
|
|
22
|
-
|
|
23
17
|
/**
|
|
24
18
|
* Create \`t\` function based on given dictionary/dictionaries and given locale
|
|
25
19
|
*/
|
|
26
|
-
export function createT<TDictionary extends
|
|
20
|
+
export function createT<TDictionary extends I18nUtils.TranslationsDictionaryLoose>(
|
|
27
21
|
dictionaries: TDictionary,
|
|
28
22
|
${t ? "locale: I18n.Locale = defaultLocale" : "locale: I18n.Locale"},
|
|
29
23
|
pluralRules?: Intl.PluralRules,
|
|
30
24
|
) {
|
|
31
25
|
pluralRules = pluralRules || new Intl.PluralRules(locale);
|
|
32
26
|
return <
|
|
33
|
-
|
|
34
|
-
TFallback extends I18nUtils.Get<TDictionary,
|
|
35
|
-
TReturn = I18nUtils.Get<TDictionary,
|
|
27
|
+
TTrace extends I18nUtils.Paths<TDictionary>,
|
|
28
|
+
TFallback extends I18nUtils.Get<TDictionary, TTrace>,
|
|
29
|
+
TReturn = I18nUtils.Get<TDictionary, TTrace>,
|
|
36
30
|
>(
|
|
37
|
-
|
|
38
|
-
query?:
|
|
31
|
+
trace: TTrace,
|
|
32
|
+
query?: I18nUtils.TranslateQuery,
|
|
39
33
|
fallback?: TFallback
|
|
40
34
|
): TReturn => {
|
|
41
|
-
let [namespaceOrPath, maybePath] =
|
|
35
|
+
let [namespaceOrPath, maybePath] = trace.split("${l}");
|
|
42
36
|
// namespace is optional, so in case there is no delimiter we just have the path
|
|
43
37
|
const namespace = namespaceOrPath && maybePath ? namespaceOrPath : "";
|
|
44
38
|
const path = namespaceOrPath && maybePath ? maybePath : namespaceOrPath;
|
|
45
39
|
const dic = (namespace && dictionaries[namespace]) || dictionaries || {};
|
|
46
40
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, path, query);
|
|
47
|
-
const value =
|
|
41
|
+
const value = getValue(dic, pluralisedKey);
|
|
48
42
|
|
|
49
43
|
// check if value is empty
|
|
50
44
|
if (
|
|
@@ -56,7 +50,7 @@ export function createT<TDictionary extends I18n.TranslationsDictionaryLoose>(
|
|
|
56
50
|
) {
|
|
57
51
|
return typeof fallback !== "undefined"
|
|
58
52
|
? fallback
|
|
59
|
-
: ${"key" === a ? "
|
|
53
|
+
: ${"key" === a ? "trace" : '""'} as TReturn;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
return (query ? tInterpolateParamsDeep(value, query) : value) as TReturn;
|
|
@@ -66,15 +60,14 @@ export function createT<TDictionary extends I18n.TranslationsDictionaryLoose>(
|
|
|
66
60
|
/**
|
|
67
61
|
* Get value from key (allow nested keys as parent.children)
|
|
68
62
|
*/
|
|
69
|
-
function
|
|
70
|
-
dic:
|
|
63
|
+
function getValue(
|
|
64
|
+
dic: I18nUtils.TranslationsDictionaryLoose,
|
|
71
65
|
key: string = "",
|
|
72
66
|
): unknown | undefined {
|
|
73
|
-
const
|
|
74
|
-
const keyParts = keyDelimiter ? key.split(keyDelimiter) : [key];
|
|
67
|
+
const keyParts = key.split("${n}");
|
|
75
68
|
|
|
76
69
|
return keyParts.reduce(
|
|
77
|
-
(val:
|
|
70
|
+
(val: I18nUtils.TranslationsDictionaryLoose | string, key: string) => {
|
|
78
71
|
return val?.[key as keyof typeof val] ?? {};
|
|
79
72
|
},
|
|
80
73
|
dic,
|
|
@@ -86,29 +79,29 @@ function getDicValue(
|
|
|
86
79
|
*/
|
|
87
80
|
function getPluralisedKey(
|
|
88
81
|
pluralRules: Intl.PluralRules,
|
|
89
|
-
dic:
|
|
82
|
+
dic: I18nUtils.TranslationsDictionaryLoose,
|
|
90
83
|
key: string,
|
|
91
|
-
query?:
|
|
84
|
+
query?: I18nUtils.TranslateQuery
|
|
92
85
|
): string {
|
|
93
86
|
const count = query instanceof Object ? query["count"] : null;
|
|
94
87
|
|
|
95
88
|
if (!query || typeof count !== "number") return key;
|
|
96
89
|
|
|
97
|
-
if (
|
|
90
|
+
if (getValue(dic, key + "_" + count) !== undefined) {
|
|
98
91
|
return key + "_" + count;
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
const pluralKey = key + "_" + pluralRules.select(count);
|
|
102
|
-
if (
|
|
95
|
+
if (getValue(dic, pluralKey) !== undefined) {
|
|
103
96
|
return pluralKey;
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
if (
|
|
99
|
+
if (getValue(dic, key + "${n}" + count) !== undefined) {
|
|
107
100
|
return key + "." + count;
|
|
108
101
|
}
|
|
109
102
|
|
|
110
103
|
const nestedKey = key + "${n}" + pluralRules.select(count);
|
|
111
|
-
if (
|
|
104
|
+
if (getValue(dic, nestedKey) !== undefined) {
|
|
112
105
|
return nestedKey;
|
|
113
106
|
}
|
|
114
107
|
|
|
@@ -121,4 +114,4 @@ export default createT;
|
|
|
121
114
|
};
|
|
122
115
|
});
|
|
123
116
|
|
|
124
|
-
export {
|
|
117
|
+
export { e as default };
|
|
@@ -84,7 +84,7 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, n)=>new funct
|
|
|
84
84
|
return pathname;
|
|
85
85
|
`
|
|
86
86
|
});
|
|
87
|
-
var
|
|
87
|
+
var t = createAdapter.createGenerator("js", (a)=>{
|
|
88
88
|
let { config: t } = a;
|
|
89
89
|
return {
|
|
90
90
|
formatTo: {
|
|
@@ -102,5 +102,5 @@ var a = createAdapter.createGenerator("js", (a)=>{
|
|
|
102
102
|
};
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
exports.default =
|
|
105
|
+
exports.default = t;
|
|
106
106
|
exports.formatTo = formatTo;
|
|
@@ -80,7 +80,7 @@ const formatTo = ({ defaultLocale: e, hideDefaultLocaleInUrl: t }, n)=>new Funct
|
|
|
80
80
|
return pathname;
|
|
81
81
|
`
|
|
82
82
|
});
|
|
83
|
-
var
|
|
83
|
+
var t = createGenerator("js", (a)=>{
|
|
84
84
|
let { config: t } = a;
|
|
85
85
|
return {
|
|
86
86
|
formatTo: {
|
|
@@ -98,4 +98,4 @@ var a = createGenerator("js", (a)=>{
|
|
|
98
98
|
};
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
export {
|
|
101
|
+
export { t as default, formatTo };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var a = createAdapter.createGenerator("js", (e)=>{
|
|
6
6
|
let { config: { baseUrl: t, trailingSlash: a } } = e;
|
|
7
7
|
return {
|
|
8
8
|
formatUrl: {
|
|
@@ -24,4 +24,4 @@ export default formatUrl;
|
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
module.exports =
|
|
27
|
+
module.exports = a;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var a = createGenerator("js", (e)=>{
|
|
4
4
|
let { config: { baseUrl: t, trailingSlash: a } } = e;
|
|
5
5
|
return {
|
|
6
6
|
formatUrl: {
|
|
@@ -22,4 +22,4 @@ export default formatUrl;
|
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
export {
|
|
25
|
+
export { a as default };
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var m = createAdapter.createGenerator("js", (n)=>({
|
|
6
6
|
getI18nDictionaries: {
|
|
7
7
|
dir: createAdapter.createGenerator.dirs.internal,
|
|
8
8
|
name: "getI18nDictionaries",
|
|
9
9
|
ext: "ts",
|
|
10
10
|
index: !1,
|
|
11
11
|
content: ()=>`
|
|
12
|
+
import type { I18nUtils } from "${process.env.JEST_WORKER_ID ? "../../../types" : "@koine/i18n"}";
|
|
12
13
|
import { defaultLocale } from "../defaultLocale";
|
|
13
14
|
import type { I18n } from "../types";
|
|
14
15
|
import { loadTranslations } from "./loadTranslations";
|
|
15
16
|
|
|
16
17
|
type GetI18nDictionariesOptions = {
|
|
17
18
|
locale?: I18n.Locale;
|
|
18
|
-
namespaces?: I18n.
|
|
19
|
+
namespaces?: I18n.TranslationsNamespace[];
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export async function getI18nDictionaries({
|
|
@@ -32,12 +33,12 @@ export async function getI18nDictionaries({
|
|
|
32
33
|
return namespaces.reduce((dictionaries, ns, idx) => {
|
|
33
34
|
dictionaries[ns] =
|
|
34
35
|
translations[idx] ||
|
|
35
|
-
(null as unknown as
|
|
36
|
+
(null as unknown as I18nUtils.TranslationsDictionaryLoose);
|
|
36
37
|
return dictionaries;
|
|
37
|
-
}, {} as
|
|
38
|
+
}, {} as I18nUtils.TranslationsDictionaries);
|
|
38
39
|
}
|
|
39
40
|
`
|
|
40
41
|
}
|
|
41
42
|
}));
|
|
42
43
|
|
|
43
|
-
module.exports =
|
|
44
|
+
module.exports = m;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var m = createGenerator("js", (n)=>({
|
|
4
4
|
getI18nDictionaries: {
|
|
5
5
|
dir: createGenerator.dirs.internal,
|
|
6
6
|
name: "getI18nDictionaries",
|
|
7
7
|
ext: "ts",
|
|
8
8
|
index: !1,
|
|
9
9
|
content: ()=>`
|
|
10
|
+
import type { I18nUtils } from "${process.env.JEST_WORKER_ID ? "../../../types" : "@koine/i18n"}";
|
|
10
11
|
import { defaultLocale } from "../defaultLocale";
|
|
11
12
|
import type { I18n } from "../types";
|
|
12
13
|
import { loadTranslations } from "./loadTranslations";
|
|
13
14
|
|
|
14
15
|
type GetI18nDictionariesOptions = {
|
|
15
16
|
locale?: I18n.Locale;
|
|
16
|
-
namespaces?: I18n.
|
|
17
|
+
namespaces?: I18n.TranslationsNamespace[];
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export async function getI18nDictionaries({
|
|
@@ -30,12 +31,12 @@ export async function getI18nDictionaries({
|
|
|
30
31
|
return namespaces.reduce((dictionaries, ns, idx) => {
|
|
31
32
|
dictionaries[ns] =
|
|
32
33
|
translations[idx] ||
|
|
33
|
-
(null as unknown as
|
|
34
|
+
(null as unknown as I18nUtils.TranslationsDictionaryLoose);
|
|
34
35
|
return dictionaries;
|
|
35
|
-
}, {} as
|
|
36
|
+
}, {} as I18nUtils.TranslationsDictionaries);
|
|
36
37
|
}
|
|
37
38
|
`
|
|
38
39
|
}
|
|
39
40
|
}));
|
|
40
41
|
|
|
41
|
-
export {
|
|
42
|
+
export { m as default };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var s = createAdapter.createGenerator("js", (e)=>{
|
|
6
6
|
let { routes: { dynamicRoutes: a, staticRoutes: o } } = e;
|
|
7
7
|
return {
|
|
8
8
|
getI18nMetadata: {
|
|
@@ -11,12 +11,12 @@ var n = createAdapter.createGenerator("js", (e)=>{
|
|
|
11
11
|
ext: "ts",
|
|
12
12
|
index: !1,
|
|
13
13
|
content: ()=>`
|
|
14
|
+
import { type I18nUtils, i18nDefaultMetadata } from "@koine/i18n";
|
|
14
15
|
import { defaultLocale } from "../defaultLocale";
|
|
15
16
|
import { formatUrl } from "../formatUrl";
|
|
16
17
|
import { locales } from "../locales";
|
|
17
18
|
import { to } from "../to";
|
|
18
19
|
import type { I18n } from "../types";
|
|
19
|
-
import { defaultI18nMetadata } from "./defaultI18nMetadata";
|
|
20
20
|
import { type RouteIdError, isErrorRoute } from "./routesError";
|
|
21
21
|
|
|
22
22
|
type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
@@ -35,9 +35,9 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
35
35
|
id,${a.length ? `
|
|
36
36
|
params,` : ""}
|
|
37
37
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
38
|
-
if (isErrorRoute(id)) return
|
|
38
|
+
if (isErrorRoute(id)) return i18nDefaultMetadata;${a.length && !o.length ? `
|
|
39
39
|
params = params as NonNullable<typeof params>;` : ""}
|
|
40
|
-
const alternates:
|
|
40
|
+
const alternates: I18nUtils.Alternates = {
|
|
41
41
|
"x-default": formatUrl(${a.length && o.length ? `
|
|
42
42
|
// @ ts-ignore dynamic to fn typing
|
|
43
43
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
@@ -63,4 +63,4 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
63
63
|
};
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
module.exports =
|
|
66
|
+
module.exports = s;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var s = createGenerator("js", (e)=>{
|
|
4
4
|
let { routes: { dynamicRoutes: a, staticRoutes: o } } = e;
|
|
5
5
|
return {
|
|
6
6
|
getI18nMetadata: {
|
|
@@ -9,12 +9,12 @@ var n = createGenerator("js", (e)=>{
|
|
|
9
9
|
ext: "ts",
|
|
10
10
|
index: !1,
|
|
11
11
|
content: ()=>`
|
|
12
|
+
import { type I18nUtils, i18nDefaultMetadata } from "@koine/i18n";
|
|
12
13
|
import { defaultLocale } from "../defaultLocale";
|
|
13
14
|
import { formatUrl } from "../formatUrl";
|
|
14
15
|
import { locales } from "../locales";
|
|
15
16
|
import { to } from "../to";
|
|
16
17
|
import type { I18n } from "../types";
|
|
17
|
-
import { defaultI18nMetadata } from "./defaultI18nMetadata";
|
|
18
18
|
import { type RouteIdError, isErrorRoute } from "./routesError";
|
|
19
19
|
|
|
20
20
|
type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
@@ -33,9 +33,9 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
33
33
|
id,${a.length ? `
|
|
34
34
|
params,` : ""}
|
|
35
35
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
36
|
-
if (isErrorRoute(id)) return
|
|
36
|
+
if (isErrorRoute(id)) return i18nDefaultMetadata;${a.length && !o.length ? `
|
|
37
37
|
params = params as NonNullable<typeof params>;` : ""}
|
|
38
|
-
const alternates:
|
|
38
|
+
const alternates: I18nUtils.Alternates = {
|
|
39
39
|
"x-default": formatUrl(${a.length && o.length ? `
|
|
40
40
|
// @ ts-ignore dynamic to fn typing
|
|
41
41
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
@@ -61,4 +61,4 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
export {
|
|
64
|
+
export { s as default };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var n = createAdapter.createGenerator("js", (a)=>({
|
|
6
6
|
getT: {
|
|
7
7
|
name: "getT",
|
|
8
8
|
ext: "ts",
|
|
@@ -12,7 +12,7 @@ import { loadTranslations } from "./internal/loadTranslations";
|
|
|
12
12
|
import { createT } from "../createT";
|
|
13
13
|
import type { I18n } from "./types";
|
|
14
14
|
|
|
15
|
-
export async function getT<TNamespace extends I18n.
|
|
15
|
+
export async function getT<TNamespace extends I18n.TranslationsNamespace>(
|
|
16
16
|
locale: I18n.Locale,
|
|
17
17
|
namespace: TNamespace,
|
|
18
18
|
) {
|
|
@@ -20,9 +20,9 @@ export async function getT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
20
20
|
const pluralRules = new Intl.PluralRules(locale);
|
|
21
21
|
|
|
22
22
|
const t = createT({ [namespace]: translations }, pluralRules, locale);
|
|
23
|
-
return ((
|
|
23
|
+
return ((path: string, ...args: any[]) =>
|
|
24
24
|
(t as any)(
|
|
25
|
-
\`\${namespace}:\${
|
|
25
|
+
\`\${namespace}:\${path}\`,
|
|
26
26
|
...args,
|
|
27
27
|
)) as I18n.TranslateNamespaced<TNamespace>;
|
|
28
28
|
}
|
|
@@ -32,4 +32,4 @@ export default getT;
|
|
|
32
32
|
}
|
|
33
33
|
}));
|
|
34
34
|
|
|
35
|
-
module.exports =
|
|
35
|
+
module.exports = n;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var n = createGenerator("js", (a)=>({
|
|
4
4
|
getT: {
|
|
5
5
|
name: "getT",
|
|
6
6
|
ext: "ts",
|
|
@@ -10,7 +10,7 @@ import { loadTranslations } from "./internal/loadTranslations";
|
|
|
10
10
|
import { createT } from "../createT";
|
|
11
11
|
import type { I18n } from "./types";
|
|
12
12
|
|
|
13
|
-
export async function getT<TNamespace extends I18n.
|
|
13
|
+
export async function getT<TNamespace extends I18n.TranslationsNamespace>(
|
|
14
14
|
locale: I18n.Locale,
|
|
15
15
|
namespace: TNamespace,
|
|
16
16
|
) {
|
|
@@ -18,9 +18,9 @@ export async function getT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
18
18
|
const pluralRules = new Intl.PluralRules(locale);
|
|
19
19
|
|
|
20
20
|
const t = createT({ [namespace]: translations }, pluralRules, locale);
|
|
21
|
-
return ((
|
|
21
|
+
return ((path: string, ...args: any[]) =>
|
|
22
22
|
(t as any)(
|
|
23
|
-
\`\${namespace}:\${
|
|
23
|
+
\`\${namespace}:\${path}\`,
|
|
24
24
|
...args,
|
|
25
25
|
)) as I18n.TranslateNamespaced<TNamespace>;
|
|
26
26
|
}
|
|
@@ -30,4 +30,4 @@ export default getT;
|
|
|
30
30
|
}
|
|
31
31
|
}));
|
|
32
32
|
|
|
33
|
-
export {
|
|
33
|
+
export { n as default };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var p = createAdapter.createGenerator("js", (e)=>({
|
|
6
6
|
isLocale: {
|
|
7
7
|
name: "isLocale",
|
|
8
8
|
ext: "ts",
|
|
@@ -19,4 +19,4 @@ export default isLocale;
|
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
-
module.exports =
|
|
22
|
+
module.exports = p;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var p = createGenerator("js", (e)=>({
|
|
4
4
|
isLocale: {
|
|
5
5
|
name: "isLocale",
|
|
6
6
|
ext: "ts",
|
|
@@ -17,4 +17,4 @@ export default isLocale;
|
|
|
17
17
|
}
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export { p as default };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
var helpers = require('../../compiler/helpers.cjs.js');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var i = createAdapter.createGenerator("js", (n)=>({
|
|
7
7
|
loadTranslations: {
|
|
8
8
|
dir: createAdapter.createGenerator.dirs.internal,
|
|
9
9
|
name: "loadTranslations",
|
|
@@ -17,7 +17,7 @@ import type { I18n } from "../types";
|
|
|
17
17
|
*/
|
|
18
18
|
export const loadTranslations = (
|
|
19
19
|
locale: I18n.Locale,
|
|
20
|
-
namespace: I18n.
|
|
20
|
+
namespace: I18n.TranslationsNamespace,
|
|
21
21
|
) =>
|
|
22
22
|
import(\`${helpers.getTranslationsDir(1)}/\${locale}/\${namespace}.json\`).then(
|
|
23
23
|
(m) => m.default,
|
|
@@ -26,4 +26,4 @@ export const loadTranslations = (
|
|
|
26
26
|
}
|
|
27
27
|
}));
|
|
28
28
|
|
|
29
|
-
module.exports =
|
|
29
|
+
module.exports = i;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
import { getTranslationsDir } from '../../compiler/helpers.esm.js';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var i = createGenerator("js", (n)=>({
|
|
5
5
|
loadTranslations: {
|
|
6
6
|
dir: createGenerator.dirs.internal,
|
|
7
7
|
name: "loadTranslations",
|
|
@@ -15,7 +15,7 @@ import type { I18n } from "../types";
|
|
|
15
15
|
*/
|
|
16
16
|
export const loadTranslations = (
|
|
17
17
|
locale: I18n.Locale,
|
|
18
|
-
namespace: I18n.
|
|
18
|
+
namespace: I18n.TranslationsNamespace,
|
|
19
19
|
) =>
|
|
20
20
|
import(\`${getTranslationsDir(1)}/\${locale}/\${namespace}.json\`).then(
|
|
21
21
|
(m) => m.default,
|
|
@@ -24,4 +24,4 @@ export const loadTranslations = (
|
|
|
24
24
|
}
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
|
-
export {
|
|
27
|
+
export { i as default };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var utils = require('@koine/utils');
|
|
4
4
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var f = createAdapter.createGenerator("js", (t)=>{
|
|
7
7
|
let { options: a } = t, { idDelimiter: r, optionalCatchAll: o, catchAll: n } = a.routes.tokens;
|
|
8
8
|
return {
|
|
9
9
|
pathnameToRouteId: {
|
|
@@ -30,4 +30,4 @@ export default pathnameToRouteId;
|
|
|
30
30
|
};
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
module.exports =
|
|
33
|
+
module.exports = f;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { escapeRegExp } from '@koine/utils';
|
|
2
2
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var f = createGenerator("js", (t)=>{
|
|
5
5
|
let { options: a } = t, { idDelimiter: r, optionalCatchAll: o, catchAll: n } = a.routes.tokens;
|
|
6
6
|
return {
|
|
7
7
|
pathnameToRouteId: {
|
|
@@ -28,4 +28,4 @@ export default pathnameToRouteId;
|
|
|
28
28
|
};
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
export {
|
|
31
|
+
export { f as default };
|