-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from VeriTas-arch
simplified Chinese translations and minor
- Loading branch information
Showing
6 changed files
with
1,553 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains 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,8 @@ | ||
# Tools for Translators | ||
|
||
This directory contains tools that can help translators to work more efficiently. | ||
|
||
## Tools | ||
|
||
- `check.py`: Check which keys are missing in the translation files. | ||
- `sort.py`: Sort the keys in the translation files. |
This file contains 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,100 @@ | ||
import json | ||
from pathlib import Path | ||
import re | ||
|
||
ROOT_DIR = Path(__file__).resolve().parent.parent.parent | ||
JSON_DIR = ROOT_DIR / "src/main/resources/assets/mythicmetals/lang" | ||
LANG_SOURCE = JSON_DIR / "en_us.json" # Original language file, set to English by default | ||
LANG_TARGET = JSON_DIR / "zh_cn.json" # Target language file, set to your own language file | ||
IGNORE_PATTERNS = [r"doge", r"froge", r".color"] | ||
|
||
|
||
def load_json(file_path): | ||
with open(file_path, "r", encoding="utf-8") as f: | ||
return json.load(f) | ||
|
||
|
||
def should_ignore_key(key, ignore_patterns): | ||
""" | ||
Judge whether the key should be ignored (supports regex matching). | ||
Parameters | ||
---------- | ||
key : str | ||
The key to be checked (full path, e.g., "metadata.author"). | ||
ignore_patterns : list | ||
List of regex patterns to ignore. | ||
Returns | ||
------- | ||
bool | ||
Whether to ignore (True / False). | ||
""" | ||
return any(re.search(pattern, key) for pattern in ignore_patterns) | ||
|
||
|
||
def find_untranslated_keys(source, localized, untranslated_keys=None, parent_key="", ignore_patterns=None): | ||
""" | ||
Look for untranslated keys recursively, supporting the use of | ||
regular expressions to exclude specific keys. | ||
Parameters | ||
---------- | ||
source | ||
Original JSON data. | ||
localized | ||
Localized JSON data. | ||
untranslated_keys : list, optional | ||
Record untranslated keys. | ||
parent_key : str, optional | ||
Record nested key paths. | ||
ignore_patterns : list, optional | ||
List of regular expression patterns to exclude keys. | ||
Returns | ||
------- | ||
untranslated_keys : list | ||
Untranslated keys. | ||
""" | ||
if untranslated_keys is None: | ||
untranslated_keys = [] | ||
if ignore_patterns is None: | ||
ignore_patterns = [] | ||
|
||
if isinstance(source, dict): | ||
for key, value in source.items(): | ||
new_key = f"{parent_key}.{key}" if parent_key else key | ||
|
||
if should_ignore_key(new_key, ignore_patterns): | ||
continue | ||
|
||
if key in localized: | ||
if isinstance(value, (dict, list)): | ||
find_untranslated_keys( | ||
value, localized[key], untranslated_keys, new_key, ignore_patterns | ||
) | ||
elif localized[key] == value: | ||
untranslated_keys.append(new_key) | ||
else: | ||
untranslated_keys.append(new_key) | ||
|
||
elif isinstance(source, list) and isinstance(localized, list): | ||
for index, (s_item, l_item) in enumerate(zip(source, localized)): | ||
find_untranslated_keys( | ||
s_item, l_item, untranslated_keys, f"{parent_key}[{index}]", ignore_patterns | ||
) | ||
|
||
return untranslated_keys | ||
|
||
|
||
source_json = load_json(LANG_SOURCE) | ||
localized_json = load_json(LANG_TARGET) | ||
|
||
untranslated_keys = find_untranslated_keys(source_json, localized_json, ignore_patterns=IGNORE_PATTERNS) | ||
|
||
if untranslated_keys: | ||
print(f"You have {len(untranslated_keys)} untranslated keys:") | ||
for key in untranslated_keys: | ||
print(key) | ||
else: | ||
print("All keys are translated!") |
This file contains 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,43 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
ROOT_DIR = Path(__file__).resolve().parent.parent.parent | ||
JSON_DIR = ROOT_DIR / "src/main/resources/assets/mythicmetals/lang" | ||
INPUT = JSON_DIR / "zh_cn.json" # Original json file to be sorted | ||
OUTPUT = JSON_DIR / "zh_cn.json" # Output json file, set to the same as INPUT for in-place sorting | ||
|
||
|
||
def sort_json_keys(obj): | ||
""" | ||
Sort all dictionary keys in the JSON structure recursively. | ||
Parameters | ||
---------- | ||
obj : dict or list | ||
JSON data to be sorted (dictionary or list). | ||
Returns | ||
------- | ||
JSON data after reordering. | ||
""" | ||
if isinstance(obj, dict): | ||
return {key: sort_json_keys(obj[key]) for key in sorted(obj.keys())} | ||
elif isinstance(obj, list): | ||
return [sort_json_keys(item) for item in obj] | ||
else: | ||
return obj | ||
|
||
|
||
def reorder_json_file(input_file, output_file): | ||
with open(input_file, "r", encoding="utf-8") as f: | ||
data = json.load(f) | ||
|
||
sorted_data = sort_json_keys(data) | ||
|
||
with open(output_file, "w", encoding="utf-8") as f: | ||
json.dump(sorted_data, f, ensure_ascii=False, indent=4) | ||
|
||
|
||
reorder_json_file(INPUT, OUTPUT) | ||
|
||
print("JSON sorting completed.") |
This file contains 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 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 |
---|---|---|
@@ -1,38 +1,33 @@ | ||
# Mythic Metals | ||
|
||
Mythic Metals is a Fabric based Minecraft mod, that adds new ores, materials, tools and sets of armor. | ||
The mod is heavily inspired by Shadowclaimers Metallurgy, and was originally intended as a port. | ||
After being denied the privilege to do so this mod was created from the ground up as my first proper Minecraft mod. | ||
Mythic Metals is a Fabric based Minecraft mod, that adds new ores, materials, tools and sets of armor. The mod is heavily inspired by Shadowclaimers Metallurgy, and was originally intended as a port. After being denied the privilege to do so this mod was created from the ground up as my first proper Minecraft mod. | ||
|
||
You can find the patch notes in the [PATCHNOTES.md](PATCHNOTES.md) file. | ||
|
||
## Download | ||
|
||
You can download the mod from CurseForge, Modrinth, use CI builds, or build it yourself. | ||
CurseForge link: | ||
https://www.curseforge.com/minecraft/mc-mods/mythicmetals | ||
You can download the mod from CurseForge, Modrinth, use CI builds, or build it yourself. | ||
|
||
Modrinth link: | ||
https://modrinth.com/mod/mythicmetals | ||
|
||
GitHub Actions link: | ||
https://github.com/Noaaan/MythicMetals/actions | ||
- CurseForge link: <https://www.curseforge.com/minecraft/mc-mods/mythicmetals> | ||
- Modrinth link: <https://modrinth.com/mod/mythicmetals> | ||
- GitHub Actions link: <https://github.com/Noaaan/MythicMetals/actions> | ||
|
||
## License | ||
|
||
This mod is licensed under a custom MIT license. Please read it before re-using any code. | ||
You can use this mod as an example/base for adding in blocks, ingots, armor, tools, and ore generation for Fabric mods. | ||
Feel free to use this in any modpack you wish for. | ||
Some modpacks that use Mythic Metals: | ||
- Euphoric Curiosities: https://www.curseforge.com/minecraft/modpacks/euphoriccuriosity | ||
- Medieval Minecraft (Fabric): https://www.curseforge.com/minecraft/modpacks/medieval-mc-fabric-mmc2 | ||
- BounceSMP: https://www.curseforge.com/minecraft/modpacks/bouncesmp-public | ||
This mod is licensed under a custom MIT license. Please read it before re-using any code. You can use this mod as an example/base for adding in blocks, ingots, armor, tools, and ore generation for Fabric mods. Feel free to use this in any modpack you wish for. | ||
|
||
Some modpacks that use Mythic Metals: | ||
|
||
- Euphoric Curiosities: <https://www.curseforge.com/minecraft/modpacks/euphoriccuriosity> | ||
- Medieval Minecraft (Fabric): <https://www.curseforge.com/minecraft/modpacks/medieval-mc-fabric-mmc2> | ||
- BounceSMP: <https://www.curseforge.com/minecraft/modpacks/bouncesmp-public> | ||
|
||
## Credits | ||
|
||
See [the Credits file in the repo](CREDITS.md), as it contains a shoutout to everyone who has worked on the project! | ||
|
||
## Translations | ||
Feel free to contribute a translation if you want to! | ||
I currently do not support Crowdin, so you will have to either put it up as a pull request or raise an issue with a translated lang file. | ||
|
||
Feel free to contribute a translation if you want to! I currently do not support Crowdin, so you will have to either put it up as a pull request or raise an issue with a translated lang file. | ||
|
||
Any translator is added to [the Credits.](CREDITS.md) |
Oops, something went wrong.