@rimelight/i18n 0.0.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimelight/i18n",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "private": false,
5
5
  "description": "Rimelight i18n — unified translation loader with optional KV backing",
6
6
  "files": [
@@ -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) {
@@ -87,7 +108,7 @@ export function rimelightI18n(options?: RimelightI18nOptions): any {
87
108
  return [
88
109
  nanostoresI18n({
89
110
  translationLoader,
90
- addMiddleware: true,
111
+ addMiddleware: false,
91
112
  translations: nanostoresTranslations
92
113
  }),
93
114
  rimelightI18nCore
@@ -1,5 +1,7 @@
1
- const SUPPORTED_LOCALES = new Set(["en", "pt", "es"])
2
- const DEFAULT_LOCALE = "en"
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
package/src/virtual.d.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  declare module "astro-nanostores-i18n:runtime" {
2
2
  export * from "astro-nanostores-i18n/runtime"
3
3
  }
4
+
5
+ declare module "virtual:rimelight-i18n-config" {
6
+ export const locales: string[]
7
+ export const defaultLocale: string
8
+ }