astro-i18nya 0.1.3 → 0.2.1
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 +2 -2
- package/dist/Trans.d.ts +31 -0
- package/dist/Trans.d.ts.map +1 -0
- package/dist/Trans.js +81 -0
- package/dist/Trans.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/util.d.ts +21 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +24 -0
- package/dist/util.js.map +1 -0
- package/package.json +1 -1
- package/src/util.ts +9 -4
package/README.md
CHANGED
|
@@ -36,13 +36,13 @@ export default defineConfig({
|
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
Then for all pages in `src/pages/[lang]/*.astro`:
|
|
39
|
+
Then for all pages in `src/pages/[...lang]/*.astro`:
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
import i18nya, { makeT } from "../../i18n.ts";
|
|
43
43
|
import { makeGetStaticPaths } from "astro-i18nya";
|
|
44
44
|
const t = makeT(Astro.params.lang);
|
|
45
|
-
// generate paths only for languages in your `langs/` folder!
|
|
45
|
+
// generate paths only for languages in your `[...langs]/` folder!
|
|
46
46
|
export const getStaticPaths = makeGetStaticPaths(i18nya);
|
|
47
47
|
```
|
|
48
48
|
|
package/dist/Trans.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
t: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A fake version of `<Trans>` in `react-i18next` with *very different* behaviour.
|
|
8
|
+
*
|
|
9
|
+
* You feed in a list of empty elements in `<Trans>`. The structure will follow the translation strings.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: It is **HIGHLY RECOMMENDED** to use `experimentalReactChildren: true` for `@astrojs/react` in your astro config,
|
|
12
|
+
* otherwise this will not work correctly outside of `.tsx` files.
|
|
13
|
+
*
|
|
14
|
+
* @example ```tsx
|
|
15
|
+
* <Trans t={t("test", { user: "John" })}>
|
|
16
|
+
* <b />
|
|
17
|
+
* <a href="https://example.com" />
|
|
18
|
+
* </Trans>
|
|
19
|
+
* ```
|
|
20
|
+
* With `"test": "Hello <1>{{user}}</1>, welcome to <2><1>my site</1></2>."`, the above element will become:
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <b>Hello John</b>, welcome to <a href="https://example.com"><b>my site</b></a>.
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param children the list of tags.
|
|
26
|
+
* @param t return value of t()
|
|
27
|
+
* @returns ReactNode
|
|
28
|
+
*/
|
|
29
|
+
declare const _default: ({ children, t }: Props) => string | import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export default _default;
|
|
31
|
+
//# sourceMappingURL=Trans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Trans.d.ts","sourceRoot":"","sources":["../src/Trans.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,SAAS,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;0CAC+B,KAAK;AAAvC,wBAsDsC"}
|
package/dist/Trans.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
//? https://react.i18next.com/latest/trans-component
|
|
3
|
+
// do something similar to ↑
|
|
4
|
+
import { Children, cloneElement, isValidElement } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* A fake version of `<Trans>` in `react-i18next` with *very different* behaviour.
|
|
7
|
+
*
|
|
8
|
+
* You feed in a list of empty elements in `<Trans>`. The structure will follow the translation strings.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: It is **HIGHLY RECOMMENDED** to use `experimentalReactChildren: true` for `@astrojs/react` in your astro config,
|
|
11
|
+
* otherwise this will not work correctly outside of `.tsx` files.
|
|
12
|
+
*
|
|
13
|
+
* @example ```tsx
|
|
14
|
+
* <Trans t={t("test", { user: "John" })}>
|
|
15
|
+
* <b />
|
|
16
|
+
* <a href="https://example.com" />
|
|
17
|
+
* </Trans>
|
|
18
|
+
* ```
|
|
19
|
+
* With `"test": "Hello <1>{{user}}</1>, welcome to <2><1>my site</1></2>."`, the above element will become:
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <b>Hello John</b>, welcome to <a href="https://example.com"><b>my site</b></a>.
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param children the list of tags.
|
|
25
|
+
* @param t return value of t()
|
|
26
|
+
* @returns ReactNode
|
|
27
|
+
*/
|
|
28
|
+
export default (({ children, t }) => {
|
|
29
|
+
// find /<\/(\d+)>/g, where group 1 parse to int is largest
|
|
30
|
+
const maxTagId = Math.max(...t.match(/<\/(\d+)>/g).map((i) => parseInt(i.slice(2, -1))));
|
|
31
|
+
const inputs = Children.toArray(children).filter((c) => isValidElement(c));
|
|
32
|
+
if ((maxTagId ?? 0) > inputs.length) {
|
|
33
|
+
return t; // syntax error
|
|
34
|
+
}
|
|
35
|
+
const elms = []; // resulting list of elements
|
|
36
|
+
const tagStack = [];
|
|
37
|
+
for (let ch_idx = 0; ch_idx < t.length;) {
|
|
38
|
+
if (t.substring(ch_idx, ch_idx + 2) == "\\<") {
|
|
39
|
+
elms.push("<");
|
|
40
|
+
ch_idx += 2;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (t.substring(ch_idx, ch_idx + 2) == "</") {
|
|
44
|
+
let j = 0;
|
|
45
|
+
while (t[++j + ch_idx] != ">" && j + ch_idx < t.length)
|
|
46
|
+
;
|
|
47
|
+
const tag = Number.parseInt(t.substring(++ch_idx + 1, (ch_idx += j)));
|
|
48
|
+
if (Number.isNaN(tag)) {
|
|
49
|
+
elms.push(t.substring(ch_idx - j - 1, ch_idx));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
let { p, l } = tagStack.pop();
|
|
53
|
+
if (tag != p) {
|
|
54
|
+
return t; // syntax error
|
|
55
|
+
}
|
|
56
|
+
elms.push(cloneElement(inputs[p - 1], {}, ...elms.splice(l, elms.length - l)));
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (t[ch_idx] == "<") {
|
|
60
|
+
let j = 0;
|
|
61
|
+
while (t[++j + ch_idx] != ">" && j + ch_idx < t.length)
|
|
62
|
+
;
|
|
63
|
+
const tag = Number.parseInt(t.substring(++ch_idx, (ch_idx += j)));
|
|
64
|
+
if (Number.isNaN(tag)) {
|
|
65
|
+
elms.push(t.substring(ch_idx - j - 1, ch_idx));
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
tagStack.push({ p: tag, l: elms.length });
|
|
69
|
+
elms.push(""); // in order to splice later, contents inside a new tag element must start fresh
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (typeof elms[elms.length - 1] === "string") {
|
|
73
|
+
elms[elms.length - 1] += t[ch_idx++];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
elms.push(t[ch_idx++]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return _jsx(_Fragment, { children: elms });
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=Trans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Trans.js","sourceRoot":"","sources":["../src/Trans.tsx"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,4BAA4B;AAE5B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAQ/D;;;;;;;;;;;;;;;;;;;;;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AAC,EAAE,MAAM,CAAC,CAAC,CAAC;gBAC/C,SAAS;YACX,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,+EAA+E;YAC9F,SAAS;QACX,CAAC;QACD,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,4BAAG,IAAI,GAAI,CAAC;AACrB,CAAC,CAAoC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { I18Nya } from "i18nya";
|
|
2
|
+
import type { AstroIntegration } from "astro";
|
|
3
|
+
import Trans from "./Trans.js";
|
|
4
|
+
import { listLang, getLangName, makeGetStaticPaths } from "./util.js";
|
|
5
|
+
export { Trans, listLang, getLangName, makeGetStaticPaths };
|
|
6
|
+
export default function astroI18nya<T extends string | number | symbol>(i18nya: I18Nya<T>): AstroIntegration;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EACpE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAChB,gBAAgB,CAqBlB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Trans from "./Trans.js";
|
|
2
|
+
import { listLang, getLangName, makeGetStaticPaths } from "./util.js";
|
|
3
|
+
export { Trans, listLang, getLangName, makeGetStaticPaths };
|
|
4
|
+
export default function astroI18nya(i18nya) {
|
|
5
|
+
return {
|
|
6
|
+
name: "astro-i18nya",
|
|
7
|
+
hooks: {
|
|
8
|
+
"astro:config:setup": ({ updateConfig }) => {
|
|
9
|
+
updateConfig({
|
|
10
|
+
i18n: {
|
|
11
|
+
defaultLocale: i18nya.config.defaultLang,
|
|
12
|
+
locales: Object.keys(i18nya.translations),
|
|
13
|
+
routing: {
|
|
14
|
+
prefixDefaultLocale: false,
|
|
15
|
+
redirectToDefaultLocale: true,
|
|
16
|
+
fallbackType: "redirect",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
// required for <Trans>
|
|
20
|
+
// integrations: [react({ experimentalReactChildren: true })],
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,MAAiB;IAEjB,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE;gBACzC,YAAY,CAAC;oBACX,IAAI,EAAE;wBACJ,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW;wBACxC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;wBACzC,OAAO,EAAE;4BACP,mBAAmB,EAAE,KAAK;4BAC1B,uBAAuB,EAAE,IAAI;4BAC7B,YAAY,EAAE,UAAU;yBACzB;qBACF;oBACD,uBAAuB;oBACvB,8DAA8D;iBAC/D,CAAC,CAAC;YACL,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { I18Nya } from "i18nya";
|
|
2
|
+
/**
|
|
3
|
+
* Obtain the language name.
|
|
4
|
+
* @param lang the language locale
|
|
5
|
+
* @param displayLang in what language should the name of the language be shown. By default, use native language names.
|
|
6
|
+
* @returns language name
|
|
7
|
+
*/
|
|
8
|
+
export declare const getLangName: (lang: string, displayLang?: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* List out available languages.
|
|
11
|
+
* @param i18nya return value of `init()` from `i18nya`
|
|
12
|
+
* @param displayLang in what language should the name of the language be shown. By default, use native language names.
|
|
13
|
+
* @returns a map of language locale → language name
|
|
14
|
+
*/
|
|
15
|
+
export declare const listLang: <T extends string | number | symbol>(i18nya: I18Nya<T>, displayLang?: string) => Map<string, string>;
|
|
16
|
+
export declare const makeGetStaticPaths: <T extends string | number | symbol>(i18nya: I18Nya<T>) => () => Promise<{
|
|
17
|
+
params: {
|
|
18
|
+
lang: string;
|
|
19
|
+
};
|
|
20
|
+
}[]>;
|
|
21
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,WAIjD,CAAC;AAEd;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EACzD,QAAQ,MAAM,CAAC,CAAC,CAAC,EACjB,cAAc,MAAM,wBAOnB,CAAC;AAEJ,eAAO,MAAM,kBAAkB,GAC5B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC;;;;IAMnD,CAAC"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obtain the language name.
|
|
3
|
+
* @param lang the language locale
|
|
4
|
+
* @param displayLang in what language should the name of the language be shown. By default, use native language names.
|
|
5
|
+
* @returns language name
|
|
6
|
+
*/
|
|
7
|
+
export const getLangName = (lang, displayLang) => new Intl.DisplayNames([displayLang ?? lang], {
|
|
8
|
+
type: "language",
|
|
9
|
+
style: "narrow",
|
|
10
|
+
}).of(lang);
|
|
11
|
+
/**
|
|
12
|
+
* List out available languages.
|
|
13
|
+
* @param i18nya return value of `init()` from `i18nya`
|
|
14
|
+
* @param displayLang in what language should the name of the language be shown. By default, use native language names.
|
|
15
|
+
* @returns a map of language locale → language name
|
|
16
|
+
*/
|
|
17
|
+
export const listLang = (i18nya, displayLang) => new Map(Object.keys(i18nya.translations).map((l) => [
|
|
18
|
+
l,
|
|
19
|
+
getLangName(l.replace("_", "-"), displayLang),
|
|
20
|
+
]));
|
|
21
|
+
export const makeGetStaticPaths = (i18nya) => async () => Object.keys(i18nya.translations).map((lang) => lang === i18nya.config.defaultLang
|
|
22
|
+
? { params: { lang: undefined } }
|
|
23
|
+
: { params: { lang: lang } });
|
|
24
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,WAAoB,EAAE,EAAE,CAChE,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,EAAE;IAC3C,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,QAAQ;CAChB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAEd;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,MAAiB,EACjB,WAAoB,EACpB,EAAE,CACF,IAAI,GAAG,CACL,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1C,CAAC;IACD,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC;CAC9C,CAAC,CACH,CAAC;AAEJ,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAqC,MAAiB,EAAE,EAAE,CAC1D,KAAK,IAAI,EAAE,CACT,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5C,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,WAAW;IAChC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;IACjC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAC/B,CAAC"}
|
package/package.json
CHANGED
package/src/util.ts
CHANGED
|
@@ -7,7 +7,10 @@ import type { I18Nya } from "i18nya";
|
|
|
7
7
|
* @returns language name
|
|
8
8
|
*/
|
|
9
9
|
export const getLangName = (lang: string, displayLang?: string) =>
|
|
10
|
-
new Intl.DisplayNames([displayLang ?? lang], {
|
|
10
|
+
new Intl.DisplayNames([displayLang ?? lang], {
|
|
11
|
+
type: "language",
|
|
12
|
+
style: "narrow",
|
|
13
|
+
}).of(lang);
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* List out available languages.
|
|
@@ -29,6 +32,8 @@ export const listLang = <T extends string | number | symbol>(
|
|
|
29
32
|
export const makeGetStaticPaths =
|
|
30
33
|
<T extends string | number | symbol>(i18nya: I18Nya<T>) =>
|
|
31
34
|
async () =>
|
|
32
|
-
Object.keys(i18nya.translations)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
Object.keys(i18nya.translations).map((lang) =>
|
|
36
|
+
lang === i18nya.config.defaultLang
|
|
37
|
+
? { params: { lang: undefined } }
|
|
38
|
+
: { params: { lang: lang } },
|
|
39
|
+
);
|