astro-i18nya 0.1.3 → 0.2.0
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/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/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
|
+
);
|