mirror of
https://github.com/zadam/trilium.git
synced 2025-12-15 11:54:24 +01:00
Compare commits
No commits in common. "161238ca111dc0baf00ace5df6c96ab72f51a38b" and "b2f1b3c910b724c8ae05b623ebbe62061ffe9fe8" have entirely different histories.
161238ca11
...
b2f1b3c910
@ -56,20 +56,7 @@ function SingleNoteRenderer({ note, onReady }: RendererProps) {
|
|||||||
await import("@triliumnext/ckeditor5/src/theme/ck-content.css");
|
await import("@triliumnext/ckeditor5/src/theme/ck-content.css");
|
||||||
}
|
}
|
||||||
const { $renderedContent } = await content_renderer.getRenderedContent(note, { noChildrenList: true });
|
const { $renderedContent } = await content_renderer.getRenderedContent(note, { noChildrenList: true });
|
||||||
const container = containerRef.current!;
|
containerRef.current?.replaceChildren(...$renderedContent);
|
||||||
container.replaceChildren(...$renderedContent);
|
|
||||||
|
|
||||||
// Wait for all images to load.
|
|
||||||
const images = Array.from(container.querySelectorAll("img"));
|
|
||||||
await Promise.all(
|
|
||||||
images.map(img => {
|
|
||||||
if (img.complete) return Promise.resolve();
|
|
||||||
return new Promise<void>(resolve => {
|
|
||||||
img.addEventListener("load", () => resolve(), { once: true });
|
|
||||||
img.addEventListener("error", () => resolve(), { once: true });
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
load().then(() => requestAnimationFrame(onReady))
|
load().then(() => requestAnimationFrame(onReady))
|
||||||
|
|||||||
@ -13,13 +13,6 @@
|
|||||||
"critical-error": {
|
"critical-error": {
|
||||||
"title": "Kritische Error",
|
"title": "Kritische Error",
|
||||||
"message": "Een kritieke fout heeft plaatsgevonden waardoor de cliënt zich aanmeldt vanaf het begin:\n\n84X\n\nDit is waarschijnlijk veroorzaakt door een script dat op een onverwachte manier faalt. Probeer de sollicitatie in veilige modus te starten en de kwestie aan te spreken."
|
"message": "Een kritieke fout heeft plaatsgevonden waardoor de cliënt zich aanmeldt vanaf het begin:\n\n84X\n\nDit is waarschijnlijk veroorzaakt door een script dat op een onverwachte manier faalt. Probeer de sollicitatie in veilige modus te starten en de kwestie aan te spreken."
|
||||||
},
|
|
||||||
"widget-error": {
|
|
||||||
"title": "Starten widget mislukt",
|
|
||||||
"message-unknown": "Onbekende widget kan niet gestart worden omdat:\n\n{{message}}"
|
|
||||||
},
|
|
||||||
"bundle-error": {
|
|
||||||
"title": "Custom script laden mislukt"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"add_link": {
|
"add_link": {
|
||||||
|
|||||||
@ -155,11 +155,6 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid not showing recent notes when creating a new empty tab.
|
|
||||||
if ("noteContext" in data && data.noteContext.ntxId !== "_popup-editor") {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.handleEventInChildren(name, data);
|
return super.handleEventInChildren(name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ WHERE powershell.exe > NUL 2>&1
|
|||||||
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
||||||
|
|
||||||
:POWERSHELL
|
:POWERSHELL
|
||||||
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command "Set-Item -Path Env:NODE_TLS_REJECT_UNAUTHORIZED -Value 0; ./trilium.exe"
|
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo "Set-Item -Path Env:NODE_TLS_REJECT_UNAUTHORIZED -Value 0; ./trilium.exe"
|
||||||
GOTO END
|
GOTO END
|
||||||
|
|
||||||
:BATCH
|
:BATCH
|
||||||
|
|||||||
@ -6,7 +6,7 @@ WHERE powershell.exe > NUL 2>&1
|
|||||||
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
||||||
|
|
||||||
:POWERSHELL
|
:POWERSHELL
|
||||||
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command "Set-Item -Path Env:TRILIUM_DATA_DIR -Value './trilium-data'; ./trilium.exe"
|
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo "Set-Item -Path Env:TRILIUM_DATA_DIR -Value './trilium-data'; ./trilium.exe"
|
||||||
GOTO END
|
GOTO END
|
||||||
|
|
||||||
:BATCH
|
:BATCH
|
||||||
|
|||||||
@ -6,7 +6,7 @@ WHERE powershell.exe > NUL 2>&1
|
|||||||
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
IF %ERRORLEVEL% NEQ 0 GOTO BATCH ELSE GOTO POWERSHELL
|
||||||
|
|
||||||
:POWERSHELL
|
:POWERSHELL
|
||||||
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command "Set-Item -Path Env:TRILIUM_SAFE_MODE -Value 1; ./trilium.exe --disable-gpu"
|
powershell -ExecutionPolicy Bypass -NonInteractive -NoLogo "Set-Item -Path Env:TRILIUM_SAFE_MODE -Value 1; ./trilium.exe --disable-gpu"
|
||||||
GOTO END
|
GOTO END
|
||||||
|
|
||||||
:BATCH
|
:BATCH
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/src/assets/favicon.ico" />
|
<link rel="icon" type="image/svg+xml" href="/src/assets/favicon.ico" />
|
||||||
|
|||||||
@ -95,7 +95,8 @@
|
|||||||
"get_started": "Comenzar"
|
"get_started": "Comenzar"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "Saber más…"
|
"link_learn_more": "Saber más…",
|
||||||
|
"list_with_screenshot_alt": "Captura de pantalla de la función seleccionada"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "Descarga ahora ",
|
"text": "Descarga ahora ",
|
||||||
@ -74,7 +74,8 @@
|
|||||||
"get_started": "Commencer"
|
"get_started": "Commencer"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "En savoir plus..."
|
"link_learn_more": "En savoir plus...",
|
||||||
|
"list_with_screenshot_alt": "Capture d'écran de la fonctionnalité sélectionnée"
|
||||||
},
|
},
|
||||||
"support_us": {
|
"support_us": {
|
||||||
"financial_donations_title": "Dons financiers",
|
"financial_donations_title": "Dons financiers",
|
||||||
@ -51,8 +51,7 @@
|
|||||||
"mermaid_description": "Crea diagrammi come diagrammi di flusso, diagrammi di classe e sequenza, diagrammi di Gantt e molti altri, utilizzando la sintassi Mermaid.",
|
"mermaid_description": "Crea diagrammi come diagrammi di flusso, diagrammi di classe e sequenza, diagrammi di Gantt e molti altri, utilizzando la sintassi Mermaid.",
|
||||||
"mindmap_title": "Mappe mentali",
|
"mindmap_title": "Mappe mentali",
|
||||||
"mindmap_description": "Organizza i tuoi pensieri visivamente o fai una sessione di brainstorming.",
|
"mindmap_description": "Organizza i tuoi pensieri visivamente o fai una sessione di brainstorming.",
|
||||||
"others_list": "e altri: <0>mappa delle note</0>, <1>mappa delle relazioni</1>, <2>ricerche salvate</2>, <3>renderizza nota</3> e <4>visualizzazioni web</4>.",
|
"others_list": "e altri: <0>mappa delle note</0>, <1>mappa delle relazioni</1>, <2>ricerche salvate</2>, <3>renderizza nota</3> e <4>visualizzazioni web</4>."
|
||||||
"title": "Diversi modi per rappresentare le tue informazioni"
|
|
||||||
},
|
},
|
||||||
"extensibility_benefits": {
|
"extensibility_benefits": {
|
||||||
"title": "Condivisione ed estensibilità",
|
"title": "Condivisione ed estensibilità",
|
||||||
@ -73,10 +72,7 @@
|
|||||||
"board_title": "Board",
|
"board_title": "Board",
|
||||||
"board_description": "Organizza le tue attività o lo stato dei tuoi progetti in una lavagna Kanban con un modo semplice per creare nuovi elementi e colonne e modificare facilmente il loro stato trascinandoli sulla lavagna.",
|
"board_description": "Organizza le tue attività o lo stato dei tuoi progetti in una lavagna Kanban con un modo semplice per creare nuovi elementi e colonne e modificare facilmente il loro stato trascinandoli sulla lavagna.",
|
||||||
"geomap_title": "Geomappa",
|
"geomap_title": "Geomappa",
|
||||||
"geomap_description": "Pianifica le tue vacanze o segna i tuoi punti di interesse direttamente su una mappa geografica utilizzando indicatori personalizzabili. Visualizza le tracce GPX registrate per seguire gli itinerari.",
|
"geomap_description": "Pianifica le tue vacanze o segna i tuoi punti di interesse direttamente su una mappa geografica utilizzando indicatori personalizzabili. Visualizza le tracce GPX registrate per seguire gli itinerari."
|
||||||
"title": "Collezioni",
|
|
||||||
"presentation_title": "Presentazione",
|
|
||||||
"presentation_description": "Organizza le informazioni in diapositive e presentale a schermo intero con transizioni fluide. Le diapositive possono anche essere esportate in formato PDF per una facile condivisione."
|
|
||||||
},
|
},
|
||||||
"faq": {
|
"faq": {
|
||||||
"title": "Domande frequenti",
|
"title": "Domande frequenti",
|
||||||
@ -99,7 +95,8 @@
|
|||||||
"get_started": "Inizia ora"
|
"get_started": "Inizia ora"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "Per saperne di più..."
|
"link_learn_more": "Per saperne di più...",
|
||||||
|
"list_with_screenshot_alt": "Screenshot della funzione selezionata"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "Scarica ora ",
|
"text": "Scarica ora ",
|
||||||
@ -191,10 +188,5 @@
|
|||||||
"description": "Trilium Notes è ospitato su PikaPods, un servizio a pagamento che consente un facile accesso e una semplice gestione. Non è direttamente affiliato al team Trilium.",
|
"description": "Trilium Notes è ospitato su PikaPods, un servizio a pagamento che consente un facile accesso e una semplice gestione. Non è direttamente affiliato al team Trilium.",
|
||||||
"download_pikapod": "Configurazione su PikaPods",
|
"download_pikapod": "Configurazione su PikaPods",
|
||||||
"download_triliumcc": "In alternativa, consultare trilium.cc"
|
"download_triliumcc": "In alternativa, consultare trilium.cc"
|
||||||
},
|
|
||||||
"header": {
|
|
||||||
"get-started": "Inizia",
|
|
||||||
"documentation": "Documentazione",
|
|
||||||
"support-us": "Sostienici"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,8 +51,7 @@
|
|||||||
"mermaid_description": "Mermaid 構文を使用して、フローチャート、クラス図、シーケンス図、ガント チャートなどの図を作成します。",
|
"mermaid_description": "Mermaid 構文を使用して、フローチャート、クラス図、シーケンス図、ガント チャートなどの図を作成します。",
|
||||||
"mindmap_title": "マインドマップ",
|
"mindmap_title": "マインドマップ",
|
||||||
"mindmap_description": "考えを視覚的に整理したり、ブレインストーミング セッションを行ったりします。",
|
"mindmap_description": "考えを視覚的に整理したり、ブレインストーミング セッションを行ったりします。",
|
||||||
"others_list": "その他: <0>ノートマップ</0>、<1>リレーションマップ</1>、<2>保存された検索</2>、<3>レンダリングノート</3>、<4>Web ビュー</4>。",
|
"others_list": "その他: <0>ノートマップ</0>、<1>リレーションマップ</1>、<2>保存された検索</2>、<3>レンダリングノート</3>、<4>Web ビュー</4>。"
|
||||||
"title": "情報を表現するための複数の方法"
|
|
||||||
},
|
},
|
||||||
"extensibility_benefits": {
|
"extensibility_benefits": {
|
||||||
"title": "共有と拡張性",
|
"title": "共有と拡張性",
|
||||||
@ -73,10 +72,7 @@
|
|||||||
"board_title": "ボード",
|
"board_title": "ボード",
|
||||||
"board_description": "新しい項目や列を簡単に作成し、ボード上でドラッグするだけでステータスを変更できるカンバン ボードで、タスクやプロジェクトのステータスを整理できます。",
|
"board_description": "新しい項目や列を簡単に作成し、ボード上でドラッグするだけでステータスを変更できるカンバン ボードで、タスクやプロジェクトのステータスを整理できます。",
|
||||||
"geomap_title": "ジオマップ",
|
"geomap_title": "ジオマップ",
|
||||||
"geomap_description": "カスタマイズ可能なマーカーを使って、休暇を計画したり、興味のある場所を地図上に直接マークしたりできます。記録されたGPXトラックを表示して、旅程を追跡できます。",
|
"geomap_description": "カスタマイズ可能なマーカーを使って、休暇を計画したり、興味のある場所を地図上に直接マークしたりできます。記録されたGPXトラックを表示して、旅程を追跡できます。"
|
||||||
"title": "コレクション",
|
|
||||||
"presentation_title": "プレゼンテーション",
|
|
||||||
"presentation_description": "情報をスライドに整理し、スムーズな遷移で全画面表示できます。スライドはPDFにエクスポートできるので、簡単に共有できます。"
|
|
||||||
},
|
},
|
||||||
"faq": {
|
"faq": {
|
||||||
"title": "よくある質問",
|
"title": "よくある質問",
|
||||||
@ -99,7 +95,8 @@
|
|||||||
"get_started": "はじめる"
|
"get_started": "はじめる"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "さらに詳しく..."
|
"link_learn_more": "さらに詳しく...",
|
||||||
|
"list_with_screenshot_alt": "選択中の機能のスクリーンショット"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "今すぐダウンロード ",
|
"text": "今すぐダウンロード ",
|
||||||
@ -191,10 +188,5 @@
|
|||||||
"description": "Trilium Notesは、アクセスと管理を容易にする有料サービス PikaPods でホストされています。Trilium チームとは直接関係ありません。",
|
"description": "Trilium Notesは、アクセスと管理を容易にする有料サービス PikaPods でホストされています。Trilium チームとは直接関係ありません。",
|
||||||
"download_pikapod": "PikaPods にセットアップする",
|
"download_pikapod": "PikaPods にセットアップする",
|
||||||
"download_triliumcc": "または、trilium.cc を参照してください"
|
"download_triliumcc": "または、trilium.cc を参照してください"
|
||||||
},
|
|
||||||
"header": {
|
|
||||||
"get-started": "はじめる",
|
|
||||||
"documentation": "ドキュメント",
|
|
||||||
"support-us": "サポート"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,8 @@
|
|||||||
"get_started": "Start"
|
"get_started": "Start"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "Dowiedz się więcej...."
|
"link_learn_more": "Dowiedz się więcej....",
|
||||||
|
"list_with_screenshot_alt": "Zrzut ekranu wybranej funkcji"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "Pobierz teraz ",
|
"text": "Pobierz teraz ",
|
||||||
@ -95,7 +95,8 @@
|
|||||||
"get_started": "Începe"
|
"get_started": "Începe"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "Mai multe detalii..."
|
"link_learn_more": "Mai multe detalii...",
|
||||||
|
"list_with_screenshot_alt": "Captură de ecran a funcției selectate"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "Descărcați acum ",
|
"text": "Descărcați acum ",
|
||||||
@ -51,8 +51,7 @@
|
|||||||
"mermaid_description": "使用 Mermaid 語法繪製流程圖、類別圖與序列圖、甘特圖等多種圖表。",
|
"mermaid_description": "使用 Mermaid 語法繪製流程圖、類別圖與序列圖、甘特圖等多種圖表。",
|
||||||
"mindmap_title": "心智圖",
|
"mindmap_title": "心智圖",
|
||||||
"mindmap_description": "以視覺方式整理思緒,或進行腦力激盪。",
|
"mindmap_description": "以視覺方式整理思緒,或進行腦力激盪。",
|
||||||
"others_list": "及其他項目:<0>筆記地圖</0>、<1>關聯地圖</1>、<2>儲存搜尋</2>、<3>渲染筆記</3>,以及<4>網頁檢視</4>。",
|
"others_list": "及其他項目:<0>筆記地圖</0>、<1>關聯地圖</1>、<2>儲存搜尋</2>、<3>渲染筆記</3>,以及<4>網頁檢視</4>。"
|
||||||
"title": "多種方式呈現您的資訊"
|
|
||||||
},
|
},
|
||||||
"extensibility_benefits": {
|
"extensibility_benefits": {
|
||||||
"title": "分享及擴展性",
|
"title": "分享及擴展性",
|
||||||
@ -73,10 +72,7 @@
|
|||||||
"board_title": "看板",
|
"board_title": "看板",
|
||||||
"board_description": "將您的任務或專案狀態整理成看板,輕鬆建立新項目與欄位,並透過在看板上拖曳即可簡單變更狀態。",
|
"board_description": "將您的任務或專案狀態整理成看板,輕鬆建立新項目與欄位,並透過在看板上拖曳即可簡單變更狀態。",
|
||||||
"geomap_title": "地理地圖",
|
"geomap_title": "地理地圖",
|
||||||
"geomap_description": "使用可自訂的標記,直接在地圖上規劃您的假期行程或標記感興趣的地點。顯示已記錄的GPX軌跡,以便追蹤行程路線。",
|
"geomap_description": "使用可自訂的標記,直接在地圖上規劃您的假期行程或標記感興趣的地點。顯示已記錄的GPX軌跡,以便追蹤行程路線。"
|
||||||
"title": "集合",
|
|
||||||
"presentation_title": "簡報",
|
|
||||||
"presentation_description": "將資訊整理成投影片,並以全螢幕模式及流暢的轉場效果呈現。投影片亦可匯出為 PDF 格式,方便分享。"
|
|
||||||
},
|
},
|
||||||
"faq": {
|
"faq": {
|
||||||
"title": "常見問題",
|
"title": "常見問題",
|
||||||
@ -99,7 +95,8 @@
|
|||||||
"get_started": "上手指南"
|
"get_started": "上手指南"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"link_learn_more": "了解更多…"
|
"link_learn_more": "了解更多…",
|
||||||
|
"list_with_screenshot_alt": "已選擇功能的螢幕截圖"
|
||||||
},
|
},
|
||||||
"download_now": {
|
"download_now": {
|
||||||
"text": "馬上下載 ",
|
"text": "馬上下載 ",
|
||||||
@ -191,10 +188,5 @@
|
|||||||
"description": "Trilium Notes 託管於 PikaPods,此為付費服務,提供便捷存取與管理功能。與 Trilium 團隊無直接關聯。",
|
"description": "Trilium Notes 託管於 PikaPods,此為付費服務,提供便捷存取與管理功能。與 Trilium 團隊無直接關聯。",
|
||||||
"download_pikapod": "在 PikaPods 上設定",
|
"download_pikapod": "在 PikaPods 上設定",
|
||||||
"download_triliumcc": "或參見 trilium.cc"
|
"download_triliumcc": "或參見 trilium.cc"
|
||||||
},
|
|
||||||
"header": {
|
|
||||||
"get-started": "上手指南",
|
|
||||||
"documentation": "文件",
|
|
||||||
"support-us": "支持我們"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,7 +19,6 @@ describe("swapLocale", () => {
|
|||||||
expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started");
|
expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started");
|
||||||
expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started");
|
expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started");
|
||||||
expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/");
|
expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/");
|
||||||
expect(swapLocaleInUrl("/ro", "en")).toStrictEqual("/en");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,36 +1,9 @@
|
|||||||
import i18next from "i18next";
|
|
||||||
import { initReactI18next } from "react-i18next";
|
|
||||||
|
|
||||||
interface Locale {
|
interface Locale {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
rtl?: boolean;
|
rtl?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
i18next.use(initReactI18next);
|
|
||||||
const localeFiles = import.meta.glob("./translations/*/translation.json", { eager: true });
|
|
||||||
const resources: Record<string, Record<string, Record<string, string>>> = {};
|
|
||||||
for (const [path, module] of Object.entries(localeFiles)) {
|
|
||||||
const id = path.split("/").at(-2);
|
|
||||||
if (!id) continue;
|
|
||||||
|
|
||||||
const translations = (module as any).default ?? module;
|
|
||||||
resources[id] = { translation: translations };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initTranslations(lng: string) {
|
|
||||||
i18next.init({
|
|
||||||
fallbackLng: "en",
|
|
||||||
lng,
|
|
||||||
returnEmptyString: false,
|
|
||||||
resources,
|
|
||||||
initAsync: false,
|
|
||||||
react: {
|
|
||||||
useSuspense: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LOCALES: Locale[] = [
|
export const LOCALES: Locale[] = [
|
||||||
{ id: "en", name: "English" },
|
{ id: "en", name: "English" },
|
||||||
{ id: "ro", name: "Română" },
|
{ id: "ro", name: "Română" },
|
||||||
@ -62,13 +35,7 @@ export function mapLocale(locale: string) {
|
|||||||
export function swapLocaleInUrl(url: string, newLocale: string) {
|
export function swapLocaleInUrl(url: string, newLocale: string) {
|
||||||
const components = url.split("/");
|
const components = url.split("/");
|
||||||
if (components.length === 2) {
|
if (components.length === 2) {
|
||||||
const potentialLocale = components[1];
|
|
||||||
const correspondingLocale = LOCALES.find(l => l.id === potentialLocale);
|
|
||||||
if (correspondingLocale) {
|
|
||||||
return `/${newLocale}`;
|
|
||||||
} else {
|
|
||||||
return `/${newLocale}${url}`;
|
return `/${newLocale}${url}`;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
components[1] = newLocale;
|
components[1] = newLocale;
|
||||||
return components.join("/");
|
return components.join("/");
|
||||||
|
|||||||
@ -8,9 +8,11 @@ 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 } from 'preact/hooks';
|
import { useLayoutEffect, useState } from 'preact/hooks';
|
||||||
import { changeLanguage } from 'i18next';
|
import { default as i18next, changeLanguage } from 'i18next';
|
||||||
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
|
import { extractLocaleFromUrl, 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');
|
||||||
|
|
||||||
@ -40,26 +42,34 @@ export function App(props: {repoStargazersCount: number}) {
|
|||||||
|
|
||||||
export function LocaleProvider({ children }) {
|
export function LocaleProvider({ children }) {
|
||||||
const { path } = useLocation();
|
const { path } = useLocation();
|
||||||
const localeId = getLocaleId(path);
|
const localeId = mapLocale(extractLocaleFromUrl(path) || navigator.language);
|
||||||
const loadedRef = useRef(false);
|
const [ loaded, setLoaded ] = useState(false);
|
||||||
|
|
||||||
if (!loadedRef.current) {
|
|
||||||
initTranslations(localeId);
|
|
||||||
loadedRef.current = true;
|
|
||||||
} else {
|
|
||||||
changeLanguage(localeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update html lang and dir attributes
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
i18next
|
||||||
|
.use(HttpApi)
|
||||||
|
.use(initReactI18next);
|
||||||
|
i18next.init({
|
||||||
|
lng: localeId,
|
||||||
|
fallbackLng: "en",
|
||||||
|
backend: {
|
||||||
|
loadPath: "/translations/{{lng}}/{{ns}}.json",
|
||||||
|
},
|
||||||
|
returnEmptyString: false
|
||||||
|
}).then(() => setLoaded(true))
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (!loaded) return;
|
||||||
|
changeLanguage(localeId);
|
||||||
const correspondingLocale = LOCALES.find(l => l.id === localeId);
|
const correspondingLocale = LOCALES.find(l => l.id === localeId);
|
||||||
document.documentElement.lang = localeId;
|
document.documentElement.lang = localeId;
|
||||||
document.documentElement.dir = correspondingLocale?.rtl ? "rtl" : "ltr";
|
document.documentElement.dir = correspondingLocale?.rtl ? "rtl" : "ltr";
|
||||||
}, [localeId]);
|
}, [ loaded, localeId ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LocaleContext.Provider value={localeId}>
|
<LocaleContext.Provider value={localeId}>
|
||||||
{children}
|
{loaded && children}
|
||||||
</LocaleContext.Provider>
|
</LocaleContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -68,26 +78,12 @@ 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.
|
||||||
// This ensures the GitHub API is not called on every page load in the client.
|
// This ensures the GitHub API is not called on every page load in the client.
|
||||||
const stargazersCount = await getRepoStargazersCount();
|
const stargazersCount = await getRepoStargazersCount();
|
||||||
|
|
||||||
const { html, links } = await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
|
return await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
|
||||||
return {
|
|
||||||
html,
|
|
||||||
links,
|
|
||||||
head: {
|
|
||||||
lang: extractLocaleFromUrl(data.url) ?? "en"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,6 @@
|
|||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "preact",
|
"jsxImportSource": "preact",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"types": [
|
|
||||||
"vite/client"
|
|
||||||
],
|
|
||||||
"paths": {
|
"paths": {
|
||||||
"react": ["../../node_modules/preact/compat/"],
|
"react": ["../../node_modules/preact/compat/"],
|
||||||
"react-dom": ["../../node_modules/preact/compat/"]
|
"react-dom": ["../../node_modules/preact/compat/"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user