I've been playing with localization on the client side. So I want to collect messages for djangojs from python and html files, but it didn't work
Django version is 1.3, Gettext utilitest are installed in the system
django-admin.py makemessages -d djangojs -l ru -e html,py
Does anyone know how to generate/use translations messages from django.po for JavaScript (djangojs)?
For example I put just ngettext("Hello world")
messages for test reasons in some js
file and finally it doesn't get into djangojs.po file.
Sultan
Django then provides utilities to extract the translation strings into a message file. This file is a convenient way for translators to provide the equivalent of the translation strings in the target language. Once the translators have filled in the message file, it must be compiled.
gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django's startup); gettext_lazy translates the strings in a lazy fashion, which means, eg.
{% load i18n %} is needed for internationalization. The purpose of internationalization is to allow a single application to read in multiple languages. In order to do this: you need a few hooks called translation strings. To give your template access to these tags, put {% load i18n %} toward the top of your template..
I'm the author of this question: Django 1.2.3 - Internationalization - makemessages does not detect all strings.
Your problem has probably the same cause as mine. It is because the makemessages for javascript is a hack and sometimes doesn't get the strings marked for translation. As the gettext tools do not support javascript, the code first goes through simple transforms and is then processed as Perl.
You can find an article about it here: A Javascript lexer in Python, and the saga behind it
And the bug report here: Ticket 7704. It is fixed in Django 1.4.
As my project was small, I edited the PO files directly but if yours is bigger you should use either django 1.4 RC or the patch linked in the bug report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With