diff --git a/data b/data index 8925f8a..4fc2f61 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 8925f8a25fc97e84dd5d1c641edc55eeba9cd3d7 +Subproject commit 4fc2f61c3dbda6442fbfd2723d6670b97b5f9d42 diff --git a/data_model/loader/manager_i18n.py b/data_model/loader/manager_i18n.py index a6fe5d1..593ecb8 100644 --- a/data_model/loader/manager_i18n.py +++ b/data_model/loader/manager_i18n.py @@ -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): diff --git a/data_model/types/lang_string.py b/data_model/types/lang_string.py index 69c3aeb..be484d2 100644 --- a/data_model/types/lang_string.py +++ b/data_model/types/lang_string.py @@ -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 此类需要多语言支持的东西""" @@ -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) @@ -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)