Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation on different strategies for loading translations #38

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions docs/modules/ROOT/pages/neo4j-arc/i18n.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ Default displaed text is in English if left un-translated
yarn add react-i18next i18next
----

=== Configuring i18next
=== Load Translations

Create a new file `i18n.ts` beside our `App.tsx` containing following content:
==== Add on i18next Init

[source,javascript]
We can add the translations on init by create a new file `i18n.ts` beside our `App.tsx` containing following content:

[source,typescript]
----
import i18n from 'i18next'
import { resources } from 'neo4j-arc/graph-visualization'
Expand All @@ -43,6 +45,42 @@ export default i18n
https://qubitpi.gitbook.io/react-i18next/guides/quick-start[react-i18next documentation]
====

==== Add after Init

We can also add the translations after init:

[source,typescript]
----
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'

i18n.use(initReactI18next).init({
resources: {},
lng: 'zh',
interpolation: {
escapeValue: false
}
})

export default i18n
----

[NOTE]
====
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

[source,typescript]
----
import i18next from 'i18next';

i18next.addResources("en", "translation", resources.en.translation);
i18next.addResources("zh", "translation", resources.zh.translation);
----

=== I18nextProvider

[source,typescript]
Expand Down
2 changes: 1 addition & 1 deletion src/neo4j-arc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neo4j-devtools-arc",
"version": "0.0.66",
"version": "0.0.67",
"main": "dist/neo4j-arc.js",
"author": "Neo4j Inc.",
"license": "GPL-3.0",
Expand Down