-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Migrate to i18next for internationalization #4731
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
Merged
Merged
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
d78919c
Add files via upload
ac-mmi ac566eb
Add files via upload
ac-mmi 29a4416
Merge branch 'sugarlabs:master' into master
ac-mmi 1678672
Merge branch 'sugarlabs:master' into master
ac-mmi 5ead512
Migrate internationalization from webL10n to i18next in JS files
ac-mmi b844c94
removed random encodings spoiling the .po files
ac-mmi 5cf011e
Add files via upload
ac-mmi 1680230
Changed the function definition of _() suited for i18next
ac-mmi d8bbb85
Merge branch 'internalization-js' of https://github.com/ac-mmi/musicb…
ac-mmi d6b1114
updated the i18next json files
ac-mmi e6e8c5a
changed the language switch functions to i18next standard in activity…
ac-mmi c21fb14
Merge branch 'master' into internalization-js
ac-mmi 7c46058
Add files via upload
ac-mmi a238ef8
Add files via upload
ac-mmi ce5a5e5
Delete locales/ja-kana.json
ac-mmi c9d69ca
Delete locales/ja.json
ac-mmi fe630ea
Add files via upload
ac-mmi c25e7fb
Merge branch 'master' into internalization-js
ac-mmi 740b4da
Merge branch 'master' into internalization-js
ac-mmi dcb2d7e
Merge branch 'master' into internalization-js
ac-mmi 040a030
Add files via upload
ac-mmi bbaca35
Add files via upload
ac-mmi 4540621
Add files via upload
ac-mmi 75f50db
Add files via upload
ac-mmi 45990f8
Update translate_ai.py
ac-mmi ea46f98
Add files via upload
ac-mmi 8abe738
migration to i18next
ac-mmi ca1987f
migration to i18next
ac-mmi d4bd26f
Merge branch 'master' into i18next
ac-mmi 25ecd9b
fixed the linting issue
ac-mmi 72bfad3
Merge branch 'i18next' of https://github.com/ac-mmi/musicblocks into …
ac-mmi a0c1ef5
fixed some test cases of toolbar due to addition of TR language had t…
ac-mmi 3b0d1d5
added newly updated TR file
ac-mmi d6e56e4
fix: update package-lock.json to sync with package.json
ac-mmi c09ab33
Merge branch 'i18next' of https://github.com/ac-mmi/musicblocks into …
ac-mmi 13b94b9
removed old kana kanji jap files
ac-mmi 4d88b7e
added docstring in po to json converter
ac-mmi 97ecdee
added license and copyright in the converter file
ac-mmi c9695d5
added worflow for auto conversion of po to json files
ac-mmi b19803b
testing worflow
ac-mmi d01f9c9
chore(i18n): auto-update JSON files from updated PO files
github-actions[bot] ae4a2a4
resolved the lng change issues in japanese
ac-mmi cd88498
Merge branch 'i18next' of https://github.com/ac-mmi/musicblocks into …
ac-mmi 0e9346e
solved the lang change issue for japanese kana and kanji
ac-mmi 3e0f528
solved the issue of separate loader image in case of jap lang and adv…
ac-mmi 19f02bf
po files updation
ac-mmi 7b11ec7
chore(i18n): auto-update JSON files from updated PO files
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """ | ||
| This script converts GNU gettext .po translation files into JSON format. | ||
| It extracts only `msgid` and `msgstr` pairs, skipping metadata and comments, | ||
| and writes them to language-specific .json files for use in localization. | ||
|
|
||
| Usage: | ||
| - Place .po files inside a directory (e.g., ./po) | ||
| - The script will convert all .po files in that directory into .json | ||
| and save them to the specified output directory (e.g., ./locales) | ||
| """ | ||
|
|
||
| import os | ||
| import json | ||
| import re | ||
|
|
||
| def convert_po_to_json(po_file, output_dir): | ||
| """Convert a .po file to .json reading only msgid and msgstr lines.""" | ||
|
|
||
| json_data = {} | ||
| current_msgid = None | ||
| current_msgstr = None | ||
|
|
||
| with open(po_file, "r", encoding="utf-8") as f: | ||
| for line in f: | ||
| # Ignore all lines except those with msgid or msgstr | ||
| line = line.strip() | ||
| if line.startswith("msgid"): | ||
| current_msgid = re.findall(r'"(.*)"', line)[0] | ||
| elif line.startswith("msgstr"): | ||
| current_msgstr = re.findall(r'"(.*)"', line)[0] | ||
| # Save the pair if msgid is present | ||
| if current_msgid is not None: | ||
| json_data[current_msgid] = current_msgstr or current_msgid | ||
| current_msgid = None # Reset for the next pair | ||
|
|
||
| # Extract language code (e.g., 'fr' from 'fr.po') | ||
| lang_code = os.path.splitext(os.path.basename(po_file))[0] | ||
| output_path = os.path.join(output_dir, f"{lang_code}.json") | ||
|
|
||
| os.makedirs(output_dir, exist_ok=True) | ||
| with open(output_path, "w", encoding="utf-8") as f: | ||
| json.dump(json_data, f, indent=2, ensure_ascii=False) | ||
|
|
||
| print(f"✅ Converted {po_file} → {output_path}") | ||
|
|
||
| def convert_all_po_files(po_dir, output_dir): | ||
| """Convert all .po files in the given directory to .json format.""" | ||
| for root, _, files in os.walk(po_dir): | ||
| for file in files: | ||
| if file.endswith(".po"): | ||
| convert_po_to_json(os.path.join(root, file), output_dir) | ||
|
|
||
| convert_all_po_files("./po", "./locales") | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.