简体   繁体   中英

Django naturaltime Localization error

My language ID is 'id'. I used localized humanize library for my Django template tags and use the naturaltime , but the translation is partially wrong. The now translated to sekarang is right. second to detik . minute to menit , but when it comes to date , week , or months , the word is not translated to my language. It keeps printing date , week , and months .

Here are my Django configuration

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.

You could add translations yourself.

Missing translations on 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. 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 ). Don't forget to restart django apps to see the changes. Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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