-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d76c749
commit f3f3897
Showing
8 changed files
with
146 additions
and
72 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,2 @@ | ||
FLASK_DEBUG = 1 | ||
BABEL_DEFAULT_LOCALE = zh |
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,3 +1,4 @@ | ||
__pycache__/ | ||
.idea | ||
.vercel | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- encoding: utf-8 -*- | ||
"""基础文件""" | ||
|
||
import re | ||
import json | ||
import sys | ||
import tomllib as tl | ||
from pathlib import Path | ||
|
||
# 当前绝对路径 | ||
P = Path(__file__).resolve().parent | ||
|
||
# 加载配置 | ||
CONFIG_DIR = P / "configuration.toml" | ||
if not CONFIG_DIR.exists(): | ||
print("\n无法找到配置文件,请将配置文件放置在与此脚本同级的目录下。") | ||
sys.exit() | ||
with open(CONFIG_DIR, "rb") as f: | ||
config = tl.load(f) | ||
|
||
LANG_DIR = P / config["language_folder"] | ||
IGNORE_SUPPLEMENTS = config["ignore_supplements"] | ||
|
||
# 读取语言文件 | ||
print("开始读取语言文件。") | ||
file_list = [ | ||
"en_us.json", | ||
"zh_cn.json", | ||
"zh_hk.json", | ||
"zh_tw.json", | ||
"lzh.json", | ||
] | ||
data = {} | ||
for file in file_list: | ||
with open(LANG_DIR / file, "r", encoding="utf-8") as f: | ||
data[file.split(".", maxsplit=1)[0]] = json.load(f) | ||
|
||
# 读取补充字符串 | ||
if not IGNORE_SUPPLEMENTS: | ||
with open(LANG_DIR / "supplements.json", "r", encoding="utf-8") as f: | ||
supplements = json.load(f) | ||
for lang in ["zh_cn", "zh_hk", "zh_tw", "lzh"]: | ||
data[lang].update(supplements[lang]) | ||
print(f"已补充{len(supplements['zh_cn'])}条字符串。") | ||
|
||
|
||
def is_valid_key(translation_key: str): | ||
"""判断是否为有效键名""" | ||
|
||
prefixes = ( | ||
"block.", | ||
"item.minecraft.", | ||
"entity.minecraft.", | ||
"biome.", | ||
"effect.minecraft.", | ||
"enchantment.minecraft.", | ||
"trim_pattern.", | ||
"upgrade.", | ||
) | ||
|
||
if ( | ||
translation_key.startswith(prefixes) | ||
and not re.match( | ||
r"(block\.minecraft\.|item\.minecraft\.|entity\.minecraft\.)[^.]*\.", | ||
translation_key, | ||
) | ||
and translation_key | ||
not in ["block.minecraft.set_spawn", "entity.minecraft.falling_block_type"] | ||
and "pottery_shard" not in translation_key | ||
): | ||
return True | ||
|
||
# 匹配进度键名 | ||
if re.match(r"advancements\.(.*)\.title", translation_key): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def get_translation(query_str: str): | ||
"""在语言文件中匹配含有输入内容的源字符串""" | ||
translation = {} | ||
for k, v in data["en_us"].items(): | ||
if query_str.lower() in v.lower(): | ||
element = {lang: content.get(k, "?") for lang, content in data.items()} | ||
translation[k] = element | ||
return translation |
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,5 @@ | ||
# 语言文件文件夹 | ||
language_folder = "lang" | ||
|
||
# 是否忽略补充字符串 | ||
ignore_supplements = true |
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 +1,6 @@ | ||
Flask==3.0.0 | ||
Flask==3.0.1 | ||
flask_wtf==1.2.1 | ||
fonttools==4.47.2 | ||
python-dotenv==1.0.1 | ||
Requests==2.31.0 | ||
WTForms==3.1.2 |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- encoding: utf-8 -*- | ||
"""手动设置环境变量并导入程序实例""" | ||
|
||
from pathlib import Path | ||
from dotenv import load_dotenv | ||
from app import flask_app | ||
|
||
dotenv_path = Path(__file__).resolve().parent / ".env" | ||
if dotenv_path.exists(): | ||
load_dotenv(dotenv_path) | ||
|
||
app = flask_app |