Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django i18n: How to translate css content?

Have the following css section:

.introduction:before { content: 'Who is going to translate me in a graceful way?'; }

Probably there is no easy way to handle i18n for css file, two possible choices:

  1. gather all these css which with content and ship them together within Django templates.
  2. generate i18n sensitive css name in template to choose different pre-translated css content.

Any new possible solutions will be appreciated, thanks.

like image 565
IPX Avatar asked Sep 25 '12 15:09

IPX


2 Answers

I would serve the css file that needs translating through Django and cache it per language to mitigate the performance hit.

urls.py

url(r'^static/css/translated.css$', TemplateView.as_view(template_name='translated.css')),

translated.css

{% load cache %}
{% cache 60*60*24 translated_css LANGUAGE_CODE %}
  {# write css here, translate as a normal template #}
  .introduction:before { content: 
    {% trans 'Who is going to translate me in a graceful way?' %}
  ; }
{% endcache %}
like image 57
dokkaebi Avatar answered Sep 29 '22 15:09

dokkaebi


I think that this is impossible. Only you can translate it if the css is a template (like the html template). But this is a bad solution.... efficiency

But if you have a class language in the body for example, you can have something like this:

body.language_en .introduction:before { content: 'Who is going to translate me in a graceful way?'; }
body.language_es .introduction:before { content: 'El traductor de google es terrible :-)'; }

And in your base.html something like this:

....
<body class="language_{{ LANGUAGE_CODE }}">
....
like image 38
Goin Avatar answered Sep 29 '22 16:09

Goin