Skip to content

Commit

Permalink
language fix WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
NookieGrey committed Feb 18, 2025
1 parent 84fd732 commit 46e92e5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion i18n.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function createI18nInstance() {
.use(LanguageDetector)
.init({
fallbackLng: "en",
preload: ["en", "ru"],
ns: ["common", "auth", "chat"],
defaultNS: "common",
backend: {
Expand All @@ -24,6 +23,9 @@ export function createI18nInstance() {
react: {
useSuspense: false,
},
detection: {
caches: ["cookie"],
},
});

return instance;
Expand Down
3 changes: 3 additions & 0 deletions locales/en/chat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Chats"
}
6 changes: 0 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ app.use("*", async (req, res) => {
try {
const url = req.originalUrl.replace(base, "/");

const initialI18nStore = {};
req.i18n.languages.forEach((lng) => {
initialI18nStore[lng] = req.i18n.store.data[lng] || {};
});

/** @type {string} */
let template;
/** @type {import('./src/entry-server.ts').render} */
Expand All @@ -96,7 +91,6 @@ app.use("*", async (req, res) => {
`<!--i18n-head-->`,
`
<script>
window.initialI18nStore = ${JSON.stringify(initialI18nStore)};
window.initialLanguage = '${req.i18n.language}';
</script>
`,
Expand Down
13 changes: 9 additions & 4 deletions src/entry-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ i18next
.use(LanguageDetector)
.init(
{
lng: window.initialLanguage,
fallbackLng: "en",
debug: false,
resources: window.initialI18nStore,
ns: ["common", "auth", "chat"],
defaultNS: "common",
fallbackLng: window.initialLanguage,
react: {
useSuspense: false,
},
backend: {
loadPath: "/locales/{{lng}}/{{ns}}.json",
},
detection: {
caches: ["cookie"],
},
},
() => {
const preloadedState = window.__PRELOADED_STATE__ || {};
Expand Down

0 comments on commit 46e92e5

Please sign in to comment.