Skip to content

Commit

Permalink
i18n reduction to en/jp/zh_cn
Browse files Browse the repository at this point in the history
  • Loading branch information
sctop committed Mar 17, 2024
1 parent fda8d51 commit f9937a5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion data
Submodule data updated 176 files
46 changes: 35 additions & 11 deletions data_model/loader/manager_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,43 @@ def load(self):

def __getitem__(self, item) -> LangStringModel:
temp = dict((key, value.get(item)) for key, value in self.translations.items())
if temp["zh_cn"] == "":
# Special i18n case: Student Name, etc.
# There are at lease 3 variants when talking about that in Chinese.
# - zh_cn_cn indicates the data from the Blue Archive (China Server)
# - zh_cn_tw indicates the data from the Blue Archive (Global/Taiwan Server)
# But with the content being converted from Traditional to Simplified Chinese
# - zh_cn_jp indicates the data from a third-party unofficial translation of
# the original Japanese content (which is widely-accepted as well).
m = ZhLangStringModel()
m.load(temp)
else:

# NEW: ZhLangStringModel 自动降级到 LangStringModel
# 由于 ZhLangStringModel 在导出到JSON后太占存储空间,为了爱和正义决定根据特殊情况将其自动
# 降级到 LangStringModel 进行处置
if temp["zh_cn_cn"] == temp["zh_cn_jp"] == temp["zh_cn_tw"]:
# 如果三者全部都一样,那不就是单语言?
temp["zh_cn"] = temp["zh_cn_cn"]
m = LangStringModel()
m.load(temp)
else:
# 单独考察三种小语言,是不是有两个是空的
try:
if temp["zh_cn_cn"] == "" and temp["zh_cn_jp"] == "":
temp["zh_cn"] = temp["zh_cn_tw"]
elif temp["zh_cn_cn"] == "" and temp["zh_cn_tw"] == "":
temp["zh_cn"] = temp["zh_cn_jp"]
elif temp["zh_cn_jp"] == "" and temp["zh_cn_tw"] == "":
temp["zh_cn"] = temp["zh_cn_cn"]
else:
# 哦原来降级不了啊
raise AssertionError
except AssertionError:
# 降级不了,老老实实.jpg
# Special i18n case: Student Name, etc.
# There are at lease 3 variants when talking about that in Chinese.
# - zh_cn_cn indicates the data from the Blue Archive (China Server)
# - zh_cn_tw indicates the data from the Blue Archive (Global/Taiwan Server)
# But with the content being converted from Traditional to Simplified Chinese
# - zh_cn_jp indicates the data from a third-party unofficial translation of
# the original Japanese content (which is widely-accepted as well).
m = ZhLangStringModel()
m.load(temp)
else:
# 能降级就嗯降
m = LangStringModel()
m.load(temp)

return m

def query(self, key):
Expand Down
7 changes: 5 additions & 2 deletions data_model/types/lang_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

__all__ = ["LangStringModel", "LangStringModelList", "ZhLangStringModel"]

EXPORT_FOR_LANGSTRINGMODEL = ["en", "jp", "zh_cn"]
EXPORT_FOR_ZHLANGMODEL = ["en", "jp", "zh_cn_jp", "zh_cn_tw", "zh_cn_cn"]


class LangStringModel(BaseDataModel):
"""如 name description 此类需要多语言支持的东西"""
Expand All @@ -12,7 +15,7 @@ class LangStringModel(BaseDataModel):
ko = String("ko")
zh_cn = String("zh_cn")
zh_tw = String("zh_tw")
_components = ["en", "jp", "thai", "ko", "zh_cn", "zh_tw"]
_components = EXPORT_FOR_LANGSTRINGMODEL

def __init__(self, key_name=None):
super().__init__(key_name)
Expand Down Expand Up @@ -51,7 +54,7 @@ class ZhLangStringModel(LangStringModel):
zh_cn_jp = String("zh_cn_jp")
zh_cn_tw = String("zh_cn_tw")
zh_cn_cn = String("zh_cn_cn")
_components = ["en", "jp", "thai", "ko", "zh_tw", "zh_cn_jp", "zh_cn_tw", "zh_cn_cn"]
_components = EXPORT_FOR_ZHLANGMODEL

def load(self, data: dict):
super().load(data)
Expand Down

0 comments on commit f9937a5

Please sign in to comment.