Skip to content

Commit 316b0e2

Browse files
committed
lang url issue: Sync configBot lang tag to URL when it changes, and sync URL to configBot on page load
1 parent 7746024 commit 316b0e2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/seed-bible/app/components/thePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function ThePage({
625625
book: data?.book,
626626
chapter: data?.chapter,
627627
});
628-
os.syncConfigBotTagsToURL(["book", "chapter", "translation"]);
628+
os.syncConfigBotTagsToURL(["book", "chapter", "translation", "lang"]);
629629
}
630630
}, [data]);
631631

packages/seed-bible/app/hooks/i18n.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ export async function initI18n(): Promise<any> {
153153
throw new Error("i18next failed to load from CDN");
154154
}
155155

156-
// Get saved language from localStorage, or detect from browser using navigator.language
156+
// Check configBot.tags.lang first, then localStorage, then browser detection
157+
const tagLang = configBot?.tags?.lang;
157158
const savedLang = localStorage.getItem("i18nextLng");
158-
const detectedLang = savedLang || getBrowserLanguage();
159+
const detectedLang =
160+
(tagLang && supportedLangCodes.includes(tagLang) ? tagLang : null) ||
161+
savedLang ||
162+
getBrowserLanguage();
159163

160164
await i18next.init({
161165
resources,
@@ -200,6 +204,10 @@ export function t(key: string, options?: any): string {
200204
export function changeLanguage(lng: string): Promise<void> {
201205
if (i18nInstance) {
202206
localStorage.setItem("i18nextLng", lng);
207+
// Sync to configBot tags
208+
if (configBot?.tags) {
209+
configBot.tags.lang = lng;
210+
}
203211
// Update document direction for RTL languages
204212
const langConfig = availableLanguages.find((l) => l.code === lng);
205213
document.documentElement.dir = langConfig?.rtl ? "rtl" : "ltr";

0 commit comments

Comments
 (0)