Skip to content

Commit 46e92e5

Browse files
committedFeb 18, 2025
language fix WIP
1 parent 84fd732 commit 46e92e5

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed
 

‎i18n.server.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function createI18nInstance() {
1515
.use(LanguageDetector)
1616
.init({
1717
fallbackLng: "en",
18-
preload: ["en", "ru"],
1918
ns: ["common", "auth", "chat"],
2019
defaultNS: "common",
2120
backend: {
@@ -24,6 +23,9 @@ export function createI18nInstance() {
2423
react: {
2524
useSuspense: false,
2625
},
26+
detection: {
27+
caches: ["cookie"],
28+
},
2729
});
2830

2931
return instance;

‎locales/en/chat.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"title": "Chats"
3+
}

‎server.js

-6
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ app.use("*", async (req, res) => {
6666
try {
6767
const url = req.originalUrl.replace(base, "/");
6868

69-
const initialI18nStore = {};
70-
req.i18n.languages.forEach((lng) => {
71-
initialI18nStore[lng] = req.i18n.store.data[lng] || {};
72-
});
73-
7469
/** @type {string} */
7570
let template;
7671
/** @type {import('./src/entry-server.ts').render} */
@@ -96,7 +91,6 @@ app.use("*", async (req, res) => {
9691
`<!--i18n-head-->`,
9792
`
9893
<script>
99-
window.initialI18nStore = ${JSON.stringify(initialI18nStore)};
10094
window.initialLanguage = '${req.i18n.language}';
10195
</script>
10296
`,

‎src/entry-client.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ i18next
1010
.use(LanguageDetector)
1111
.init(
1212
{
13-
lng: window.initialLanguage,
14-
fallbackLng: "en",
15-
debug: false,
16-
resources: window.initialI18nStore,
13+
ns: ["common", "auth", "chat"],
14+
defaultNS: "common",
15+
fallbackLng: window.initialLanguage,
1716
react: {
1817
useSuspense: false,
1918
},
19+
backend: {
20+
loadPath: "/locales/{{lng}}/{{ns}}.json",
21+
},
22+
detection: {
23+
caches: ["cookie"],
24+
},
2025
},
2126
() => {
2227
const preloadedState = window.__PRELOADED_STATE__ || {};

0 commit comments

Comments
 (0)
Please sign in to comment.