Comments (7)
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'.
from microblog.
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.
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
from microblog.
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.
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.
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 acceptszh_cn
.
I don't find any support from moment.js or flask_babel documentation.
from microblog.
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.
Thank you for your patience to answer my question.
from microblog.
Related Issues (20)
- Chapter 22 Export task stuck at 0% HOT 5
- elastic_transport.ConnectionError when post is submitted? HOT 6
- Using JinJa2 filter function truncate to implement 'Read more'? HOT 21
- Bug in lesson 5 due to werkzeug.urls - url parsing removed HOT 4
- Lesson 6, FLASK_ENV is removed from Flask 2.3.0 HOT 2
- Unable to load celery application. 'str' object has no attribute 'level' when Integrating Celery with Flask? HOT 17
- Unable to import 'url_parse' from 'werkzeug.urls' in flask shell execution HOT 15
- login error was reported during deployment? HOT 7
- Github links in chapters start with wrong tag (one-off) HOT 2
- Dead link to flask-babel docs HOT 1
- flask_moment error when trying to format HOT 4
- Multidict Package Problematic in python:slim HOT 1
- next HOT 3
- Error: Cannot import name 'app' from 'app' HOT 2
- Exporting a huge number of database records HOT 3
- ImportError...circular import HOT 3
- Chp 4 udemy course: Video 27 Time 1 min: db.sessions.add(u) Generates Error
- Tagging system HOT 3
- Chapter 7 -Listing 63: Email without from-adress and subject HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microblog.