-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70c8319
commit e95580c
Showing
10 changed files
with
244 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const loadI18nMessages = async (localesList: Record<string, string>) => { | ||
const supportedLocales = Object.values(localesList); | ||
const messages = {} as I18nMessages; | ||
|
||
for await (const locale of supportedLocales) { | ||
try { | ||
const result = await fetch(`/translations/ui-linked-data/${locale}.json`); | ||
|
||
if (result.ok) { | ||
const parsedMessages = await result.json(); | ||
|
||
messages[locale] = parsedMessages; | ||
} | ||
} catch (error) { | ||
console.error('Error occured while loading i18n messages', error); | ||
} | ||
} | ||
|
||
return messages; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useEffect } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { loadI18nMessages } from '@common/helpers/locales.helper'; | ||
import { LOCALES } from '@common/i18n/locales'; | ||
import baseLocaleMessages from '@translations/ui-linked-data/en.json'; | ||
import state from '@state'; | ||
|
||
export const useLoadI18nMessages = () => { | ||
const [i18nMessages, setI18nMessages] = useRecoilState(state.config.i18nMessages); | ||
|
||
useEffect(() => { | ||
async function onLoad() { | ||
try { | ||
const messages = await loadI18nMessages(LOCALES); | ||
setI18nMessages(messages); | ||
} catch (error) { | ||
console.error('Messages loading failed', error); | ||
} | ||
} | ||
|
||
onLoad(); | ||
}, []); | ||
|
||
return { i18nMessages, baseLocaleMessages }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type I18nMessages = Record<string, Record<string, string>>; |
Oops, something went wrong.