Internationalization
Default displaed text is in English if left un-translated
How to Enable i18n in neo4j-arc
Intalling i18next and react-i18next with auto language detector
yarn add react-i18next i18next i18next-browser-languagedetector
If we choose to have fixed locale, we can opt-out |
Load Translations
Add on i18next Init
We can add the translations on init by create a new file i18n.ts
beside our App.tsx
containing following content:
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import { resources } from 'neo4j-arc/graph-visualization'
import LanguageDetector from 'i18next-browser-languagedetector'
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
interpolation: {
escapeValue: false
}
})
export default i18n
|
Add after Init
We can also add the translations after init:
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources: {},
interpolation: {
escapeValue: false
}
})
export default i18n
Note that we have passed in an empty resources object on init. This is necessary because otherwise i18next will try to load translations and give us a warning that we are not using a backend. |
Then we would include the following logic anywhere we would like to load translations in
import i18next from 'i18next';
i18next.addResources("en", "translation", resources.en.translation);
i18next.addResources("zh", "translation", resources.zh.translation);
Troubleshooting
Switching Browser Lanauage Does Not Alter the Displayed Language in Neo4j Browser
Please make sure the i18n is either
-
set up with fixed language, for example
The initialization assumes provider pattern around regular App component:
i18n .use(initReactI18next) .init({ ... lng: 'zh' })
-
or, if auto language detection is enabled, try clearing browser cookie and try again.