miguelgrinberg/microblog

Language inconsistency during poedit translation process?

Closed this issue · 7 comments

According to tutorial, i used poedit to translate language. But a single language is a mix of two different languages like chinese and english. The tricky point is that %(when)s produces an uncertain long string whose format is like "number + date"
rather than a single string. How to solve it to make it become a pure one-kind language?
5
6

Precisely speaking, %(username) said %(when)s shoudle be translated into a whole chinese clause like “username 发布于 10 天前" ranther than a mix 'username 发布于 10 days ago'.
7

This line shows how to set the locale for date and time conversions. If this does not work for Chinese, then it is a problem with the moment.js library and should be reported to them as a bug.

This line shows how to set the locale for date and time conversions. If this does not work for Chinese, then it is a problem with the moment.js library and should be reported to them as a bug.

I indeed have these code in base template and in routes.py
8
9

To test Chinese timestamps, I changed the line I highlighted above in base.html to this:

    {{ moment.lang('zh-cn') }}

Then I started the application, and I'm getting timestamps in Chinese.

image

I do not know if this is correct or not, but the moment.js library clearly has support for the language.

I think the issue is on your side. You need to debug why the locale that is passed to the moment.js library is English instead of Chinese.

I happen to find a chinese who have meet same question at https://zhuanlan.zhihu.com/p/79061618.
According to his statement, the reason lies in the language code acceptance inconsistency between flask_babel and moment.js:

the get_locale function from flask_babel only accepts chinese code 'zh' and 'zh-cn'. But moment.lang(g.locale) only accepts zh_cn.

I don't find any support from moment.js or flask_babel documentation.

As I said before, it is difficult for me to test a language that I do not understand, but based on what I could find out the solution is to use a language code that is supported by moment.js. The list of available locales is here: https://github.com/moment/moment/tree/develop/locale. There are four Chinese regions to choose from.

Once you select the one you want to use, create a translation repository with that language code, and then I think everything will work correctly for you.

Thank you for your patience to answer my question.