@@ -8,11 +8,9 @@ import Footer from './components/Footer.js';
88import GetStarted from './pages/GetStarted/get-started.js' ;
99import SupportUs from './pages/SupportUs/SupportUs.js' ;
1010import { createContext } from 'preact' ;
11- import { useLayoutEffect , useRef , useState } from 'preact/hooks' ;
12- import { default as i18next , changeLanguage } from 'i18next' ;
11+ import { useRef } from 'preact/hooks' ;
12+ import { changeLanguage } from 'i18next' ;
1313import { extractLocaleFromUrl , initTranslations , LOCALES , mapLocale } from './i18n' ;
14- import HttpApi from 'i18next-http-backend' ;
15- import { initReactI18next } from "react-i18next" ;
1614
1715export const LocaleContext = createContext ( 'en' ) ;
1816
@@ -42,7 +40,7 @@ export function App(props: {repoStargazersCount: number}) {
4240
4341export function LocaleProvider ( { children } ) {
4442 const { path } = useLocation ( ) ;
45- const localeId = mapLocale ( extractLocaleFromUrl ( path ) || navigator . language ) ;
43+ const localeId = getLocaleId ( path ) ;
4644 const loadedRef = useRef ( false ) ;
4745
4846 if ( ! loadedRef . current ) {
@@ -63,19 +61,25 @@ if (typeof window !== 'undefined') {
6361 hydrate ( < App repoStargazersCount = { FALLBACK_STARGAZERS_COUNT } /> , document . getElementById ( 'app' ) ! ) ;
6462}
6563
64+ function getLocaleId ( path : string ) {
65+ const extractedLocale = extractLocaleFromUrl ( path ) ;
66+ if ( extractedLocale ) return mapLocale ( extractedLocale ) ;
67+ if ( typeof window === "undefined" ) return 'en' ;
68+ return mapLocale ( navigator . language ) ;
69+ }
70+
6671export async function prerender ( data ) {
6772 // Fetch the stargazer count of the Trilium's GitHub repo on prerender to pass
6873 // it to the App component for SSR.
6974 // This ensures the GitHub API is not called on every page load in the client.
7075 const stargazersCount = await getRepoStargazersCount ( ) ;
7176
7277 const { html, links } = await ssr ( < App repoStargazersCount = { stargazersCount } { ...data } /> ) ;
73- const lang = extractLocaleFromUrl ( data . url ) ;
7478 return {
7579 html,
7680 links,
7781 head : {
78- lang
82+ lang : extractLocaleFromUrl ( data . url ) ?? "en"
7983 }
8084 }
8185}
0 commit comments