@koine/i18n 2.0.0-beta.89 → 2.0.0-beta.91
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-react/code/useLocale.d.ts +1 -1
- package/api.cjs.js +23 -29
- package/api.esm.js +23 -29
- package/package.json +3 -3
package/api.cjs.js
CHANGED
|
@@ -435,6 +435,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
|
|
|
435
435
|
|
|
436
436
|
const alternates: I18n.Alternates = {
|
|
437
437
|
"x-default": toUrl(
|
|
438
|
+
// @ts-expect-error FIXME: route conditional type
|
|
438
439
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
439
440
|
),
|
|
440
441
|
};
|
|
@@ -442,6 +443,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
|
|
|
442
443
|
.filter((l) => l !== locale)
|
|
443
444
|
.forEach((locale) => {
|
|
444
445
|
alternates[locale] = toUrl(
|
|
446
|
+
// @ts-expect-error FIXME: route conditional type
|
|
445
447
|
params ? to(id, params, locale) : to(id, locale),
|
|
446
448
|
);
|
|
447
449
|
});
|
|
@@ -544,7 +546,8 @@ import { locales } from "./locales";
|
|
|
544
546
|
import type { I18n } from "./types";
|
|
545
547
|
|
|
546
548
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
547
|
-
export const isLocale = (payload: any): payload is I18n.Locale =>
|
|
549
|
+
export const isLocale = (payload: any): payload is I18n.Locale =>
|
|
550
|
+
locales.includes(payload);
|
|
548
551
|
|
|
549
552
|
export default isLocale;
|
|
550
553
|
`);
|
|
@@ -1768,6 +1771,7 @@ export const I18nAlternates = <TRouteId extends I18n.RouteId>(
|
|
|
1768
1771
|
const [alternates, setAlternates] = useContext(I18nAlternatesContext);
|
|
1769
1772
|
|
|
1770
1773
|
useEffect(() => {
|
|
1774
|
+
// @ts-expect-error FIXME: route conditional type
|
|
1771
1775
|
setAlternates(getAlternates({ locale, id, params }));
|
|
1772
1776
|
}, [id, params, locale, setAlternates]);
|
|
1773
1777
|
|
|
@@ -1843,7 +1847,7 @@ var o$7 = (({})=>`
|
|
|
1843
1847
|
"use client";
|
|
1844
1848
|
|
|
1845
1849
|
import Head from "next/head";
|
|
1846
|
-
import type { I18n } from "./
|
|
1850
|
+
import type { I18n } from "./types";
|
|
1847
1851
|
|
|
1848
1852
|
export type I18nHeadProps = {
|
|
1849
1853
|
alternates?: I18n.Alternates;
|
|
@@ -1950,6 +1954,7 @@ export const I18nPage = async <TRouteId extends I18n.RouteId>(
|
|
|
1950
1954
|
params,
|
|
1951
1955
|
children,
|
|
1952
1956
|
} = props;
|
|
1957
|
+
// @ts-expect-error FIXME: route conditional type
|
|
1953
1958
|
const alternates = await getAlternates({ locale, id, params });
|
|
1954
1959
|
const dictionaries = await getI18nDictionaries({ locale, namespaces });
|
|
1955
1960
|
|
|
@@ -1971,11 +1976,8 @@ export default I18nPage;
|
|
|
1971
1976
|
`);
|
|
1972
1977
|
|
|
1973
1978
|
var i$4 = (({ options: { routes: { localeParamName: o } } })=>`
|
|
1974
|
-
import { I18nProvider } from "./I18nProvider";
|
|
1975
1979
|
import { I18nAlternatesProvider } from "./I18nAlternatesProvider";
|
|
1976
1980
|
import { I18nRouteProvider } from "./I18nRouteProvider";
|
|
1977
|
-
import { defaultLocale } from "./defaultLocale";
|
|
1978
|
-
import { getI18nDictionaries } from "./getI18nDictionaries";
|
|
1979
1981
|
import type { I18n } from "./types";
|
|
1980
1982
|
|
|
1981
1983
|
export type I18nRootProps = React.PropsWithChildren;
|
|
@@ -1984,14 +1986,13 @@ const alternates = {};
|
|
|
1984
1986
|
|
|
1985
1987
|
/**
|
|
1986
1988
|
* Use this _only once_ in the root \`layout.tsx\` at root folder of your app
|
|
1987
|
-
* directory (one up than the \`[
|
|
1988
|
-
*
|
|
1989
|
+
* directory (one up than the \`[lang]\` folder).
|
|
1990
|
+
*
|
|
1989
1991
|
* **For App Router only**
|
|
1990
1992
|
*/
|
|
1991
1993
|
export const I18nRoot = ({ children }: I18nRootProps) => {
|
|
1992
|
-
|
|
1993
1994
|
return (
|
|
1994
|
-
<I18nRouteProvider id="">
|
|
1995
|
+
<I18nRouteProvider id={"" as I18n.RouteId}>
|
|
1995
1996
|
<I18nAlternatesProvider alternates={alternates}>
|
|
1996
1997
|
{children}
|
|
1997
1998
|
</I18nAlternatesProvider>
|
|
@@ -2047,6 +2048,7 @@ export async function i18nProps<TRouteId extends I18n.RouteId, TParams, TData>({
|
|
|
2047
2048
|
}: I18nPropsOptions<TRouteId, TParams, TData>) {
|
|
2048
2049
|
const i18n: I18nAppPropsData = {
|
|
2049
2050
|
locale: locale,
|
|
2051
|
+
// @ts-expect-error FIXME: route conditional type
|
|
2050
2052
|
alternates: getAlternates({ locale, id: routeId, params: routeParams }),
|
|
2051
2053
|
dictionaries: await getI18nDictionaries({ locale, namespaces }),
|
|
2052
2054
|
}
|
|
@@ -2698,16 +2700,16 @@ import { useContext, useEffect } from "react";
|
|
|
2698
2700
|
import { I18nRouteContext } from "./I18nRouteContext";
|
|
2699
2701
|
import type { I18n } from "./types";
|
|
2700
2702
|
|
|
2701
|
-
type
|
|
2702
|
-
id: I18n.
|
|
2703
|
+
type I18nRouteSetterProps = {
|
|
2704
|
+
id: I18n.RouteId;
|
|
2703
2705
|
};
|
|
2704
2706
|
|
|
2705
2707
|
/**
|
|
2706
2708
|
* NB: Do not use it next.js Pages router
|
|
2707
|
-
*
|
|
2709
|
+
*
|
|
2708
2710
|
* @internal
|
|
2709
2711
|
*/
|
|
2710
|
-
export const I18nRouteSetter = (props:
|
|
2712
|
+
export const I18nRouteSetter = (props: I18nRouteSetterProps) => {
|
|
2711
2713
|
const { id } = props;
|
|
2712
2714
|
const [, setRouteId] = useContext(I18nRouteContext);
|
|
2713
2715
|
|
|
@@ -2775,22 +2777,14 @@ var I$1 = (({})=>`
|
|
|
2775
2777
|
"use client";
|
|
2776
2778
|
|
|
2777
2779
|
import { useMemo } from "react";
|
|
2778
|
-
import { formatElements } from "./formatElements";
|
|
2779
2780
|
import type { TProps } from "./T";
|
|
2780
|
-
import
|
|
2781
|
+
import { formatElements } from "./formatElements";
|
|
2781
2782
|
|
|
2782
|
-
export type TransTextProps<
|
|
2783
|
-
TNamespace extends I18n.TranslateNamespace | undefined,
|
|
2784
|
-
> = Pick<TProps<TNamespace>, "components"> & {
|
|
2783
|
+
export type TransTextProps = Pick<TProps, "components"> & {
|
|
2785
2784
|
text: string;
|
|
2786
2785
|
};
|
|
2787
2786
|
|
|
2788
|
-
export const TransText =
|
|
2789
|
-
TNamespace extends I18n.TranslateNamespace | undefined,
|
|
2790
|
-
>({
|
|
2791
|
-
text,
|
|
2792
|
-
components,
|
|
2793
|
-
}: TransTextProps<TNamespace>) => {
|
|
2787
|
+
export const TransText = ({ text, components }: TransTextProps) => {
|
|
2794
2788
|
return useMemo(
|
|
2795
2789
|
() =>
|
|
2796
2790
|
!components || components.length === 0
|
|
@@ -2900,14 +2894,14 @@ export const useAlternates = (
|
|
|
2900
2894
|
export default useAlternates;
|
|
2901
2895
|
`);
|
|
2902
2896
|
|
|
2903
|
-
var u = (({
|
|
2897
|
+
var u = (({})=>`
|
|
2904
2898
|
"use client";
|
|
2905
2899
|
|
|
2906
2900
|
import { useContext } from "react";
|
|
2901
|
+
import { defaultLocale } from "./defaultLocale";
|
|
2907
2902
|
import { I18nContext } from "./I18nContext";
|
|
2908
|
-
import type { I18n } from "./types";
|
|
2909
2903
|
|
|
2910
|
-
export const useLocale = () => useContext(I18nContext).locale ||
|
|
2904
|
+
export const useLocale = () => useContext(I18nContext).locale || defaultLocale;
|
|
2911
2905
|
|
|
2912
2906
|
export default useLocale;
|
|
2913
2907
|
`);
|
|
@@ -2923,9 +2917,9 @@ export const useT = <T extends I18n.TranslateNamespace>(namespace: T) => {
|
|
|
2923
2917
|
const t = useContext(I18nContext).t;
|
|
2924
2918
|
return useMemo(
|
|
2925
2919
|
() =>
|
|
2926
|
-
(
|
|
2920
|
+
(key: string, ...args) =>
|
|
2927
2921
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2928
|
-
(t as any)(\`\${namespace}:\${
|
|
2922
|
+
(t as any)(\`\${namespace}:\${key}\`, ...args),
|
|
2929
2923
|
[t],
|
|
2930
2924
|
) as I18n.TranslateNamespaced<T>;
|
|
2931
2925
|
};
|
package/api.esm.js
CHANGED
|
@@ -413,6 +413,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
|
|
|
413
413
|
|
|
414
414
|
const alternates: I18n.Alternates = {
|
|
415
415
|
"x-default": toUrl(
|
|
416
|
+
// @ts-expect-error FIXME: route conditional type
|
|
416
417
|
params ? to(id, params, defaultLocale) : to(id, defaultLocale),
|
|
417
418
|
),
|
|
418
419
|
};
|
|
@@ -420,6 +421,7 @@ export function getAlternates<TRouteId extends I18n.RouteId>({
|
|
|
420
421
|
.filter((l) => l !== locale)
|
|
421
422
|
.forEach((locale) => {
|
|
422
423
|
alternates[locale] = toUrl(
|
|
424
|
+
// @ts-expect-error FIXME: route conditional type
|
|
423
425
|
params ? to(id, params, locale) : to(id, locale),
|
|
424
426
|
);
|
|
425
427
|
});
|
|
@@ -522,7 +524,8 @@ import { locales } from "./locales";
|
|
|
522
524
|
import type { I18n } from "./types";
|
|
523
525
|
|
|
524
526
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
525
|
-
export const isLocale = (payload: any): payload is I18n.Locale =>
|
|
527
|
+
export const isLocale = (payload: any): payload is I18n.Locale =>
|
|
528
|
+
locales.includes(payload);
|
|
526
529
|
|
|
527
530
|
export default isLocale;
|
|
528
531
|
`);
|
|
@@ -1746,6 +1749,7 @@ export const I18nAlternates = <TRouteId extends I18n.RouteId>(
|
|
|
1746
1749
|
const [alternates, setAlternates] = useContext(I18nAlternatesContext);
|
|
1747
1750
|
|
|
1748
1751
|
useEffect(() => {
|
|
1752
|
+
// @ts-expect-error FIXME: route conditional type
|
|
1749
1753
|
setAlternates(getAlternates({ locale, id, params }));
|
|
1750
1754
|
}, [id, params, locale, setAlternates]);
|
|
1751
1755
|
|
|
@@ -1821,7 +1825,7 @@ var o$7 = (({})=>`
|
|
|
1821
1825
|
"use client";
|
|
1822
1826
|
|
|
1823
1827
|
import Head from "next/head";
|
|
1824
|
-
import type { I18n } from "./
|
|
1828
|
+
import type { I18n } from "./types";
|
|
1825
1829
|
|
|
1826
1830
|
export type I18nHeadProps = {
|
|
1827
1831
|
alternates?: I18n.Alternates;
|
|
@@ -1928,6 +1932,7 @@ export const I18nPage = async <TRouteId extends I18n.RouteId>(
|
|
|
1928
1932
|
params,
|
|
1929
1933
|
children,
|
|
1930
1934
|
} = props;
|
|
1935
|
+
// @ts-expect-error FIXME: route conditional type
|
|
1931
1936
|
const alternates = await getAlternates({ locale, id, params });
|
|
1932
1937
|
const dictionaries = await getI18nDictionaries({ locale, namespaces });
|
|
1933
1938
|
|
|
@@ -1949,11 +1954,8 @@ export default I18nPage;
|
|
|
1949
1954
|
`);
|
|
1950
1955
|
|
|
1951
1956
|
var i$4 = (({ options: { routes: { localeParamName: o } } })=>`
|
|
1952
|
-
import { I18nProvider } from "./I18nProvider";
|
|
1953
1957
|
import { I18nAlternatesProvider } from "./I18nAlternatesProvider";
|
|
1954
1958
|
import { I18nRouteProvider } from "./I18nRouteProvider";
|
|
1955
|
-
import { defaultLocale } from "./defaultLocale";
|
|
1956
|
-
import { getI18nDictionaries } from "./getI18nDictionaries";
|
|
1957
1959
|
import type { I18n } from "./types";
|
|
1958
1960
|
|
|
1959
1961
|
export type I18nRootProps = React.PropsWithChildren;
|
|
@@ -1962,14 +1964,13 @@ const alternates = {};
|
|
|
1962
1964
|
|
|
1963
1965
|
/**
|
|
1964
1966
|
* Use this _only once_ in the root \`layout.tsx\` at root folder of your app
|
|
1965
|
-
* directory (one up than the \`[
|
|
1966
|
-
*
|
|
1967
|
+
* directory (one up than the \`[lang]\` folder).
|
|
1968
|
+
*
|
|
1967
1969
|
* **For App Router only**
|
|
1968
1970
|
*/
|
|
1969
1971
|
export const I18nRoot = ({ children }: I18nRootProps) => {
|
|
1970
|
-
|
|
1971
1972
|
return (
|
|
1972
|
-
<I18nRouteProvider id="">
|
|
1973
|
+
<I18nRouteProvider id={"" as I18n.RouteId}>
|
|
1973
1974
|
<I18nAlternatesProvider alternates={alternates}>
|
|
1974
1975
|
{children}
|
|
1975
1976
|
</I18nAlternatesProvider>
|
|
@@ -2025,6 +2026,7 @@ export async function i18nProps<TRouteId extends I18n.RouteId, TParams, TData>({
|
|
|
2025
2026
|
}: I18nPropsOptions<TRouteId, TParams, TData>) {
|
|
2026
2027
|
const i18n: I18nAppPropsData = {
|
|
2027
2028
|
locale: locale,
|
|
2029
|
+
// @ts-expect-error FIXME: route conditional type
|
|
2028
2030
|
alternates: getAlternates({ locale, id: routeId, params: routeParams }),
|
|
2029
2031
|
dictionaries: await getI18nDictionaries({ locale, namespaces }),
|
|
2030
2032
|
}
|
|
@@ -2676,16 +2678,16 @@ import { useContext, useEffect } from "react";
|
|
|
2676
2678
|
import { I18nRouteContext } from "./I18nRouteContext";
|
|
2677
2679
|
import type { I18n } from "./types";
|
|
2678
2680
|
|
|
2679
|
-
type
|
|
2680
|
-
id: I18n.
|
|
2681
|
+
type I18nRouteSetterProps = {
|
|
2682
|
+
id: I18n.RouteId;
|
|
2681
2683
|
};
|
|
2682
2684
|
|
|
2683
2685
|
/**
|
|
2684
2686
|
* NB: Do not use it next.js Pages router
|
|
2685
|
-
*
|
|
2687
|
+
*
|
|
2686
2688
|
* @internal
|
|
2687
2689
|
*/
|
|
2688
|
-
export const I18nRouteSetter = (props:
|
|
2690
|
+
export const I18nRouteSetter = (props: I18nRouteSetterProps) => {
|
|
2689
2691
|
const { id } = props;
|
|
2690
2692
|
const [, setRouteId] = useContext(I18nRouteContext);
|
|
2691
2693
|
|
|
@@ -2753,22 +2755,14 @@ var I$1 = (({})=>`
|
|
|
2753
2755
|
"use client";
|
|
2754
2756
|
|
|
2755
2757
|
import { useMemo } from "react";
|
|
2756
|
-
import { formatElements } from "./formatElements";
|
|
2757
2758
|
import type { TProps } from "./T";
|
|
2758
|
-
import
|
|
2759
|
+
import { formatElements } from "./formatElements";
|
|
2759
2760
|
|
|
2760
|
-
export type TransTextProps<
|
|
2761
|
-
TNamespace extends I18n.TranslateNamespace | undefined,
|
|
2762
|
-
> = Pick<TProps<TNamespace>, "components"> & {
|
|
2761
|
+
export type TransTextProps = Pick<TProps, "components"> & {
|
|
2763
2762
|
text: string;
|
|
2764
2763
|
};
|
|
2765
2764
|
|
|
2766
|
-
export const TransText =
|
|
2767
|
-
TNamespace extends I18n.TranslateNamespace | undefined,
|
|
2768
|
-
>({
|
|
2769
|
-
text,
|
|
2770
|
-
components,
|
|
2771
|
-
}: TransTextProps<TNamespace>) => {
|
|
2765
|
+
export const TransText = ({ text, components }: TransTextProps) => {
|
|
2772
2766
|
return useMemo(
|
|
2773
2767
|
() =>
|
|
2774
2768
|
!components || components.length === 0
|
|
@@ -2878,14 +2872,14 @@ export const useAlternates = (
|
|
|
2878
2872
|
export default useAlternates;
|
|
2879
2873
|
`);
|
|
2880
2874
|
|
|
2881
|
-
var u = (({
|
|
2875
|
+
var u = (({})=>`
|
|
2882
2876
|
"use client";
|
|
2883
2877
|
|
|
2884
2878
|
import { useContext } from "react";
|
|
2879
|
+
import { defaultLocale } from "./defaultLocale";
|
|
2885
2880
|
import { I18nContext } from "./I18nContext";
|
|
2886
|
-
import type { I18n } from "./types";
|
|
2887
2881
|
|
|
2888
|
-
export const useLocale = () => useContext(I18nContext).locale ||
|
|
2882
|
+
export const useLocale = () => useContext(I18nContext).locale || defaultLocale;
|
|
2889
2883
|
|
|
2890
2884
|
export default useLocale;
|
|
2891
2885
|
`);
|
|
@@ -2901,9 +2895,9 @@ export const useT = <T extends I18n.TranslateNamespace>(namespace: T) => {
|
|
|
2901
2895
|
const t = useContext(I18nContext).t;
|
|
2902
2896
|
return useMemo(
|
|
2903
2897
|
() =>
|
|
2904
|
-
(
|
|
2898
|
+
(key: string, ...args) =>
|
|
2905
2899
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2906
|
-
(t as any)(\`\${namespace}:\${
|
|
2900
|
+
(t as any)(\`\${namespace}:\${key}\`, ...args),
|
|
2907
2901
|
[t],
|
|
2908
2902
|
) as I18n.TranslateNamespaced<T>;
|
|
2909
2903
|
};
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/i18n",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/node": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/node": "2.0.0-beta.91",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.91",
|
|
7
7
|
"glob": "^10.3.10",
|
|
8
8
|
"webpack": "^5.90.1",
|
|
9
9
|
"minimatch": "^9.0.3",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
},
|
|
59
59
|
"module": "./index.esm.js",
|
|
60
60
|
"main": "./index.cjs.js",
|
|
61
|
-
"version": "2.0.0-beta.
|
|
61
|
+
"version": "2.0.0-beta.91"
|
|
62
62
|
}
|