Code Monkey home page Code Monkey logo

Comments (7)

JTP-123 avatar JTP-123 commented on June 11, 2024

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

from microblog.

miguelgrinberg avatar miguelgrinberg commented on June 11, 2024

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.

from microblog.

JTP-123 avatar JTP-123 commented on June 11, 2024

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

from microblog.

miguelgrinberg avatar miguelgrinberg commented on June 11, 2024

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.

from microblog.

JTP-123 avatar JTP-123 commented on June 11, 2024

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.

from microblog.

miguelgrinberg avatar miguelgrinberg commented on June 11, 2024

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.

from microblog.

JTP-123 avatar JTP-123 commented on June 11, 2024

Thank you for your patience to answer my question.

from microblog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.