Skip to content

Commit 6b8b427

Browse files
aastefanovroot
authored andcommitted
Load localles from source
This fixes the issue with cache stalessness in the only vite-friendly way we have :/
1 parent 67db0ab commit 6b8b427

7 files changed

Lines changed: 408 additions & 31 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"typescript": "^5.9.3",
5454
"typescript-eslint": "^8.54.0",
5555
"typescript-plugin-css-modules": "^5.2.0",
56-
"vite": "^7.3.0"
56+
"vite": "^7.3.0",
57+
"vite-plugin-i18next-loader": "^3.1.3"
5758
}
5859
}

src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {createElement, useEffect} from 'react';
1+
import {createElement, useEffect, Suspense} from 'react';
22
import {Container} from 'react-bootstrap';
33
import {Route, Routes} from 'react-router-dom';
44

5+
import LoadingIcon from './widgets/LoadingIcon.tsx';
56
import NavBar from './layout/NavBar.tsx';
67
import Footer from './layout/Footer.tsx';
78
import Sensors from './pages/Sensors.tsx';
@@ -22,7 +23,7 @@ function App() {
2223
const [theme] = useTheme();
2324
useEffect(() => document.documentElement.setAttribute('data-bs-theme', theme), [theme]);
2425

25-
return (<>
26+
return (<Suspense fallback={<LoadingIcon/>}>
2627
<NavBar/>
2728
<main>
2829
<Container as="section" className="mt-4">
@@ -46,7 +47,7 @@ function App() {
4647
</Container>
4748
</main>
4849
<Footer/>
49-
</>);
50+
</Suspense>);
5051
}
5152

5253
export default App;

src/i18n.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import Backend from 'i18next-http-backend';
33
import {initReactI18next} from 'react-i18next';
44
import {load} from 'js-yaml';
55

6+
import resources from 'virtual:i18next-loader';
7+
68
i18n
7-
.use(Backend)
89
.use(initReactI18next)
10+
.on('failedLoading', (lng, ns, msg) => console.error(msg))
911
.init({
10-
backend: {
11-
loadPath: import.meta.env.BASE_URL + 'locales/{{lng}}.yaml',
12-
parse: (data: any) => load(data),
13-
},
1412
interpolation: {
1513
escapeValue: false,
1614
},
15+
// I hate this, but i18next changed the format
16+
resources: Object.fromEntries(Object.entries(resources).map(x => [x[0], ({translation: x[1]})])),
17+
detection: {
18+
supportedLanguages: ["en", "bg"],
19+
},
1720
})
1821
.then();
1922

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ views:
126126
имейл us@initlab.org.
127127
colibri_message_emergency: При неотложни случаи, моля обадете се на тел. 02 422 54 36.
128128
devices:
129-
lock: заключи
130-
unlock: отключи
131-
open: отвори
132-
open_alternative: отвори
133-
turn_off: изключи
134-
turn_on: включи
135-
turn_on_cooling: охлаждане
136-
turn_on_heating: отопление
129+
lock: Заключи
130+
unlock: Отключи
131+
open: Отвори
132+
open_alternative: Отвори
133+
turn_off: Изключи
134+
turn_on: Включи
135+
turn_on_cooling: Охлаждане
136+
turn_on_heating: Отопление
137137
offline: В момента няма връзка с устройството
138138
door:
139139
locked: Заключено
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ views:
119119
at us@initlab.org.
120120
colibri_message_emergency: In case of major malfunction, please call +359 2 422 54 36.
121121
devices:
122-
lock: lock
123-
unlock: unlock
124-
open: open
125-
open_alternative: open
126-
turn_off: turn off
127-
turn_on: turn on
128-
turn_on_cooling: cooling
129-
turn_on_heating: heating
122+
lock: Lock
123+
unlock: Unlock
124+
open: Open
125+
open_alternative: Open
126+
turn_off: Turn off
127+
turn_on: Turn on
128+
turn_on_cooling: Cooling
129+
turn_on_heating: Heating
130130
offline: Device is currently offline
131131
door:
132132
locked: Locked

vite.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {defineConfig} from 'vite';
22
import react from '@vitejs/plugin-react';
33
import viteCompression from 'vite-plugin-compression';
4+
import i18nextLoader from 'vite-plugin-i18next-loader';
45

56
// https://vitejs.dev/config/
67
export default defineConfig({
7-
build: {sourcemap: true,},
8+
build: {sourcemap: true, assetsInlineLimit: 0,},
89
css: {
910
preprocessorOptions: {
1011
scss: {api: 'modern-compiler',},
@@ -20,5 +21,6 @@ export default defineConfig({
2021
plugins: [
2122
react(),
2223
viteCompression(),
24+
i18nextLoader({ paths: ['./src/locales'] }),
2325
],
2426
});

0 commit comments

Comments
 (0)