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

Localize Web UI #39 #46

Merged
merged 30 commits into from
Dec 27, 2022
Merged

Localize Web UI #39 #46

merged 30 commits into from
Dec 27, 2022

Conversation

gangjun06
Copy link
Contributor

@gangjun06 gangjun06 commented Nov 27, 2022

Check Lists

  • Setup localization module
  • Move texts to json file
  • Translate english into korean
  • Resolve Conflict
  • Language select in Login page and setting page

What changed and added?

package.json

  • next-translate for support multi languages.

Locale files in frontend/locales

All language files are located under frontend/locales/{language}.json.
Language file is like this;

{
  "namespace": {
     "key": "value",
     "nested-key": {
       "key": "nested-value"
    }
  }
}

Texts in frontend/pages/ and frontend/components

import useTranslation from "next-translate/useTranslation";
......
 const { t } = useTranslation("");
 ......
 <div>{t("common:hello")}</div>
 ......

Define namespaces and locales in frontend/i18n.js

Defines the namespaces to use per page

docker-compose.dev.yml

https://github.com/gangjun06/infisical/blob/4c94ddd1b2635143ef93c941962c2bd29dfdd828/docker-compose.dev.yml#L52-53
To change language files without recreate full container with just restart, Added this lines.

Translate key convention?

I didn't make it clearly, but i followed some rules.

  • use - for space in key.
  • seperate namespace by page and section.
  • make keys simple as possible

ETC

For vscode, i18n-ally is very useful plugin for translated file.
It can be able to preview value of the translate key.

@vmatsiiako vmatsiiako linked an issue Nov 28, 2022 that may be closed by this pull request
@gangjun06
Copy link
Contributor Author

gangjun06 commented Dec 2, 2022

I'm sorry that it is taking a long time and little delayed.
I'll make it mergeable without conflict in a few days.

@vmatsiiako
Copy link
Collaborator

Hi @gangjun06! Don't worry about it! Just take as much time as you need! We really appreciate your contributions. Thank you.

@gangjun06 gangjun06 marked this pull request as ready for review December 6, 2022 13:11
@gangjun06
Copy link
Contributor Author

I didn't translated all texts, but It seems almost done and ready to merge. If possible, I'll create translate part2 later.

@vmatsiiako
Copy link
Collaborator

HI @gangjun06! This is really awesome! I'm still looking into this, it's a lot of code 😃

Do you think you could fix the merge conflicts?

@gangjun06
Copy link
Contributor Author

I fixed conflicts 5910bfb

@vmatsiiako
Copy link
Collaborator

Quick question. Why did you decide to use next-translate instead of next-i18next?

@gangjun06 gangjun06 changed the title WIP: Localize Web UI #39 Localize Web UI #39 Dec 8, 2022
@gitguardian
Copy link

gitguardian bot commented Dec 26, 2022

⚠️ GitGuardian has uncovered 4 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
- Generic High Entropy Secret 5b8337a .env.example View secret
- Generic High Entropy Secret 5b8337a .env.example View secret
- Generic High Entropy Secret 5b8337a .env.example View secret
- Generic High Entropy Secret 5b8337a .env.example View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@gangjun06
Copy link
Contributor Author

gangjun06 commented Dec 26, 2022

Updated module to next-i18next and resolved all merge conflicts.

Some Notes

Apply translation to page

Next-i18next needs getServersideProps for all pages.
So more convenient, I created some utility on frontend/components/utilities/withTranslateProps.ts
You can use it like this:

import { getTranslatedServerSideProps } from "~/utilities/withTranslateProps";
export const getServerSideProps = getTranslatedServerSideProps(["dashboard"]);
---
import { getTranslatedStaticProps } from "~/components/utilities/withTranslateProps";
export const getStaticProps = getTranslatedStaticProps(["auth", "login"]);

Too many locale files

I couldn't find good way for manage namespaces in one file. So, I just created lots of file in locales/{language}.
Maybe make all locale texts to same namespace will be better way. (But I created multiple namespaces because next-i18next doesn't cache locale text, just load all texts in every time page load.)

How language change works?

I believe next-i18next doesn't have language change function. It's just working with dynamic locale path. (/en/... , /ko/.......)
So, I save locale on the localStorage, and if the URL doesn't match with current locale, It will be redirect to correct url by useEffect in _app. I can't sure it's good way, Actually I didn't looked up much about this library.


Currently, this PR doesn't cover all texts. If no one contributes to this, I'll create new PR later when I am free(Maybe Jan 3rd week~).

Also, I'm so sorry for being late

@vmatsiiako
Copy link
Collaborator

Sounds good! Thank you so much, I will have a look soon!

Quick question. If a translation is not available, does the text default to English?

@gangjun06
Copy link
Contributor Author

gangjun06 commented Dec 26, 2022

Yes, default locale is English.
/login -> English
/en/login -> English
/{registered-locale}/login -> Registered locale
/other-wrong-locale/login -> 404 Page Not Found

@vmatsiiako
Copy link
Collaborator

Do you maybe know why this error occurs on all pages? Trying to look into this right now

Screenshot 2022-12-26 at 16 15 18

@gangjun06
Copy link
Contributor Author

gangjun06 commented Dec 27, 2022

Do you maybe know why this error occurs on all pages? Trying to look into this right now

Screenshot 2022-12-26 at 16 15 18

@mv-turtle
Oooops It was my mistake... I fixed it by using router.asPath instead of router.pathname in _app.js.

@vmatsiiako
Copy link
Collaborator

I think all of this makes sense! Thank you so much for the contribution ❤️
Would you be able to help fix the merge conflicts? there seem to be quite a lot :)

@vmatsiiako
Copy link
Collaborator

I solved all the merge conflicts! Merging now :)
Thank you so much for the contribution!!! 🚀❤️

@gangjun06 I will work on adding translation to some part of the app where it's missing right now. Would you be able to help translating them to Korean when you have time? Also, do you think you could help translate our Readme? 😃 I think we should try to do something like Supabase does (https://github.com/supabase/supabase/blob/master/i18n/languages.md)

@vmatsiiako vmatsiiako merged commit c9dc024 into Infisical:main Dec 27, 2022
@gangjun06 gangjun06 deleted the feat/39 branch December 28, 2022 13:49
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.

Localize Web UI
2 participants