Skip to content

Commit 265a5dd

Browse files
claudeenko
authored andcommitted
Fix TypeError: this.store is undefined in i18next changeLanguage
The i18next.init() call was not being awaited, so changeLanguage could be called before the internal store was initialized. Also guard the language sync effect to only run after locale initialization completes. https://claude.ai/code/session_01BCqa4WXYDrCn2ARTEA8jdd
1 parent d5defee commit 265a5dd

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

apps/frontend/src/lib/i18n/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const languageNames: Record<SupportedLanguage, string> = {
1616
/**
1717
* Initialize i18next with the given language or auto-detect
1818
*/
19-
export function initI18n(initialLanguage?: SupportedLanguage) {
20-
i18next.use(LanguageDetector).init({
19+
export async function initI18n(initialLanguage?: SupportedLanguage) {
20+
await i18next.use(LanguageDetector).init({
2121
resources: {
2222
en: { translation: en },
2323
de: { translation: de },

apps/frontend/src/lib/stores/locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function createLocaleStore() {
3232
*/
3333
initialize: async (userLanguage?: SupportedLanguage) => {
3434
// Initialize i18next with user's preference or auto-detect
35-
initI18n(userLanguage);
35+
await initI18n(userLanguage);
3636
const detectedLang = getCurrentLanguage();
3737

3838
// Update document lang attribute

apps/frontend/src/routes/+layout.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
userPreferences,
2020
} from '$lib/stores/auth';
2121
import { circles } from '$lib/stores/circles';
22-
import { locale } from '$lib/stores/locale';
22+
import { isLocaleInitialized, locale } from '$lib/stores/locale';
2323
2424
interface Props {
2525
children: Snippet;
@@ -52,7 +52,7 @@ $effect(() => {
5252
// Sync language when user preferences change (e.g., after login)
5353
$effect(() => {
5454
const prefs = $userPreferences;
55-
if (prefs?.language && prefs.language !== locale.getLanguage()) {
55+
if ($isLocaleInitialized && prefs?.language && prefs.language !== locale.getLanguage()) {
5656
locale.setLanguage(prefs.language as SupportedLanguage);
5757
}
5858
});

0 commit comments

Comments
 (0)