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 react-i18next for multi-language support #917

Merged
merged 28 commits into from
Aug 19, 2024
Merged

Conversation

keichan34
Copy link
Contributor

This is a rough start on adding react-i18next. I'll be working on adding more translatable strings and translations in the coming days. I'm going to need to wrap class components in HOCs, so let me know if there's something I should be fixing before doing that. I'm thinking now to keep the exported class names exactly the same, and rename the existing classes by prefixing an I (for internal). For example:

export default class AppToolbar ...

becomes

class IAppToolbar ...
const AppToolbar = withTranslation()(IAppToolbar);
export default AppToolbar;

I'll be able to contribute Japanese strings (I've talked to a couple people on my team and they'll be happy to help as well), so that's the language I decided to go with in this PR.

Closes #746

@HarelM
Copy link
Collaborator

HarelM commented Aug 8, 2024

The main pain point right now is the warning in the console for the auto complete component. If you can fix that before/during introduction of i18n it would be great.
Also, if there's a component library that can be used that supports i18n out of the box it might be a direction worth exploring.

@keichan34
Copy link
Contributor Author

@HarelM Thanks. I'll check out the auto complete component while I'm working on this, but doing a cursory search, it looks like there might not be much to translate in the auto complete component? I think it's just being used for values in the style itself -- not for field labels, etc? Unless I'm misunderstanding something?

@HarelM
Copy link
Collaborator

HarelM commented Aug 14, 2024

It's less about the i18n of the auto complete component, it more about replacing it with something that doesn't create console warning.
I get why it might not be relevant at all for this PR though.
I'm not a react expert, so I was hoping someone like you could easily fix this.

i18next-parser.config.js Outdated Show resolved Hide resolved
src/components/FieldId.tsx Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Aug 14, 2024

Thanks for taking the time to open this PR!
Can you add a screenshot of the language button?
Can you also add a e2e test to check language switch and make sure the text is changed?

@HarelM
Copy link
Collaborator

HarelM commented Aug 14, 2024

Also I'm not sure what should happen for RTL languages - i.e. translating to Hebrew and Arabic requires more than simple string substitution, and that's why I asked about using a component library that supports i18n, or something similar.
IDK...

@keichan34
Copy link
Contributor Author

I haven't had much experience doing translation in RTL languages, if you know anyone who uses RTL and can help us out, that would be great. I think really supporting RTL would be a bit more involved than just replacing strings, like you said -- we'd probably have to change the layout of the map to be on the left, the toolbar, etc, so there would probably be some CSS and manual i18next.dir() === 'rtl' ? ... : ... usage here and there...

Will be adding E2E tests. Here's what the language button/menu looks like now.

Screenshot 2024-08-14 at 16 36 03 Screenshot 2024-08-14 at 16 36 11 Screenshot 2024-08-14 at 16 36 21

Let me know if maybe it should go somewhere else. I just put it here because it was easy to copy-and-paste the view menu.

Thanks for taking the time to take a look at the PR.

@HarelM
Copy link
Collaborator

HarelM commented Aug 15, 2024

I'm speaking Hebrew so I can help out in terms of RTL.
It does require more work by adding the dir attribute to all kind of places in the code and have this configured globally somehow.
I have an app which is uses angular material and is fully RTL and LTR compatible here: https://israelhiking.osm.org.il/ but the extra dir is not an easy fix.
It would be nice however to include the ability to add dir=... as part of this PR.

@HarelM
Copy link
Collaborator

HarelM commented Aug 15, 2024

I've added Hebrew translation, please remove the survey translations and the relevant component as it is no longer in use.

@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 58.82353% with 49 lines in your changes missing coverage. Please review.

Project coverage is 58.31%. Comparing base (f34529e) to head (13d0b04).
Report is 8 commits behind head on main.

Files Patch % Lines
src/components/ModalSources.tsx 27.27% 8 Missing ⚠️
src/components/ModalSourcesTypeEditor.tsx 22.22% 7 Missing ⚠️
src/components/LayerEditor.tsx 60.00% 6 Missing ⚠️
src/components/_DataProperty.tsx 0.00% 4 Missing ⚠️
src/components/_ZoomProperty.tsx 0.00% 4 Missing ⚠️
src/components/InputDynamicArray.tsx 40.00% 3 Missing ⚠️
src/components/ModalSettings.tsx 0.00% 3 Missing ⚠️
src/components/_ExpressionProperty.tsx 0.00% 3 Missing ⚠️
src/components/ModalLoading.tsx 0.00% 2 Missing ⚠️
src/components/AppMessagePanel.tsx 50.00% 1 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #917      +/-   ##
==========================================
+ Coverage   57.23%   58.31%   +1.08%     
==========================================
  Files         104      105       +1     
  Lines        2932     3025      +93     
  Branches      667      669       +2     
==========================================
+ Hits         1678     1764      +86     
- Misses       1254     1261       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

Thanks for taking care of the Firefox annoying test failures.
If they continue to fail I'll simply remove them from CI.
Do you want this merged or are you planning more changes?

@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

Can you also delete the following file and remove references to it?
ModalSurvey.tsx
Thanks!

@keichan34 keichan34 marked this pull request as ready for review August 19, 2024 09:22
@keichan34 keichan34 changed the title [WIP] Add react-i18next for multi-language support Add react-i18next for multi-language support Aug 19, 2024
@keichan34
Copy link
Contributor Author

Let me know if there is anything else I should brush up.

@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

Let's push it and see how it behaves :-)

@HarelM HarelM merged commit 58edd26 into maplibre:main Aug 19, 2024
7 checks passed
@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

Looks nice! A lot better than I expected!
image

I think "zoom:" is missing in the zoom component.
Search placeholder for the geocoder control too (I'm now updating it with typescript, so it should be easier soon)

We might want to add a test to see that all the keys exist in the translation file, it should be a relatively simple test.

@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

P.S. the word Language should be kept in english, otherwise if you accidentally change the language, it's hard to understand where to click in order to revert to English.
"שפה" in the above screenshot.

@keichan34
Copy link
Contributor Author

Ah: I forgot. The maplibre controls only pick up the translation on initialization, so if you refresh the page, it should work. It has to do with the controls being outside of React's area of control, so I'll have to listen for the i18next events to make switching working with them. I think we should make a tracking issue? or individual issues? for fixes like these? What do you think?

@HarelM
Copy link
Collaborator

HarelM commented Aug 19, 2024

Sure, tracking issues should be better. If the map controls are hard to update I wouldn't stress about them, your call.

@keichan34 keichan34 deleted the 746-i18n branch August 22, 2024 11:55
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.

multi-language
4 participants