mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	fix(website): incorrect default language
This commit is contained in:
		
							parent
							
								
									ee9bf1d47b
								
							
						
					
					
						commit
						f24880d42c
					
				@ -8,11 +8,9 @@ import Footer from './components/Footer.js';
 | 
				
			|||||||
import GetStarted from './pages/GetStarted/get-started.js';
 | 
					import GetStarted from './pages/GetStarted/get-started.js';
 | 
				
			||||||
import SupportUs from './pages/SupportUs/SupportUs.js';
 | 
					import SupportUs from './pages/SupportUs/SupportUs.js';
 | 
				
			||||||
import { createContext } from 'preact';
 | 
					import { createContext } from 'preact';
 | 
				
			||||||
import { useLayoutEffect, useRef, useState } from 'preact/hooks';
 | 
					import { useRef } from 'preact/hooks';
 | 
				
			||||||
import { default as i18next, changeLanguage } from 'i18next';
 | 
					import { changeLanguage } from 'i18next';
 | 
				
			||||||
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
 | 
					import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
 | 
				
			||||||
import HttpApi from 'i18next-http-backend';
 | 
					 | 
				
			||||||
import { initReactI18next } from "react-i18next";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const LocaleContext = createContext('en');
 | 
					export const LocaleContext = createContext('en');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -42,7 +40,7 @@ export function App(props: {repoStargazersCount: number}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export function LocaleProvider({ children }) {
 | 
					export function LocaleProvider({ children }) {
 | 
				
			||||||
  const { path } = useLocation();
 | 
					  const { path } = useLocation();
 | 
				
			||||||
  const localeId = mapLocale(extractLocaleFromUrl(path) || navigator.language);
 | 
					  const localeId = getLocaleId(path);
 | 
				
			||||||
  const loadedRef = useRef(false);
 | 
					  const loadedRef = useRef(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!loadedRef.current) {
 | 
					  if (!loadedRef.current) {
 | 
				
			||||||
@ -63,6 +61,13 @@ if (typeof window !== 'undefined') {
 | 
				
			|||||||
	hydrate(<App repoStargazersCount={FALLBACK_STARGAZERS_COUNT} />, document.getElementById('app')!);
 | 
						hydrate(<App repoStargazersCount={FALLBACK_STARGAZERS_COUNT} />, document.getElementById('app')!);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getLocaleId(path: string) {
 | 
				
			||||||
 | 
					    const extractedLocale = extractLocaleFromUrl(path);
 | 
				
			||||||
 | 
					    if (extractedLocale) return mapLocale(extractedLocale);
 | 
				
			||||||
 | 
					    if (typeof window === "undefined") return 'en';
 | 
				
			||||||
 | 
					    return mapLocale(navigator.language);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function prerender(data) {
 | 
					export async function prerender(data) {
 | 
				
			||||||
	// Fetch the stargazer count of the Trilium's GitHub repo on prerender to pass
 | 
						// Fetch the stargazer count of the Trilium's GitHub repo on prerender to pass
 | 
				
			||||||
	// it to the App component for SSR.
 | 
						// it to the App component for SSR.
 | 
				
			||||||
@ -70,12 +75,11 @@ export async function prerender(data) {
 | 
				
			|||||||
	const stargazersCount = await getRepoStargazersCount();
 | 
						const stargazersCount = await getRepoStargazersCount();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const { html, links } = await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
 | 
						const { html, links } = await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
 | 
				
			||||||
    const lang = extractLocaleFromUrl(data.url);
 | 
					 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        html,
 | 
					        html,
 | 
				
			||||||
        links,
 | 
					        links,
 | 
				
			||||||
        head: {
 | 
					        head: {
 | 
				
			||||||
            lang
 | 
					            lang: extractLocaleFromUrl(data.url) ?? "en"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user