From d54e56d97150f17fbb17db864f82c9de460ec907 Mon Sep 17 00:00:00 2001 From: Naiche DESPOUY <79310743+NaicheD@users.noreply.github.com> Date: Mon, 15 May 2023 14:33:22 +0400 Subject: [PATCH] ndespouy : 000-internationalization.md Implements the internalization of Datahub. Being able to change and add language without modifying the source. This is a reedition of the following rfc : https://github.com/datahub-project/datahub/pull/5950 Which was closed because I was busy until April: https://github.com/datahub-project/datahub/pull/5950#issuecomment-1341503669 --- active/000-internationalization.md | 168 +++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 active/000-internationalization.md diff --git a/active/000-internationalization.md b/active/000-internationalization.md new file mode 100644 index 0000000..bde431c --- /dev/null +++ b/active/000-internationalization.md @@ -0,0 +1,168 @@ +- Start Date: (2022-09-14) +- RFC PR: (after opening the RFC PR, update this with a link to it and update the file name) +- Discussion Issue: (None) +- Implementation PR(s): (leave this empty) + +# Internalization (i18n) + +## Summary +> Implements the internalization of Datahub. +> Being able to change and add language without modifying the source. + +> This is a reedition of the following rfc : https://github.com/datahub-project/datahub/pull/5950 +> Which was closed because I was busy until April: https://github.com/datahub-project/datahub/pull/5950#issuecomment-1341503669 + +## Basic example +```javascript +// Instead of this + +// We write this + +// Or + +// And the display is the same in english, but translated in choosen language. +``` + +## Motivation +Why are we doing this? +> I have implemented for my company a french version of Datahub (or 90% of it). +> Now I have difficulties pulling new versions so I think it would be beneficial for both of +> us to share my modifications. +> +What use cases does it suppor +> Anyone who would want to have their own language for the Datahub will be able to do so. +> +What is the expected outcome? +> If I finish this as I expect it, Datahub will be able to change dynamically his language, no reload needed. +> And anybody will be able to add a language just by adding a *translation.json* file in the correct directory. +> + +## Requirements +> - [ ] react-i18next +> - [x] Uniformisation of Datahub types +> - [ ] Uniformisation of Datahub subtypes +> - [ ] Uniformisation of frontend displaying of exceptions +> - [ ] Factorisation of Dates +> - [ ] Factorisation of numbers (count, filter, table total, etc) + +### Extensibility +> Anybody can add his own language by adding the a *translation.json* file in the corresponding directory. + +## Non-Requirements +> I won't talk about which language should be implemented or not. English is native. +> I will take care of French. If anyone want his own language, let him be. + +## Detailed design + +### Terminology +> i18n : Internationalisation (begin with an "i", end with a "n" and have 18 letters between) +> + +### Overview +> I am using [react-i18next](https://react.i18next.com/) to do so. Basically we wrapp the App in a I18nestProvider +> which allow us to call a hook or a render prop. We give them a key string which point on a *translation.json* +> containing the text we want (according to the choosen language). Example from the react-i18next doc: +```javascript +// Example hook +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +export function MyComponent() { + const { t, i18n } = useTranslation(); + // or const [t, i18n] = useTranslation(); + + return
{t('type.translatedText')}
+} +``` +```javascript +// Example component +import React from 'react'; +import { Trans } from 'react-i18next'; + +export function MyComponent() { + return ( +