add i18n foundation with Arabic while maintaining Google Translate for progressive migration, fix translation issues, and improve language selector UX#241
Merged
mattqdev merged 19 commits intophysicshub:mainfrom Mar 26, 2026
Conversation
Collaborator
|
thank you so much for this! If you fix the conflicts i'll merge it |
Collaborator
|
eh sorry man my bad i merged a PR that was pretty similar to yours, so there are now more conflicts. |
Contributor
Author
The conflict was caused by a change in package-lock.json |
Collaborator
|
oh yea maybe i'm just too tired :/ Thank you anyway for fixing it! |
Collaborator
|
oh it hasn't fixed yet :/ |
Contributor
Author
I did fix it I just did a test because the merge behavior seemed strange, It's ready now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ChangeLogs
Summary
Adds i18n infrastructure with Arabic language support while maintaining Google Translate for a progressive migration path.
fixed google translate related issues.
afftected files
new files
found issues and fixes
1. language options are in english and affected by translations (resolved):
In app/(core)/components/GoogleTranslator.jsx
the language options are defined as:
I changed it to:
This allows people that can't read english to Identify their language immediatly,
this UX change is especially critical for speakers that can't read the Latin alphabet.
We also have to prevent Google translate from messing with them and keep them as they are.
before:
after:
the translate="no" attribute and the notranslate class will make google translate ignore the text.
2. preventing contributors github user names from being translated (resolved):
in app/(core)/components/ContributorsSection.jsx we find contributors card that displays their info,
the issue is that they are affected by google translate which can alter them.
To fix it I added
inside the className="contributor-info" div.
3. language select doesn't have a state and it default to English on reload (resolved):
in app/(core)/components/GoogleTranslator.jsx when selecting a language other than English like for example Spanish, then we reload the page, the page remains translated in Spanish but the selector dispalys "English" as it is the hardcoded initial value.
to fix it I used this helper function:
my current implementation only works with the added features I made.
Added features:
1. added arabic:
arabic is now available in both google translate and i18n:
2- added app/(core)/hooks/useTranslation.ts:
useTranslation is a hook that provides internationalization (i18n) capabilities for Next.js
first in a componentor page we import this hook then we define:
now we can use the wrapper t():
the hook is currently implemented only in app/(core)/components/Hero.jsx as a demonstration
in this folder we find the json files for each language (ar,de,en,es,fr,it)
example structure for ar.json (Arabic):
{ "hello":"مرحبًا", "edit": "تعديل" }currently I populated these json files with only the text from app/(core)/components/Hero.jsx
meta.json is a custom configuration file I speciffically made to allow us to do a progressive
transition from google translate to i18n it basically allows switching from google translate to manual translation for individual languages.
meta.json:
{ "en": { "name": "English", "completed": true }, "it": { "name": "Italian", "completed": false }, "es": { "name": "Spanish", "completed": false }, "fr": { "name": "French", "completed": false }, "de": { "name": "German", "completed": false }, "ar": { "name": "Arabic", "completed": false } }the "completed":false indicate that the .json file for the language is not ready yet and Nextjs fallsback to using GoogleTranslate.
When "completed" is set to true it means the json file is complete and Nextjs switches to
i18n had translation for that language in the case there is an unwrapped text or the wrapped text doesn't have a matching key the original English text will be returned.
currently there is one minor unresolved issue when using handtranslation for a language and the page is reloaded Google translate ignores the "completed": true flag and translates the page.
Currently not causing any problems since there is no hand translation being actively used