Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]翻译代码逻辑错误 #58

Closed
JoeanAmier opened this issue Mar 17, 2024 · 2 comments
Closed

[BUG]翻译代码逻辑错误 #58

JoeanAmier opened this issue Mar 17, 2024 · 2 comments
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems) 已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push)

Comments

@JoeanAmier
Copy link

测试代码执行位置:f2/i18n/translator.py,将语言设置为en_US

    ...
    def gettext(self, message):
        _ = self.load_translations("en_US")
        if _:
            return _(message)
        return message


_ = TranslationManager.get_instance().gettext

print(_(
    "未在响应的地址中找到sec_user_id, 检查链接是否为用户主页类名: {0}".format(
        "cls.__name__"
    )
))

在调用gettext函数之前对占位符进行格式化,会导致字符串找不到翻译而输出原文,输出结果:

未在响应的地址中找到sec_user_id, 检查链接是否为用户主页类名: cls.__name__

应该修改为下方代码,在调用gettext函数获取翻译后,再对占位符进行格式化。

    ...
    def gettext(self, message):
        _ = self.load_translations("en_US")
        if _:
            return _(message)
        return message


_ = TranslationManager.get_instance().gettext

print(_(
    "未在响应的地址中找到sec_user_id, 检查链接是否为用户主页类名: {0}").format("cls.__name__"
                                                                               ))

输入结果:

Not found sec_user_id in the response, check if the link is to the user's homepage class name: cls.__name__

@JoeanAmier JoeanAmier added the 故障(bug) 代码问题导致的错误(Bugs caused by code problems) label Mar 17, 2024
@Johnserf-Seed Johnserf-Seed added the 已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push) label Mar 17, 2024
@Johnserf-Seed
Copy link
Owner

这确实存在问题,已收到反馈

@JoeanAmier
Copy link
Author

要修改的话,除了手动修改每处使用了占位符的代码,有没有其他高效的修改方案?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems) 已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push)
Projects
None yet
Development

No branches or pull requests

2 participants