Skip to content

Commit

Permalink
fix: wrong locales loading path on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabolus committed Jan 20, 2024
1 parent 21cd233 commit f9cbb12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from 'node:path';
import { renderToString } from 'react-dom/server';
import { RemixServer } from '@remix-run/react';
import type { EntryContext } from '@remix-run/node';
Expand All @@ -14,7 +13,7 @@ import Backend from 'i18next-fs-backend';
import createEmotionCache from './src/createEmotionCache';
import createTheme from './src/theme';
import PageStyles from './src/PageStyles';
import i18next from './i18next.server';
import i18next, { localesDirectory } from './i18next.server';
import i18n from './i18n';

export default async function handleRequest(
Expand All @@ -34,7 +33,7 @@ export default async function handleRequest(
...i18n, // spread the configuration
lng, // The locale we detected above
ns, // The namespaces the routes about to render wants to use
backend: { loadPath: resolve('./public/locales/{{lng}}/{{ns}}.json') },
backend: { loadPath: localesDirectory },
});

const cache = createEmotionCache();
Expand Down
11 changes: 10 additions & 1 deletion app/i18next.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { resolve } from 'node:path';
import { RemixI18Next } from 'remix-i18next';
import i18n from './i18n';

const publicDirectory = resolve(
import.meta.env.PROD ? './build/client' : './public',
);

export const localesDirectory = resolve(
publicDirectory,
'locales/{{lng}}/{{ns}}.json',
);

export const i18next = new RemixI18Next({
detection: {
supportedLanguages: i18n.supportedLngs,
Expand All @@ -13,7 +22,7 @@ export const i18next = new RemixI18Next({
i18next: {
...i18n,
backend: {
loadPath: resolve('./public/locales/{{lng}}/{{ns}}.json'),
loadPath: localesDirectory,
},
},
// The i18next plugins you want RemixI18next to use for `i18n.getFixedT` inside loaders and actions.
Expand Down

0 comments on commit f9cbb12

Please sign in to comment.