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

feat: add i18next and transifex into the project #875

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

acezard
Copy link
Contributor

@acezard acezard commented Jul 17, 2023

Implementations

  • Added i18next, intl-pluralrules (polyfill), react-i18next, react-native-localize (native helpers)
  • Implemented i18n setup file
  • Created auto generated locales files for en and es (uploaded on tx)
  • Implemented TX pull & locale files validation
  • Export functions to use i18n in non-react files
  • Implemented i18n everywhere in the app and removed old system
  • Set default language to "en"
  • Handles language at app creation, app start, and cozy-settings lang change

image

@acezard acezard force-pushed the feat--setup-local-i18n branch 2 times, most recently from 1f87778 to d92a4f4 Compare July 18, 2023 12:18
@acezard acezard marked this pull request as draft July 18, 2023 13:26
@acezard acezard force-pushed the feat--setup-local-i18n branch 2 times, most recently from a4edb28 to aab7255 Compare July 19, 2023 08:30
@acezard acezard marked this pull request as ready for review July 19, 2023 08:31
@@ -41,6 +43,7 @@ export const createClient = async (instance: string): Promise<CozyClient> => {
const stackClient = client.getStackClient()
stackClient.setUri(instance)
await stackClient.register(instance)
await changeLanguage(client.getInstanceOptions().locale)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeLanguage() called here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is client.getInstanceOptions() supposed to work when not logged yet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the locale will change:

  • On not-logged startup based on device's locale
  • During login just after creating a cozy-client, so the password screen would have the cozy's language
  • On logged startup based on cozy's language

But:

  • We don't revert to device's language on logout or on revoked token event (i don't remember if it is what we want)
  • We don't revert to device's language if we stop the login process

Should we implement those ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could implement that, you would have the cozy language in memory here indeed (but it would reset next app launch). I'm not sure what is best for the user here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is client.getInstanceOptions() supposed to work when not logged yet?

it doesn't work indeed. I'm not sure where to put it, there are a lot of options. Can't we use a single call for both login and creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getClient, finalizeClient, check if lang can be used before login, add a fallback in nav to check if lang is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set phone lang on welcome screen

@@ -63,6 +64,7 @@ export const getClient = async () => {

await client.registerPlugin(flag.plugin)
await client.plugins.flags.initializing
await changeLanguage(client.getInstanceOptions().locale)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeLanguage() called here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should be called only once for all cases. not sure where

@@ -10,15 +10,18 @@
"home:build": "(cd cozy-home && yarn build:mobile)",
"home:watch": "(cd cozy-home && yarn watch:mobile)",
"install:home:local": "bash ./scripts/install-home.sh",
"install:home:registry": "yarn tsc --project scripts && node scripts/dist/install-home-registry.cmd.js",
"install:home:registry": "node scripts/dist/install-home-registry.cmd.js",
"install:scripts": "yarn tsc --project scripts && yarn install:home:registry",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You refactored this but you didn't change the behavior. Did you intialy want to add the validate:locales script here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but now it also compiles the validation script that is in ts, so I wanted to compile them only once and not twice. By doing it in the postinstall this is ensured

src/components/webviews/CozyWebView.js Outdated Show resolved Hide resolved
export const t: TranslationFunction = (...args) => _i18n.t(...args)
export const useI18n = (): UseTranslationResult => useTranslation()
export const changeLanguage: ChangeLanguageFunction = languageCode =>
_i18n.changeLanguage(languageCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check for supported language here? So the day we will add a new language in cozy-settings we don't need to be synchronized with a new flagship app release

Copy link
Contributor Author

@acezard acezard Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, what should we do if it's not supported? switch to english or stay on es/fr?

  • Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the language is available then take this language
Else try to take the phone's language
Else if phone's language not available, then take english

src/app/view/Lock/LockScreen.tsx Show resolved Hide resolved
src/libs/clientHelpers/magicLink.ts Outdated Show resolved Hide resolved
@@ -41,6 +43,7 @@ export const createClient = async (instance: string): Promise<CozyClient> => {
const stackClient = client.getStackClient()
stackClient.setUri(instance)
await stackClient.register(instance)
await changeLanguage(client.getInstanceOptions().locale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is client.getInstanceOptions() supposed to work when not logged yet?

@@ -41,6 +43,7 @@ export const createClient = async (instance: string): Promise<CozyClient> => {
const stackClient = client.getStackClient()
stackClient.setUri(instance)
await stackClient.register(instance)
await changeLanguage(client.getInstanceOptions().locale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the locale will change:

  • On not-logged startup based on device's locale
  • During login just after creating a cozy-client, so the password screen would have the cozy's language
  • On logged startup based on cozy's language

But:

  • We don't revert to device's language on logout or on revoked token event (i don't remember if it is what we want)
  • We don't revert to device's language if we stop the login process

Should we implement those ?

@acezard acezard force-pushed the feat--setup-local-i18n branch 2 times, most recently from 2411998 to 15164a3 Compare July 19, 2023 15:30
- Add CI check
- Add TX config
- Add TX pull script
- Add a locale check script
- Add translation files
- Add i18n service
- Install required dependencies
- Add mocks
- Add types
@acezard acezard force-pushed the feat--setup-local-i18n branch 3 times, most recently from 97113c3 to 0faf788 Compare July 20, 2023 14:24
- At prelogin
- At login
- At logout
src/locales/i18n.ts Show resolved Hide resolved
const { kdfIterations, name, locale } = await fetchPublicData(client)

// If we are able to get a locale from the public data, we update the language asap
if (locale) void changeLanguage(locale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setInstanceData is called only for classic login, in case of magicLink based auth then startMagicLinkOAuth is called and in case of OIDC oauth then startOidcOAuth is called. During those scenario we can have the 2FA screen displayed that should be translated too.

Also I'm wondering if we have enough data to do the same on the OnboardingScreen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing this in a following PR as getting locale info before full login wasn't really in the scope of this feature at the start

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with that 👍

@acezard acezard requested a review from Ldoppea July 21, 2023 11:59
@acezard acezard merged commit ec18364 into master Jul 21, 2023
1 check passed
@acezard acezard deleted the feat--setup-local-i18n branch July 21, 2023 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants