@@ -9,13 +9,52 @@ $ yarn add @scaleway/use-i18n
99```
1010
1111## Usage
12+ ### Loading locales
13+ Create a directory with your locales.
14+ Use of local variables and namespace to dynamically load the locales.
15+
16+ ** Exemple :**
17+
18+ ```
19+ 📦locales
20+ ┣ 📂de
21+ ┃ ┗ 📜common.json
22+ ┣ 📂en
23+ ┃ ┗ 📜common.json
24+ ┗ 📂fr
25+ ┃ ┗ 📜common.json
26+ ```
27+ your loader will be:
28+ ``` js
29+ const load = ({ locale, namespace }) =>
30+ import (` ./locales/${ locale} /${ namespace} ` )
31+ ```
32+ Inside your app you will need to use useTranslation to load namespace locales.
33+
34+ if you want to have pre-load locales you can use defaultTranslations.
35+
36+ ``` js
37+ import defaultTranslations from ' ./locales/en/common' ;
38+
39+ < I18N
40+ defaultLocale= " en"
41+ supportedLocales= {[' en' ]}
42+ defaultTranslations= {defaultTranslations}
43+ >
44+ < App / >
45+ < / I18N >
46+ ```
47+
48+
1249
1350``` js
1451import React from ' react'
1552import I18n from ' @scaleway/use-i18n'
1653
54+
1755const Page = () => {
18- const { t } = useI18n ()
56+ // this will load locales based on `./locales/${currentLocale}/common.json`
57+ const { t } = useTranlation ([' common' ])
1958
2059 return < h1> {t (' title' )}< / h1>
2160}
@@ -26,10 +65,13 @@ const App = () => {
2665 title: ' Welcome to I18n hooks' ,
2766 }
2867
68+ const load = ({ locale, namespace }) =>
69+ import (` ./locales/${ locale} /${ namespace} ` )
70+
2971 return (
3072 < I18n
3173 defaultLocale= " en"
32- defaultLocales = {defaultLocales}
74+ supportedLocales = {defaultLocales}
3375 defaultTranslations= {defaultTranslations}
3476 >
3577 < Page / >
0 commit comments