Django i18n along side jQuery Globalize's messages for a single page application

566 views Asked by At

I have a Django based API layer which internally uses Django's i18n facilities (ugettext etc.) to provide translations to some outputs. The API feeds a single page Javascript application which makes use of jQuery's Globalize and its own messaging facilities via CLDN/messages files etc.

At the moment I have my own generated language file for the UI in the form of a JSON file for Globalize's messages module.
Ideally I want to drive all translatable text from one location. I was hoping to use Django as the single source of truth of translatable language (as I can use Rosetta as a way to facilitate translations). However, it's not so trivial as to how to make the two work together, and I'm trying to avoid inventing my own conventions where they might already exist to prevent future confusions with other developers.

First, some text blocks are larger than a few words. Using Django's ugettext I'm expected to provide the text to be translated or shown as argument - is it good convention to provide just a key and require the translation to exist (or otherwise, just the key would show)?

Second, is there an established convention for this kind of use case?
I do not want to reinvent the wheel or diverge from the norm if the norm makes sense for this scenario.

And third - am I expected to choose between the two? Or can the translations live within the Django/API world and then outputted to Globalize/messages format when requested by the UI? Or should I use the Django provided gettext implementations for Javascript?

Thanks

1

There are 1 answers

1
Kmaschta On

The Django's JS internationalization is very powerful and comes with all the good practices. You said it, it's better to not reinvent the wheel.

If your coworkers are accustomed to use Django, they'll appreciate the move, in my opinion.

I'm not an expert, but Django's i18n can manage more than few words per blocks, it can serve paragraphs, the .po file will be like that:

msgid ""                                                                                                                                                                  
"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
" Duis ut lacus nec lacus rhoncus luctus."
" Donec luctus fringilla massa, eu accumsan odio vestibulum fermentum."
" Fusce arcu urna, tincidunt id turpis sed, rutrum lobortis sem." 
msgstr ""
"Translation goes here, and it can be on multiple lines"