Skip to content

Commit f24880d

Browse files
committed
fix(website): incorrect default language
1 parent ee9bf1d commit f24880d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apps/website/src/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import Footer from './components/Footer.js';
88
import GetStarted from './pages/GetStarted/get-started.js';
99
import SupportUs from './pages/SupportUs/SupportUs.js';
1010
import { 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';
1313
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
14-
import HttpApi from 'i18next-http-backend';
15-
import { initReactI18next } from "react-i18next";
1614

1715
export const LocaleContext = createContext('en');
1816

@@ -42,7 +40,7 @@ export function App(props: {repoStargazersCount: number}) {
4240

4341
export 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+
6671
export 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

Comments
 (0)