@koine/i18n 2.0.0-beta.133 → 2.0.0-beta.135
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 +29 -0
- package/adapter-js/generators/config.cjs.js +5 -4
- package/adapter-js/generators/config.d.ts +1 -0
- package/adapter-js/generators/config.esm.js +5 -4
- package/adapter-js/generators/createT.cjs.js +5 -9
- package/adapter-js/generators/createT.esm.js +5 -9
- package/adapter-js/generators/defaultI18nMetadata.cjs.js +2 -2
- package/adapter-js/generators/defaultI18nMetadata.d.ts +1 -0
- package/adapter-js/generators/defaultI18nMetadata.esm.js +2 -2
- package/adapter-js/generators/formatTo.cjs.js +58 -24
- package/adapter-js/generators/formatTo.d.ts +5 -1
- package/adapter-js/generators/formatTo.esm.js +55 -24
- package/adapter-js/generators/formatUrl.cjs.js +4 -5
- package/adapter-js/generators/formatUrl.esm.js +4 -5
- package/adapter-js/generators/getI18nDictionaries.cjs.js +2 -3
- package/adapter-js/generators/getI18nDictionaries.d.ts +1 -0
- package/adapter-js/generators/getI18nDictionaries.esm.js +2 -3
- package/adapter-js/generators/getI18nDictionaries_inline.cjs.js +1 -3
- package/adapter-js/generators/getI18nDictionaries_inline.esm.js +1 -3
- package/adapter-js/generators/getI18nMetadata.cjs.js +3 -5
- package/adapter-js/generators/getI18nMetadata.d.ts +1 -0
- package/adapter-js/generators/getI18nMetadata.esm.js +3 -5
- package/adapter-js/generators/getT.cjs.js +3 -3
- package/adapter-js/generators/getT.esm.js +3 -3
- package/adapter-js/generators/isLocale.cjs.js +3 -3
- package/adapter-js/generators/isLocale.esm.js +3 -3
- package/adapter-js/generators/loadTranslations.d.ts +1 -0
- package/adapter-js/generators/loadTranslations_inline.cjs.js +1 -1
- package/adapter-js/generators/loadTranslations_inline.esm.js +1 -1
- package/adapter-js/generators/pathnameToRouteId.cjs.js +1 -1
- package/adapter-js/generators/pathnameToRouteId.esm.js +1 -1
- package/adapter-js/generators/routes.cjs.js +8 -12
- package/adapter-js/generators/routes.d.ts +4 -0
- package/adapter-js/generators/routes.esm.js +8 -12
- package/adapter-js/generators/t.cjs.js +96 -81
- package/adapter-js/generators/t.d.ts +12 -0
- package/adapter-js/generators/t.esm.js +91 -82
- package/adapter-js/generators/tInterpolateParams.cjs.js +34 -15
- package/adapter-js/generators/tInterpolateParams.d.ts +6 -0
- package/adapter-js/generators/tInterpolateParams.esm.js +31 -15
- package/adapter-js/generators/tPluralise.cjs.js +32 -10
- package/adapter-js/generators/tPluralise.d.ts +3 -0
- package/adapter-js/generators/tPluralise.esm.js +29 -10
- package/adapter-js/generators/to.cjs.js +80 -52
- package/adapter-js/generators/to.esm.js +80 -52
- package/adapter-js/generators/types.cjs.js +34 -37
- package/adapter-js/generators/types.esm.js +34 -37
- package/adapter-js/index.cjs.js +6 -35
- package/adapter-js/index.d.ts +92 -47
- package/adapter-js/index.esm.js +8 -37
- package/adapter-next/generators/next-redirects.cjs.js +7 -5
- package/adapter-next/generators/next-redirects.d.ts +2 -0
- package/adapter-next/generators/next-redirects.esm.js +7 -5
- package/adapter-next/generators/next-rewrites.cjs.js +7 -5
- package/adapter-next/generators/next-rewrites.d.ts +2 -0
- package/adapter-next/generators/next-rewrites.esm.js +7 -5
- package/adapter-next/generators/{I18nLayout.cjs.js → router-app/I18nLayout.cjs.js} +14 -16
- package/adapter-next/generators/{I18nLayout.d.ts → router-app/I18nLayout.d.ts} +2 -1
- package/adapter-next/generators/{I18nLayout.esm.js → router-app/I18nLayout.esm.js} +14 -16
- package/adapter-next/generators/{I18nLayoutRoot.cjs.js → router-app/I18nLayoutRoot.cjs.js} +8 -9
- package/adapter-next/generators/{I18nLayoutRoot.d.ts → router-app/I18nLayoutRoot.d.ts} +2 -1
- package/adapter-next/generators/{I18nLayoutRoot.esm.js → router-app/I18nLayoutRoot.esm.js} +8 -9
- package/adapter-next/generators/{I18nPage.cjs.js → router-app/I18nPage.cjs.js} +12 -14
- package/adapter-next/generators/{I18nPage.d.ts → router-app/I18nPage.d.ts} +2 -1
- package/adapter-next/generators/{I18nPage.esm.js → router-app/I18nPage.esm.js} +12 -14
- package/adapter-next/generators/{i18nServer.cjs.js → router-app/i18nServer.cjs.js} +8 -8
- package/adapter-next/generators/{i18nServer.d.ts → router-app/i18nServer.d.ts} +1 -1
- package/adapter-next/generators/{i18nServer.esm.js → router-app/i18nServer.esm.js} +8 -8
- package/adapter-next/generators/{I18nApp.cjs.js → router-pages/I18nApp.cjs.js} +4 -4
- package/adapter-next/generators/{I18nApp.d.ts → router-pages/I18nApp.d.ts} +1 -1
- package/adapter-next/generators/{I18nApp.esm.js → router-pages/I18nApp.esm.js} +4 -4
- package/adapter-next/generators/{I18nDocument.cjs.js → router-pages/I18nDocument.cjs.js} +10 -11
- package/adapter-next/generators/{I18nDocument.d.ts → router-pages/I18nDocument.d.ts} +1 -1
- package/adapter-next/generators/{I18nDocument.esm.js → router-pages/I18nDocument.esm.js} +10 -11
- package/adapter-next/generators/{I18nHead.cjs.js → router-pages/I18nHead.cjs.js} +5 -9
- package/adapter-next/generators/{I18nHead.d.ts → router-pages/I18nHead.d.ts} +2 -1
- package/adapter-next/generators/{I18nHead.esm.js → router-pages/I18nHead.esm.js} +5 -9
- package/adapter-next/generators/{I18nSetter.cjs.js → router-pages/I18nSetter.cjs.js} +4 -4
- package/adapter-next/generators/{I18nSetter.d.ts → router-pages/I18nSetter.d.ts} +1 -1
- package/adapter-next/generators/{I18nSetter.esm.js → router-pages/I18nSetter.esm.js} +4 -4
- package/adapter-next/generators/{i18nGet.cjs.js → router-pages/i18nGet.cjs.js} +6 -7
- package/adapter-next/generators/{i18nGet.d.ts → router-pages/i18nGet.d.ts} +1 -1
- package/adapter-next/generators/{i18nGet.esm.js → router-pages/i18nGet.esm.js} +6 -7
- package/adapter-next/generators/useRouteId.cjs.js +5 -5
- package/adapter-next/generators/useRouteId.esm.js +5 -5
- package/adapter-next/generators/webpack-define.cjs.js +154 -0
- package/adapter-next/generators/webpack-define.d.ts +23 -0
- package/adapter-next/generators/webpack-define.esm.js +152 -0
- package/adapter-next/index.cjs.js +44 -25
- package/adapter-next/index.d.ts +252 -138
- package/adapter-next/index.esm.js +55 -36
- package/adapter-next/plugin-async.cjs.js +2 -23
- package/adapter-next/plugin-async.esm.js +2 -23
- package/adapter-next/plugin-legacy.cjs.js +5 -76
- package/adapter-next/plugin-legacy.esm.js +5 -76
- package/adapter-next/plugin-shared.cjs.js +39 -30
- package/adapter-next/plugin-shared.d.ts +1 -1
- package/adapter-next/plugin-shared.esm.js +40 -31
- package/adapter-next/plugin.cjs.js +2 -19
- package/adapter-next/plugin.esm.js +2 -19
- package/adapter-next/redirects.cjs.js +4 -15
- package/adapter-next/redirects.esm.js +4 -15
- package/adapter-next/rewrites.cjs.js +7 -34
- package/adapter-next/rewrites.esm.js +7 -34
- package/adapter-next/transformPathname.cjs.js +1 -8
- package/adapter-next/transformPathname.esm.js +1 -8
- package/adapter-next/webpackPluginI18n.cjs.js +7 -13
- package/adapter-next/webpackPluginI18n.esm.js +7 -13
- package/adapter-next-translate/generators/DynamicNamespaces.cjs.js +1 -1
- package/adapter-next-translate/generators/DynamicNamespaces.esm.js +1 -1
- package/adapter-next-translate/generators/I18nProvider.cjs.js +1 -1
- package/adapter-next-translate/generators/I18nProvider.esm.js +1 -1
- package/adapter-next-translate/generators/Trans.cjs.js +1 -1
- package/adapter-next-translate/generators/Trans.esm.js +1 -1
- package/adapter-next-translate/generators/TransText.cjs.js +1 -1
- package/adapter-next-translate/generators/TransText.esm.js +1 -1
- package/adapter-next-translate/generators/getT.cjs.js +1 -1
- package/adapter-next-translate/generators/getT.esm.js +1 -1
- package/adapter-next-translate/generators/nextTranslateI18n.cjs.js +2 -1
- package/adapter-next-translate/generators/nextTranslateI18n.d.ts +1 -0
- package/adapter-next-translate/generators/nextTranslateI18n.esm.js +2 -1
- package/adapter-next-translate/generators/useLocale.cjs.js +1 -1
- package/adapter-next-translate/generators/useLocale.esm.js +1 -1
- package/adapter-next-translate/generators/useT.cjs.js +1 -1
- package/adapter-next-translate/generators/useT.esm.js +1 -1
- package/adapter-next-translate/index.cjs.js +0 -1
- package/adapter-next-translate/index.d.ts +262 -146
- package/adapter-next-translate/index.esm.js +0 -1
- package/adapter-react/generators/I18nEffects.cjs.js +6 -5
- package/adapter-react/generators/I18nEffects.d.ts +1 -0
- package/adapter-react/generators/I18nEffects.esm.js +6 -5
- package/adapter-react/generators/I18nHeadTags.cjs.js +3 -3
- package/adapter-react/generators/I18nHeadTags.esm.js +3 -3
- package/adapter-react/generators/I18nLocaleContext.cjs.js +4 -5
- package/adapter-react/generators/I18nLocaleContext.d.ts +1 -0
- package/adapter-react/generators/I18nLocaleContext.esm.js +4 -5
- package/adapter-react/generators/I18nMetadata.cjs.js +13 -12
- package/adapter-react/generators/I18nMetadata.d.ts +3 -0
- package/adapter-react/generators/I18nMetadata.esm.js +13 -12
- package/adapter-react/generators/I18nRoute.cjs.js +15 -27
- package/adapter-react/generators/I18nRoute.d.ts +2 -5
- package/adapter-react/generators/I18nRoute.esm.js +15 -27
- package/adapter-react/generators/I18nTranslate.cjs.js +9 -6
- package/adapter-react/generators/I18nTranslate.d.ts +2 -0
- package/adapter-react/generators/I18nTranslate.esm.js +9 -6
- package/adapter-react/generators/Trans.cjs.js +93 -2
- package/adapter-react/generators/Trans.d.ts +12 -0
- package/adapter-react/generators/Trans.esm.js +93 -2
- package/adapter-react/generators/getLocale.cjs.js +4 -4
- package/adapter-react/generators/getLocale.esm.js +4 -4
- package/adapter-react/generators/getT.cjs.js +4 -4
- package/adapter-react/generators/getT.esm.js +4 -4
- package/adapter-react/generators/getTo.cjs.js +7 -7
- package/adapter-react/generators/getTo.esm.js +7 -7
- package/adapter-react/generators/packageJson.d.ts +3 -2
- package/adapter-react/generators/useRouteId.cjs.js +23 -0
- package/adapter-react/generators/{TransText.d.ts → useRouteId.d.ts} +2 -2
- package/adapter-react/generators/useRouteId.esm.js +21 -0
- package/{adapter-next → adapter-react}/generators/useTo.cjs.js +3 -4
- package/{adapter-next → adapter-react}/generators/useTo.esm.js +3 -4
- package/{adapter-next → adapter-react}/generators/useToSpa.cjs.js +3 -3
- package/{adapter-next → adapter-react}/generators/useToSpa.esm.js +3 -3
- package/adapter-react/index.cjs.js +7 -7
- package/adapter-react/index.d.ts +174 -102
- package/adapter-react/index.esm.js +11 -11
- package/compiler/api.cjs.js +4 -60
- package/compiler/api.esm.js +4 -60
- package/compiler/code/adapters.cjs.js +7 -27
- package/compiler/code/adapters.d.ts +0 -10
- package/compiler/code/adapters.esm.js +8 -27
- package/compiler/code/data-routes.cjs.js +28 -136
- package/compiler/code/data-routes.esm.js +28 -136
- package/compiler/code/data-translations.cjs.js +82 -157
- package/compiler/code/data-translations.esm.js +82 -157
- package/compiler/code/data.cjs.js +2 -14
- package/compiler/code/data.esm.js +2 -14
- package/compiler/code/generate.cjs.js +36 -47
- package/compiler/code/generate.esm.js +37 -48
- package/compiler/code/tsCompile.cjs.js +5 -22
- package/compiler/code/tsCompile.esm.js +5 -22
- package/compiler/code/write.cjs.js +55 -150
- package/compiler/code/write.d.ts +17 -1
- package/compiler/code/write.esm.js +55 -150
- package/compiler/config.cjs.js +5 -35
- package/compiler/config.d.ts +1 -1
- package/compiler/config.esm.js +6 -36
- package/compiler/createAdapter.cjs.js +4 -28
- package/compiler/createAdapter.d.ts +10 -2
- package/compiler/createAdapter.esm.js +4 -28
- package/compiler/functions.cjs.js +49 -0
- package/compiler/functions.d.ts +73 -0
- package/compiler/functions.esm.js +47 -0
- package/compiler/helpers.cjs.js +11 -25
- package/compiler/helpers.d.ts +1 -6
- package/compiler/helpers.esm.js +11 -25
- package/compiler/imports.cjs.js +29 -0
- package/compiler/imports.d.ts +41 -0
- package/compiler/imports.esm.js +27 -0
- package/compiler/input/data-local.cjs.js +3 -6
- package/compiler/input/data-local.esm.js +3 -6
- package/compiler/input/data-remote.cjs.js +2 -6
- package/compiler/input/data-remote.esm.js +2 -6
- package/compiler/input/write.cjs.js +1 -5
- package/compiler/input/write.esm.js +1 -5
- package/compiler/pluralisation.cjs.js +12 -44
- package/compiler/pluralisation.esm.js +13 -45
- package/compiler/summary/data.cjs.js +3 -8
- package/compiler/summary/data.esm.js +3 -8
- package/compiler/summary/write.cjs.js +1 -9
- package/compiler/summary/write.esm.js +1 -9
- package/compiler/types.d.ts +17 -3
- package/compiler-sync.cjs.js +1 -3
- package/compiler-sync.esm.js +1 -3
- package/formatRoutePathname.cjs.js +1 -3
- package/formatRoutePathname.esm.js +1 -3
- package/interpolateTo.cjs.js +2 -27
- package/interpolateTo.esm.js +2 -27
- package/package.json +12 -6
- package/rtlLocales.cjs.js +1 -27
- package/rtlLocales.esm.js +1 -27
- package/types.cjs.d.ts +1 -0
- package/types.cjs.default.js +1 -0
- package/types.cjs.js +2 -0
- package/types.cjs.mjs +2 -0
- package/types.esm.d.ts +1 -0
- package/types.esm.js +1 -0
- package/adapter-react/generators/TransText.cjs.js +0 -36
- package/adapter-react/generators/TransText.esm.js +0 -34
- package/adapter-react/generators/formatElements.cjs.js +0 -72
- package/adapter-react/generators/formatElements.d.ts +0 -8
- package/adapter-react/generators/formatElements.esm.js +0 -70
- /package/{adapter-next → adapter-react}/generators/useTo.d.ts +0 -0
- /package/{adapter-next → adapter-react}/generators/useToSpa.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
1
|
# @koine/i18n
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
## Co-locate multiple internationalised projects within the same monorepo
|
|
6
|
+
|
|
7
|
+
The compiled output allows to easily manage multile applications and their translations independently within the same monorepo.
|
|
8
|
+
|
|
9
|
+
**Further reading**
|
|
10
|
+
|
|
11
|
+
This was achieved preferring types compilation (the `I18n` namespace) rather than relying on [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) where interface merging of possibly exported shared types from `@koine/i18n` could have achieved the same (see [`i18next` approach](https://www.i18next.com/overview/typescript#create-a-declaration-file)). That in fact would have not allow types to be scoped to the specific i18n compiled project, especially important within a monorepo. It was taken into consideration even a class based approach possibly achieved by something like this:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// in `@koine/i18n/types.ts`:
|
|
15
|
+
export class I18nClass<Locales extends {}, ...all other configurable interfaces as generics> {
|
|
16
|
+
public Locale: keyof Locales;
|
|
17
|
+
|
|
18
|
+
constructor(locales: Locales) {
|
|
19
|
+
this.Locale = Object.keys(locales)[0] as keyof Locales;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// somewhere in the project using @koine/i18n
|
|
24
|
+
import { I18n } from "@/i18n";
|
|
25
|
+
|
|
26
|
+
const myLocale: I18n["Locale"] = "";
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
This was discarded for a better _dx_ as using `I18n["Locale"]` is not as nice as using the namespace form of this `I18n.Locale`.
|
|
30
|
+
For a better _dx_ it was also decided not to export any `I18n` namespace from `@koine/i18n` to avoid amibguity in the IDE autocomplete feature as the same namespace is always exported from the compiled output.
|
|
@@ -9,7 +9,7 @@ var o = createAdapter.createGenerator("js", (e)=>{
|
|
|
9
9
|
name: "locales",
|
|
10
10
|
ext: "ts",
|
|
11
11
|
index: !0,
|
|
12
|
-
content: ()
|
|
12
|
+
content: ()=>`
|
|
13
13
|
export const locales = ${l} as const;
|
|
14
14
|
|
|
15
15
|
export default locales;
|
|
@@ -19,7 +19,7 @@ export default locales;
|
|
|
19
19
|
name: "defaultLocale",
|
|
20
20
|
ext: "ts",
|
|
21
21
|
index: !0,
|
|
22
|
-
content: ()
|
|
22
|
+
content: ()=>`
|
|
23
23
|
import type { I18n } from "./types";
|
|
24
24
|
|
|
25
25
|
export const defaultLocale: I18n.Locale = "${o.defaultLocale}";
|
|
@@ -31,7 +31,7 @@ export default defaultLocale;
|
|
|
31
31
|
name: "config",
|
|
32
32
|
ext: "ts",
|
|
33
33
|
index: !0,
|
|
34
|
-
content: ()
|
|
34
|
+
content: ()=>`
|
|
35
35
|
import { locales } from "./locales";
|
|
36
36
|
import { defaultLocale } from "./defaultLocale";
|
|
37
37
|
|
|
@@ -49,7 +49,8 @@ export default config;
|
|
|
49
49
|
configCjs: {
|
|
50
50
|
name: "config.cjs",
|
|
51
51
|
ext: "js",
|
|
52
|
-
|
|
52
|
+
index: !1,
|
|
53
|
+
content: ()=>`
|
|
53
54
|
const { locales } = require("./locales");
|
|
54
55
|
const { defaultLocale } = require("./defaultLocale");
|
|
55
56
|
|
|
@@ -7,7 +7,7 @@ var o = createGenerator("js", (e)=>{
|
|
|
7
7
|
name: "locales",
|
|
8
8
|
ext: "ts",
|
|
9
9
|
index: !0,
|
|
10
|
-
content: ()
|
|
10
|
+
content: ()=>`
|
|
11
11
|
export const locales = ${l} as const;
|
|
12
12
|
|
|
13
13
|
export default locales;
|
|
@@ -17,7 +17,7 @@ export default locales;
|
|
|
17
17
|
name: "defaultLocale",
|
|
18
18
|
ext: "ts",
|
|
19
19
|
index: !0,
|
|
20
|
-
content: ()
|
|
20
|
+
content: ()=>`
|
|
21
21
|
import type { I18n } from "./types";
|
|
22
22
|
|
|
23
23
|
export const defaultLocale: I18n.Locale = "${o.defaultLocale}";
|
|
@@ -29,7 +29,7 @@ export default defaultLocale;
|
|
|
29
29
|
name: "config",
|
|
30
30
|
ext: "ts",
|
|
31
31
|
index: !0,
|
|
32
|
-
content: ()
|
|
32
|
+
content: ()=>`
|
|
33
33
|
import { locales } from "./locales";
|
|
34
34
|
import { defaultLocale } from "./defaultLocale";
|
|
35
35
|
|
|
@@ -47,7 +47,8 @@ export default config;
|
|
|
47
47
|
configCjs: {
|
|
48
48
|
name: "config.cjs",
|
|
49
49
|
ext: "js",
|
|
50
|
-
|
|
50
|
+
index: !1,
|
|
51
|
+
content: ()=>`
|
|
51
52
|
const { locales } = require("./locales");
|
|
52
53
|
const { defaultLocale } = require("./defaultLocale");
|
|
53
54
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
|
-
var helpers = require('../../compiler/helpers.cjs.js');
|
|
5
4
|
|
|
6
5
|
var t = createAdapter.createGenerator("js", (e)=>{
|
|
7
|
-
let { options:
|
|
6
|
+
let { options: t } = e;
|
|
8
7
|
return {
|
|
9
8
|
createT: {
|
|
10
9
|
name: "createT",
|
|
11
10
|
ext: "ts",
|
|
12
11
|
index: !0,
|
|
13
|
-
content: ()
|
|
12
|
+
content: ()=>`
|
|
14
13
|
import type { I18n } from "./types";
|
|
15
14
|
import { defaultLocale } from "./defaultLocale";
|
|
16
15
|
import { tInterpolateParams } from "./tInterpolateParams";
|
|
@@ -24,7 +23,7 @@ const allowEmptyStrings = true;
|
|
|
24
23
|
/**
|
|
25
24
|
* @see https://github.com/aralroca/next-translate/blob/master/src/transCore.tsx
|
|
26
25
|
*/
|
|
27
|
-
export function createT
|
|
26
|
+
export function createT(
|
|
28
27
|
dictionaries: I18n.Dictionaries,
|
|
29
28
|
pluralRules: Intl.PluralRules,
|
|
30
29
|
locale: string = defaultLocale,
|
|
@@ -54,7 +53,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
54
53
|
query?: I18n.TranslationQuery,
|
|
55
54
|
options?: I18n.TranslationOptions,
|
|
56
55
|
): TReturn => {
|
|
57
|
-
const [namespace, key] = path.split("${
|
|
56
|
+
const [namespace, key] = path.split("${t.translations.tokens.namespaceDelimiter}");
|
|
58
57
|
const dic = (namespace && dictionaries[namespace]) || {};
|
|
59
58
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, key, query, options);
|
|
60
59
|
const dicValue = getDicValue(dic, pluralisedKey, query, options);
|
|
@@ -66,6 +65,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
66
65
|
const empty =
|
|
67
66
|
typeof value === "undefined" ||
|
|
68
67
|
(typeof value === "object" && !Object.keys(value).length) ||
|
|
68
|
+
(Array.isArray(value) && !value.length) ||
|
|
69
69
|
(value === "" && !allowEmptyStrings);
|
|
70
70
|
|
|
71
71
|
// no need to try interpolation
|
|
@@ -168,10 +168,6 @@ function interpolation(
|
|
|
168
168
|
if (!text || !query || query === "obj") return text || "";
|
|
169
169
|
|
|
170
170
|
return tInterpolateParams(text, query);
|
|
171
|
-
// return Object.keys(query).reduce((all, key) => {
|
|
172
|
-
// const regex = new RegExp(\`${helpers.escapeEachChar(r)}\\s*\${key}(?:[\\s,]+([\\w-]*))?\\s*\$${helpers.escapeEachChar(a)}\`, "gm");
|
|
173
|
-
// return all.replace(regex, (_match) => query[key as keyof typeof query] as string);
|
|
174
|
-
// }, text);
|
|
175
171
|
}
|
|
176
172
|
|
|
177
173
|
function objectInterpolation(
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
-
import { escapeEachChar } from '../../compiler/helpers.esm.js';
|
|
3
2
|
|
|
4
3
|
var t = createGenerator("js", (e)=>{
|
|
5
|
-
let { options:
|
|
4
|
+
let { options: t } = e;
|
|
6
5
|
return {
|
|
7
6
|
createT: {
|
|
8
7
|
name: "createT",
|
|
9
8
|
ext: "ts",
|
|
10
9
|
index: !0,
|
|
11
|
-
content: ()
|
|
10
|
+
content: ()=>`
|
|
12
11
|
import type { I18n } from "./types";
|
|
13
12
|
import { defaultLocale } from "./defaultLocale";
|
|
14
13
|
import { tInterpolateParams } from "./tInterpolateParams";
|
|
@@ -22,7 +21,7 @@ const allowEmptyStrings = true;
|
|
|
22
21
|
/**
|
|
23
22
|
* @see https://github.com/aralroca/next-translate/blob/master/src/transCore.tsx
|
|
24
23
|
*/
|
|
25
|
-
export function createT
|
|
24
|
+
export function createT(
|
|
26
25
|
dictionaries: I18n.Dictionaries,
|
|
27
26
|
pluralRules: Intl.PluralRules,
|
|
28
27
|
locale: string = defaultLocale,
|
|
@@ -52,7 +51,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
52
51
|
query?: I18n.TranslationQuery,
|
|
53
52
|
options?: I18n.TranslationOptions,
|
|
54
53
|
): TReturn => {
|
|
55
|
-
const [namespace, key] = path.split("${
|
|
54
|
+
const [namespace, key] = path.split("${t.translations.tokens.namespaceDelimiter}");
|
|
56
55
|
const dic = (namespace && dictionaries[namespace]) || {};
|
|
57
56
|
const pluralisedKey = getPluralisedKey(pluralRules, dic, key, query, options);
|
|
58
57
|
const dicValue = getDicValue(dic, pluralisedKey, query, options);
|
|
@@ -64,6 +63,7 @@ export function createT<TNamespace extends I18n.TranslateNamespace>(
|
|
|
64
63
|
const empty =
|
|
65
64
|
typeof value === "undefined" ||
|
|
66
65
|
(typeof value === "object" && !Object.keys(value).length) ||
|
|
66
|
+
(Array.isArray(value) && !value.length) ||
|
|
67
67
|
(value === "" && !allowEmptyStrings);
|
|
68
68
|
|
|
69
69
|
// no need to try interpolation
|
|
@@ -166,10 +166,6 @@ function interpolation(
|
|
|
166
166
|
if (!text || !query || query === "obj") return text || "";
|
|
167
167
|
|
|
168
168
|
return tInterpolateParams(text, query);
|
|
169
|
-
// return Object.keys(query).reduce((all, key) => {
|
|
170
|
-
// const regex = new RegExp(\`${escapeEachChar(r)}\\s*\${key}(?:[\\s,]+([\\w-]*))?\\s*\$${escapeEachChar(a)}\`, "gm");
|
|
171
|
-
// return all.replace(regex, (_match) => query[key as keyof typeof query] as string);
|
|
172
|
-
// }, text);
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
function objectInterpolation(
|
|
@@ -4,10 +4,10 @@ var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
|
4
4
|
|
|
5
5
|
var e = createAdapter.createGenerator("js", (t)=>({
|
|
6
6
|
defaultI18nMetadata: {
|
|
7
|
-
// dir: createGenerator.dirs.internal,
|
|
8
7
|
name: "defaultI18nMetadata",
|
|
9
8
|
ext: "ts",
|
|
10
|
-
|
|
9
|
+
index: !1,
|
|
10
|
+
content: ()=>`
|
|
11
11
|
import type { I18n } from "./types";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -2,10 +2,10 @@ import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
|
2
2
|
|
|
3
3
|
var e = createGenerator("js", (t)=>({
|
|
4
4
|
defaultI18nMetadata: {
|
|
5
|
-
// dir: createGenerator.dirs.internal,
|
|
6
5
|
name: "defaultI18nMetadata",
|
|
7
6
|
ext: "ts",
|
|
8
|
-
|
|
7
|
+
index: !1,
|
|
8
|
+
content: ()=>`
|
|
9
9
|
import type { I18n } from "./types";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
formatTo: {
|
|
9
|
-
name: "formatTo",
|
|
10
|
-
ext: "ts",
|
|
11
|
-
content: ()=>/* js */ `
|
|
12
|
-
import { defaultLocale } from "./defaultLocale";
|
|
5
|
+
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
6
|
+
var functions = require('../../compiler/functions.cjs.js');
|
|
7
|
+
var imports = require('../../compiler/imports.cjs.js');
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const formatTo = ({ hideDefaultLocaleInUrl: e })=>new functions.FunctionsCompiler({
|
|
10
|
+
imports: [
|
|
11
|
+
new imports.ImportsCompiler({
|
|
12
|
+
path: "defaultLocale",
|
|
13
|
+
named: [
|
|
14
|
+
{
|
|
15
|
+
name: "defaultLocale"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
})
|
|
19
|
+
],
|
|
20
|
+
comment: {
|
|
21
|
+
internal: !0
|
|
22
|
+
},
|
|
23
|
+
name: "tInterpolateParams",
|
|
24
|
+
args: [
|
|
25
|
+
{
|
|
26
|
+
name: "locale",
|
|
27
|
+
type: "string | undefined",
|
|
28
|
+
optional: !1
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "pathname",
|
|
32
|
+
type: "string",
|
|
33
|
+
optional: !1
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "params",
|
|
37
|
+
type: "object",
|
|
38
|
+
optional: !0
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
body: ({ format: a })=>`{
|
|
22
42
|
locale = locale || defaultLocale;
|
|
23
43
|
if (process.env["NODE_ENV"] === "development") {
|
|
24
44
|
if (params) {
|
|
25
45
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
26
|
-
const key = dynamicKey as Extract<keyof typeof params, string
|
|
46
|
+
const key = dynamicKey${"ts" === a ? " as Extract<keyof typeof params, string>" : ""};
|
|
27
47
|
|
|
28
48
|
if (!(key in params)) {
|
|
29
49
|
console.warn(
|
|
@@ -56,21 +76,35 @@ export function formatTo(
|
|
|
56
76
|
pathname = pathname.replace(
|
|
57
77
|
/\\[(.*?)\\]/g,
|
|
58
78
|
(_, key) =>
|
|
59
|
-
params[key as keyof typeof params] + "",
|
|
79
|
+
params[key${"ts" === a ? " as keyof typeof params" : ""}] + "",
|
|
60
80
|
)
|
|
61
81
|
}
|
|
62
|
-
${
|
|
82
|
+
${e ? `
|
|
63
83
|
if (locale !== defaultLocale) {
|
|
64
84
|
return "/" + locale + (pathname === "/" ? "" : pathname);
|
|
65
85
|
}
|
|
66
86
|
` : ""}
|
|
67
87
|
return pathname;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
}`
|
|
89
|
+
});
|
|
90
|
+
var a = createAdapter.createGenerator("js", (e)=>{
|
|
91
|
+
let { config: a } = e;
|
|
92
|
+
return {
|
|
93
|
+
formatTo: {
|
|
94
|
+
name: "formatTo",
|
|
95
|
+
ext: "ts",
|
|
96
|
+
index: !1,
|
|
97
|
+
content: ()=>`
|
|
98
|
+
${formatTo(a).$out("ts", {
|
|
99
|
+
imports: {
|
|
100
|
+
folderUp: 0
|
|
101
|
+
},
|
|
102
|
+
exports: "named"
|
|
103
|
+
})}
|
|
71
104
|
`
|
|
72
105
|
}
|
|
73
106
|
};
|
|
74
107
|
});
|
|
75
108
|
|
|
76
|
-
|
|
109
|
+
exports.default = a;
|
|
110
|
+
exports.formatTo = formatTo;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { FunctionsCompiler } from "../../compiler/functions";
|
|
2
|
+
import type { I18nCompiler } from "../../compiler/types";
|
|
3
|
+
export declare const formatTo: ({ hideDefaultLocaleInUrl, }: Pick<I18nCompiler.Config, "hideDefaultLocaleInUrl">) => FunctionsCompiler;
|
|
4
|
+
declare const _default: (data: I18nCompiler.DataCode<"js">) => {
|
|
2
5
|
formatTo: {
|
|
3
6
|
name: string;
|
|
4
7
|
ext: "ts";
|
|
8
|
+
index: false;
|
|
5
9
|
content: () => string;
|
|
6
10
|
};
|
|
7
11
|
};
|
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
|
+
import { FunctionsCompiler } from '../../compiler/functions.esm.js';
|
|
3
|
+
import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
const formatTo = ({ hideDefaultLocaleInUrl: e })=>new FunctionsCompiler({
|
|
6
|
+
imports: [
|
|
7
|
+
new ImportsCompiler({
|
|
8
|
+
path: "defaultLocale",
|
|
9
|
+
named: [
|
|
10
|
+
{
|
|
11
|
+
name: "defaultLocale"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
})
|
|
15
|
+
],
|
|
16
|
+
comment: {
|
|
17
|
+
internal: !0
|
|
18
|
+
},
|
|
19
|
+
name: "tInterpolateParams",
|
|
20
|
+
args: [
|
|
21
|
+
{
|
|
22
|
+
name: "locale",
|
|
23
|
+
type: "string | undefined",
|
|
24
|
+
optional: !1
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "pathname",
|
|
28
|
+
type: "string",
|
|
29
|
+
optional: !1
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "params",
|
|
33
|
+
type: "object",
|
|
34
|
+
optional: !0
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
body: ({ format: a })=>`{
|
|
20
38
|
locale = locale || defaultLocale;
|
|
21
39
|
if (process.env["NODE_ENV"] === "development") {
|
|
22
40
|
if (params) {
|
|
23
41
|
pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
|
|
24
|
-
const key = dynamicKey as Extract<keyof typeof params, string
|
|
42
|
+
const key = dynamicKey${"ts" === a ? " as Extract<keyof typeof params, string>" : ""};
|
|
25
43
|
|
|
26
44
|
if (!(key in params)) {
|
|
27
45
|
console.warn(
|
|
@@ -54,21 +72,34 @@ export function formatTo(
|
|
|
54
72
|
pathname = pathname.replace(
|
|
55
73
|
/\\[(.*?)\\]/g,
|
|
56
74
|
(_, key) =>
|
|
57
|
-
params[key as keyof typeof params] + "",
|
|
75
|
+
params[key${"ts" === a ? " as keyof typeof params" : ""}] + "",
|
|
58
76
|
)
|
|
59
77
|
}
|
|
60
|
-
${
|
|
78
|
+
${e ? `
|
|
61
79
|
if (locale !== defaultLocale) {
|
|
62
80
|
return "/" + locale + (pathname === "/" ? "" : pathname);
|
|
63
81
|
}
|
|
64
82
|
` : ""}
|
|
65
83
|
return pathname;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
}`
|
|
85
|
+
});
|
|
86
|
+
var a = createGenerator("js", (e)=>{
|
|
87
|
+
let { config: a } = e;
|
|
88
|
+
return {
|
|
89
|
+
formatTo: {
|
|
90
|
+
name: "formatTo",
|
|
91
|
+
ext: "ts",
|
|
92
|
+
index: !1,
|
|
93
|
+
content: ()=>`
|
|
94
|
+
${formatTo(a).$out("ts", {
|
|
95
|
+
imports: {
|
|
96
|
+
folderUp: 0
|
|
97
|
+
},
|
|
98
|
+
exports: "named"
|
|
99
|
+
})}
|
|
69
100
|
`
|
|
70
101
|
}
|
|
71
102
|
};
|
|
72
103
|
});
|
|
73
104
|
|
|
74
|
-
export { a as default };
|
|
105
|
+
export { a as default, formatTo };
|
|
@@ -3,22 +3,21 @@
|
|
|
3
3
|
var createAdapter = require('../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
5
|
var m = createAdapter.createGenerator("js", (e)=>{
|
|
6
|
-
let { config: { baseUrl:
|
|
6
|
+
let { config: { baseUrl: a, trailingSlash: t } } = e;
|
|
7
7
|
return {
|
|
8
8
|
formatUrl: {
|
|
9
9
|
name: "formatUrl",
|
|
10
10
|
ext: "ts",
|
|
11
11
|
index: !0,
|
|
12
|
-
content: ()
|
|
12
|
+
content: ()=>`
|
|
13
13
|
/**
|
|
14
14
|
* Returns an absolute normalised URL prepending the \`baseUrl\` i18n option to
|
|
15
15
|
* the given pathname. It respects the \`trailingSlash\` option.
|
|
16
16
|
*
|
|
17
|
+
* @internal
|
|
17
18
|
* @param pathname Normalised, always prepended with a locale (if needed) and a slash
|
|
18
19
|
*/
|
|
19
|
-
export const formatUrl = (pathname: string) => "${
|
|
20
|
-
|
|
21
|
-
export default formatUrl;
|
|
20
|
+
export const formatUrl = (pathname: string) => "${a}" + ${t ? "pathname" : '(pathname === "/" ? "" : pathname)'};
|
|
22
21
|
`
|
|
23
22
|
}
|
|
24
23
|
};
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { createGenerator } from '../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
3
|
var m = createGenerator("js", (e)=>{
|
|
4
|
-
let { config: { baseUrl:
|
|
4
|
+
let { config: { baseUrl: a, trailingSlash: t } } = e;
|
|
5
5
|
return {
|
|
6
6
|
formatUrl: {
|
|
7
7
|
name: "formatUrl",
|
|
8
8
|
ext: "ts",
|
|
9
9
|
index: !0,
|
|
10
|
-
content: ()
|
|
10
|
+
content: ()=>`
|
|
11
11
|
/**
|
|
12
12
|
* Returns an absolute normalised URL prepending the \`baseUrl\` i18n option to
|
|
13
13
|
* the given pathname. It respects the \`trailingSlash\` option.
|
|
14
14
|
*
|
|
15
|
+
* @internal
|
|
15
16
|
* @param pathname Normalised, always prepended with a locale (if needed) and a slash
|
|
16
17
|
*/
|
|
17
|
-
export const formatUrl = (pathname: string) => "${
|
|
18
|
-
|
|
19
|
-
export default formatUrl;
|
|
18
|
+
export const formatUrl = (pathname: string) => "${a}" + ${t ? "pathname" : '(pathname === "/" ? "" : pathname)'};
|
|
20
19
|
`
|
|
21
20
|
}
|
|
22
21
|
};
|
|
@@ -7,13 +7,12 @@ var s = createAdapter.createGenerator("js", (e)=>({
|
|
|
7
7
|
getI18nDictionaries: {
|
|
8
8
|
name: "getI18nDictionaries",
|
|
9
9
|
ext: "ts",
|
|
10
|
-
|
|
10
|
+
index: !1,
|
|
11
|
+
content: ()=>`
|
|
11
12
|
import { defaultLocale } from "./defaultLocale";
|
|
12
13
|
import type { I18n } from "./types";
|
|
13
14
|
|
|
14
15
|
${getI18nDictionaries_inline.getI18nDictionaries_inline(0, !0)}
|
|
15
|
-
|
|
16
|
-
// export default getI18nDictionaries;
|
|
17
16
|
`
|
|
18
17
|
}
|
|
19
18
|
}));
|
|
@@ -5,13 +5,12 @@ var s = createGenerator("js", (e)=>({
|
|
|
5
5
|
getI18nDictionaries: {
|
|
6
6
|
name: "getI18nDictionaries",
|
|
7
7
|
ext: "ts",
|
|
8
|
-
|
|
8
|
+
index: !1,
|
|
9
|
+
content: ()=>`
|
|
9
10
|
import { defaultLocale } from "./defaultLocale";
|
|
10
11
|
import type { I18n } from "./types";
|
|
11
12
|
|
|
12
13
|
${getI18nDictionaries_inline(0, !0)}
|
|
13
|
-
|
|
14
|
-
// export default getI18nDictionaries;
|
|
15
14
|
`
|
|
16
15
|
}
|
|
17
16
|
}));
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var loadTranslations_inline = require('./loadTranslations_inline.cjs.js');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* @requires {defaultLocale, I18n}
|
|
7
|
-
*/ const getI18nDictionaries_inline = (n, i)=>`
|
|
5
|
+
const getI18nDictionaries_inline = (n, i)=>`
|
|
8
6
|
// import { loadTranslations } from "./loadTranslations";
|
|
9
7
|
|
|
10
8
|
${loadTranslations_inline.loadTranslations_inline(n)}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { loadTranslations_inline } from './loadTranslations_inline.esm.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* @requires {defaultLocale, I18n}
|
|
5
|
-
*/ const getI18nDictionaries_inline = (n, i)=>`
|
|
3
|
+
const getI18nDictionaries_inline = (n, i)=>`
|
|
6
4
|
// import { loadTranslations } from "./loadTranslations";
|
|
7
5
|
|
|
8
6
|
${loadTranslations_inline(n)}
|
|
@@ -8,8 +8,8 @@ var n = createAdapter.createGenerator("js", (t)=>{
|
|
|
8
8
|
getI18nMetadata: {
|
|
9
9
|
name: "getI18nMetadata",
|
|
10
10
|
ext: "ts",
|
|
11
|
-
|
|
12
|
-
content: ()
|
|
11
|
+
index: !1,
|
|
12
|
+
content: ()=>`
|
|
13
13
|
import { defaultI18nMetadata } from "./defaultI18nMetadata";
|
|
14
14
|
import { defaultLocale } from "./defaultLocale";
|
|
15
15
|
import { formatUrl } from "./formatUrl";
|
|
@@ -23,7 +23,7 @@ type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
|
23
23
|
} & I18n.RouteArgs<TRouteId>;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* - All localised variants should always be included (despite the current
|
|
26
|
+
* - All localised variants should always be included (despite the current locale)
|
|
27
27
|
* - We use the defaultLocale's URL as the \`x-default\` alternate value
|
|
28
28
|
* @see https://developers.google.com/search/docs/specialty/international/localized-versions#html
|
|
29
29
|
*
|
|
@@ -57,8 +57,6 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
57
57
|
),` : e.length ? "to(id, params, currentLocale))," : "to(id, currentLocale)),"}
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
// export default getI18nMetadata;
|
|
62
60
|
`
|
|
63
61
|
}
|
|
64
62
|
};
|