@rimelight/i18n 0.0.2 → 0.0.3
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/package.json +1 -1
- package/src/integration.ts +23 -2
- package/src/middleware/routing.ts +4 -2
- package/src/virtual.d.ts +5 -0
package/package.json
CHANGED
package/src/integration.ts
CHANGED
|
@@ -30,7 +30,10 @@ export function rimelightI18n(options?: RimelightI18nOptions): any {
|
|
|
30
30
|
const rimelightI18nCore: AstroIntegration = {
|
|
31
31
|
name: "@rimelight/i18n",
|
|
32
32
|
hooks: {
|
|
33
|
-
"astro:config:setup": ({ addMiddleware, updateConfig, logger }) => {
|
|
33
|
+
"astro:config:setup": ({ config, addMiddleware, updateConfig, logger }) => {
|
|
34
|
+
const locales = config.i18n?.locales ?? ["en"]
|
|
35
|
+
const defaultLocale = config.i18n?.defaultLocale ?? "en"
|
|
36
|
+
|
|
34
37
|
addMiddleware({
|
|
35
38
|
entrypoint: "@rimelight/i18n/middleware",
|
|
36
39
|
order: "pre"
|
|
@@ -39,7 +42,25 @@ export function rimelightI18n(options?: RimelightI18nOptions): any {
|
|
|
39
42
|
vite: {
|
|
40
43
|
ssr: {
|
|
41
44
|
noExternal: ["@rimelight/i18n"]
|
|
42
|
-
}
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
{
|
|
48
|
+
name: "vite-plugin-rimelight-i18n-config",
|
|
49
|
+
resolveId(id) {
|
|
50
|
+
if (id === "virtual:rimelight-i18n-config") {
|
|
51
|
+
return "\0" + id
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
load(id) {
|
|
55
|
+
if (id === "\0virtual:rimelight-i18n-config") {
|
|
56
|
+
return `
|
|
57
|
+
export const locales = ${JSON.stringify(locales)};
|
|
58
|
+
export const defaultLocale = ${JSON.stringify(defaultLocale)};
|
|
59
|
+
`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
43
64
|
}
|
|
44
65
|
})
|
|
45
66
|
if (validateExtraction) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { locales, defaultLocale } from "virtual:rimelight-i18n-config"
|
|
2
|
+
|
|
3
|
+
const SUPPORTED_LOCALES = new Set(locales)
|
|
4
|
+
const DEFAULT_LOCALE = defaultLocale
|
|
3
5
|
|
|
4
6
|
function getPreferredLocale(acceptLanguage: string | null): string {
|
|
5
7
|
if (!acceptLanguage) return DEFAULT_LOCALE
|