diff --git a/README.md b/README.md index dcc6da2..1865b2f 100644 --- a/README.md +++ b/README.md @@ -568,6 +568,7 @@ your config! | namespaces | `string` or `string[]` ('translation') | String or array of namespaces to load. | | defaultNamespace | `string` (translation') | Default namespace used if not passed to the translation function. | | load | `Array<"server" or "client">` (`["server"]`) | Load i18next on server side only, client side only or both. | +| resourcesBasePath | `?string` | Set base path for i18next resources. Defaults to `/locales`. | | i18nextServer | `?InitOptions` | The i18next server side configuration. See [i18next's documentation](https://www.i18next.com/overview/configuration-options). | | i18nextServerPlugins | `?{[key: string]: string}` (`{}`) | Set i18next server side plugins. See [available plugins](https://www.i18next.com/overview/plugins-and-utils). | | i18nextClient | `?InitOptions` | The i18next client side configuration . See [i18next's documentation](https://www.i18next.com/overview/configuration-options). | diff --git a/src/config.ts b/src/config.ts index 77bf993..cadc5de 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,7 @@ export const AstroI18next: AstroI18nextGlobal = { flatRoutes: {}, showDefaultLocale: false, trailingSlash: "ignore", + resourcesBasePath: "/locales", }, }; diff --git a/src/index.ts b/src/index.ts index 879c96a..782d5bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,7 +78,7 @@ export default (options?: AstroI18nextOptions): AstroIntegration => { initImmediate: false, backend: { loadPath: resolve( - config.publicDir.pathname + "/locales/{{lng}}/{{ns}}.json" + `${config.publicDir.pathname}/${astroI18nextConfig.resourcesBasePath}/{{lng}}/{{ns}}.json` ), }, ...astroI18nextConfig.i18nextServer, @@ -120,7 +120,7 @@ export default (options?: AstroI18nextOptions): AstroIntegration => { caches: [], }, backend: { - loadPath: "/locales/{{lng}}/{{ns}}.json", + loadPath: `${astroI18nextConfig.resourcesBasePath}/{{lng}}/{{ns}}.json`, }, ...astroI18nextConfig.i18nextClient, }; diff --git a/src/types.ts b/src/types.ts index 217e634..3897871 100644 --- a/src/types.ts +++ b/src/types.ts @@ -57,6 +57,13 @@ export interface AstroI18nextConfig { */ load?: ("server" | "client")[]; + /** + * Set base path for i18next resources. + * + * @default ["/locales"] + */ + resourcesBasePath?: string; + /** * i18next server side config. See https://www.i18next.com/overview/configuration-options */