简体   繁体   English

Django Naturaltime Localization错误

[英]Django naturaltime Localization error

My language ID is 'id'. 我的语言ID是“ id”。 I used localized humanize library for my Django template tags and use the naturaltime , but the translation is partially wrong. 我为Django模板标签使用了本地化的人性化库,并使用了naturaltime ,但是翻译部分错误。 The now translated to sekarang is right. now翻译为sekarang是正确的。 second to detik . second detik minute to menit , but when it comes to date , week , or months , the word is not translated to my language. minutemenit ,但是当涉及到dateweekmonths ,这个词没有被翻译成我的语言。 It keeps printing date , week , and months . 它保持打印dateweekmonths

Here are my Django configuration 这是我的Django配置

TIME_ZONE = 'Asia/Jakarta'
LANGUAGE_CODE = 'id'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True

Here how I used the naturaltime template tags. 在这里,我如何使用自然时间模板标签。

<time class="discussion__info__item">{{ object.created|naturaltime }}</time>

Do I forgot something? 我忘了什么吗? Thank you. 谢谢。

Unfortunately translations for day = hari, week = minggu, month = bulan, year = tahun etc. are missing in the .../site-packages/django/contrib/humanize/locale/id/LC_MESSAGES/django.[mp]o gettext files. 不幸的是, .../site-packages/django/contrib/humanize/locale/id/LC_MESSAGES/django.[mp]o humanize .../site-packages/django/contrib/humanize/locale/id/LC_MESSAGES/django.[mp]o中缺少day = hari,week = minggu,month = bulan,year = tahun等的翻译.../site-packages/django/contrib/humanize/locale/id/LC_MESSAGES/django.[mp]o gettext文件。

You could add translations yourself. 您可以自己添加翻译。

Missing translations on full-path-to../django/conf/locale/id/LC_MESSAGES/django.po . 缺少full-path-to../django/conf/locale/id/LC_MESSAGES/django.po翻译full-path-to../django/conf/locale/id/LC_MESSAGES/django.po

Search weeks, month and any other string you want to translate on that file, then translate at the line msgstr. 搜索星期,月份以及要在该文件上转换的任何其他字符串,然后在msgstr行进行转换。 Example, 例,

#: utils/timesince.py:27
#, python-format
msgid "%d day"
msgid_plural "%d days"
msgstr[0] "%d hari"

After that, convert to django.mo using any tools (you can use online tools like http://po2mo.net ). 之后,使用任何工具转换为django.mo (您可以使用诸如http://po2mo.net之类的在线工具)。 Don't forget to restart django apps to see the changes. 不要忘记重启django应用程序以查看更改。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM