Skip to content

Instantly share code, notes, and snippets.

@beck
Last active August 29, 2015 14:19
Show Gist options
  • Save beck/b73b83ce0b625b030aea to your computer and use it in GitHub Desktop.
Save beck/b73b83ce0b625b030aea to your computer and use it in GitHub Desktop.
because django's jsi18n js makes me sad
{% if LANGUAGE_CODE == 'en' %}
{% compress js inline %}
<script>
window.json_locale_data = {
"messages": {},
"locale": "en",
"lang": "en"
};
</script>
{% endcompress %}
{% elif LANGUAGE_CODE == 'de' %}
{% compress js %}<script src="{{STATIC_URL}}compiled/i18n/de/messages.js"></script>{% endcompress %}
{% elif LANGUAGE_CODE == 'es' %}
{% compress js %}<script src="{{STATIC_URL}}compiled/i18n/es/messages.js"></script>{% endcompress %}
{% elif LANGUAGE_CODE == 'fr' %}
{% compress js %}<script src="{{STATIC_URL}}compiled/i18n/fr/messages.js"></script>{% endcompress %}
{% elif LANGUAGE_CODE == 'it' %}
{% compress js %}<script src="{{STATIC_URL}}compiled/i18n/it/messages.js"></script>{% endcompress %}
{% elif LANGUAGE_CODE == 'pt-br' %}
{% compress js %}<script src="{{STATIC_URL}}compiled/i18n/pt_BR/messages.js"></script>{% endcompress %}
{% endif %}
{% comment %}
POs are converted to JS catalogs during build.
Example grunt task using:
https://github.com/mozilla/i18n-abide#popot-files
```js
grunt.initConfig({
abideCompile: {
javascriptCatalogs: {
dest: 'collected_static/compiled/i18n',
options: {
type: 'json',
localeDir: 'collected_static/compiled/locale',
}
}
}
})
```
And using gettext function:
https://github.com/beck/i18n-abide-gettext/blob/master/gettext.js
{% endcomment %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment