Skip to content

Commit

Permalink
Allow dynamic locale imports for web (bluesky-social#1971)
Browse files Browse the repository at this point in the history
* allow dynamic locale imports for web

* remove unnecessary file
  • Loading branch information
ansh authored Nov 24, 2023
1 parent 43c8fb6 commit 4b59a21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const defaultLocale = 'en'
* @param locale any locale string
*/
export async function dynamicActivate(locale: string) {
console.log('dynamicActivate', locale)
if (locale === 'en') {
i18n.loadAndActivate({locale, messages: messagesEn})
return
Expand Down
29 changes: 29 additions & 0 deletions src/locale/i18n.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {useLanguagePrefs} from '#/state/preferences'
import {i18n} from '@lingui/core'
import {useEffect} from 'react'

export const locales = {
en: 'English',
cs: 'Česky',
fr: 'Français',
hi: 'हिंदी',
es: 'Español',
}
export const defaultLocale = 'en'

/**
* We do a dynamic import of just the catalog that we need
* @param locale any locale string
*/
export async function dynamicActivate(locale: string) {
const {messages} = await import(`./locales/${locale}/messages`)
i18n.load(locale, messages)
i18n.activate(locale)
}

export async function useLocaleLanguage() {
const {appLanguage} = useLanguagePrefs()
useEffect(() => {
dynamicActivate(appLanguage)
}, [appLanguage])
}

0 comments on commit 4b59a21

Please sign in to comment.