Skip to content

Commit

Permalink
feat: make base path for i18next resources configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cauboy authored and yassinedoghri committed Mar 9, 2023
1 parent c976ddf commit 4e4b057
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const AstroI18next: AstroI18nextGlobal = {
flatRoutes: {},
showDefaultLocale: false,
trailingSlash: "ignore",
resourcesBasePath: "/locales",
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -120,7 +120,7 @@ export default (options?: AstroI18nextOptions): AstroIntegration => {
caches: [],
},
backend: {
loadPath: "/locales/{{lng}}/{{ns}}.json",
loadPath: `${astroI18nextConfig.resourcesBasePath}/{{lng}}/{{ns}}.json`,
},
...astroI18nextConfig.i18nextClient,
};
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 4e4b057

Please sign in to comment.