Translations and quotes...

29 views
Skip to first unread message

Jonas Obrist

unread,
Oct 11, 2011, 6:05:54 AM10/11/11
to django-cms...@googlegroups.com
So it happened again. Quotes end up in translation strings (for some reason always in 'es') and the JS breaks horribly.


We really need a solution for this. And I'd say the best way is escaping in the templates. However those are trans-tags, so not sure how to do it. Maybe {% escaped_js_string %}{% trans "mymsgid" %}{% endescaped_js_string %} (the block tag would include the actual quotes).

Thoughts?

Ionel Cristian Maries

unread,
Oct 11, 2011, 6:33:39 AM10/11/11
to django-cms...@googlegroups.com
Django's own javascript_catalog view could be used. It looks like they do proper quoting.

Eg,
provided that there are djangojs catalogs in the locale dirs (looks like there are):
    url(r'^jsi18n', 'django.views.i18n.javascript_catalog', {
        'packages': ['cms'],
    }, name='cms-jsi18n'),


Thanks,
-- Ionel
M.

Jonas Obrist

unread,
Oct 11, 2011, 8:08:39 AM10/11/11
to django-cms...@googlegroups.com
But that's an extra request, right?

Jonas Obrist

unread,
Oct 11, 2011, 8:10:58 AM10/11/11
to django-cms...@googlegroups.com

Mario César Señoranis Ayala

unread,
Oct 11, 2011, 8:33:48 AM10/11/11
to django-cms...@googlegroups.com
Hello All,

I made the pull request, briefly: About "for some reason always in 'es'" that Jonas says, is about how it's show Anglicism on the translations, there is no easy translation for plugin in spanish, maybe "conectado", sounds to funny.

Jonas lead me to a solution, add a new template filter and escape the js strings instead of changing the translations strings:

{% load js i18n %}
var str1 = '{% filter js_string %}¿Te gusta el 'plugin'?{% endfilter %}';
var str2 = "{% filter js_string %}¿Te gusta este otro 'plugin'?{% endfilter %}";
var str3 = "{% filter js_string %}{% trans %}Do you like this plugin?{% entrans %}{% endfilter %}";
This currently working for me
, here is the pull request for the changes → https://github.com/divio/django-cms/pull/1046



Jonas Obrist

unread,
Oct 11, 2011, 9:20:15 AM10/11/11
to django-cms...@googlegroups.com
I do however prefer the syntax:

{% load js i18n %}
var str1 = {% js_string %}{% trans "somestring" %}{% endfilter %};

The template tag should be responsible for the quotes as well, to make it easier and more stable.
Reply all
Reply to author
Forward
0 new messages