Fix an issue that causes create symlink failed when installing java on unix-like platforms.
This commit is contained in:
1 parent
8bde4ef753
commit
1754b01230
15 files changed
+600
-77
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from string import Formatter
|
||||
|
||||
from core_lib.i18n import TranslationManager
|
||||
|
||||
|
||||
def test_empty_catalog_uses_english_source_strings(tmp_path):
|
||||
(tmp_path / "zh-TW.json").write_text("{}", encoding="utf-8")
|
||||
translations = TranslationManager(tmp_path, "zh-TW")
|
||||
|
||||
assert translations.language == "zh-TW"
|
||||
assert translations.translate("Settings") == "Settings"
|
||||
assert translations.translate("Version: {version}", version="1.0") == "Version: 1.0"
|
||||
|
||||
|
||||
def test_catalog_translation_and_unknown_language_fallback(tmp_path):
|
||||
(tmp_path / "zh-TW.json").write_text(
|
||||
json.dumps({"Settings": "設定"}), encoding="utf-8"
|
||||
)
|
||||
translations = TranslationManager(tmp_path, "zh-TW")
|
||||
assert translations.translate("Settings") == "設定"
|
||||
|
||||
translations.set_language("unsupported")
|
||||
assert translations.language == "en"
|
||||
assert translations.translate("Settings") == "Settings"
|
||||
|
||||
|
||||
def test_bundled_catalogs_have_matching_english_entries():
|
||||
catalog_dir = Path(__file__).parents[1] / "resources" / "translations"
|
||||
english = json.loads((catalog_dir / "en.json").read_text(encoding="utf-8"))
|
||||
traditional_chinese = json.loads(
|
||||
(catalog_dir / "zh-TW.json").read_text(encoding="utf-8")
|
||||
)
|
||||
|
||||
assert english
|
||||
assert set(traditional_chinese) == set(english)
|
||||
assert traditional_chinese["Settings"] == "設定"
|
||||
untranslated_names = {"English", "Fabric"}
|
||||
assert {
|
||||
key
|
||||
for key, value in traditional_chinese.items()
|
||||
if key == value
|
||||
} == untranslated_names
|
||||
|
||||
formatter = Formatter()
|
||||
for key, translated in traditional_chinese.items():
|
||||
source_fields = {
|
||||
field for _, field, _, _ in formatter.parse(key) if field is not None
|
||||
}
|
||||
translated_fields = {
|
||||
field
|
||||
for _, field, _, _ in formatter.parse(translated)
|
||||
if field is not None
|
||||
}
|
||||
assert translated_fields == source_fields, key
|
||||
Reference in new issue
Block a user