Questions tagged [django-i18n]

Django internationalization provides developers with the ability to build web applications and provide content in multiple languages and locales.

Django internationalization provides developers with the ability to build web applications and provide content in multiple languages and locales.

For text translations, the Django developer can accomplish this goal by adding a minimal amount of hooks to Python and templates. These hooks are called translation strings. They tell Django: “This text should be translated into the end user’s language, if a translation for this text is available in that language.”

Internationalization is achieved in three steps:

  1. Embed translation strings in your Python code and templates.
  2. Get translations for those strings, in whichever languages you want to support.
  3. Activate the locale middleware in your Django settings.
359 questions
14
votes
2 answers

How to specify context of translation in Django {% trans %} {% blocktrans %}?

Documentation of Django says Contextual markers are also supported by the trans and blocktrans template tags. but it not explained how to do it? Can you help marking translation context since I have some words with several meanings. In Python I can…
Chameleon
  • 9,722
  • 16
  • 65
  • 127
13
votes
5 answers

Django: i18n - change language

I installed model_translation, rosetta, locale_url. But does not work change language. My settings.py: LANGUAGE_CODE = 'ru' MODELTRANSLATION_TRANSLATION_REGISTRY = "project.translation" TRANSLATION_REGISTRY = "project.translation" ugettext = lambda…
Taras
  • 131
  • 1
  • 1
  • 3
13
votes
3 answers

How to maintain different country versions of same language in Django?

I would like to have a few different versions of the same language in Django, customized for different countries (e.g. locale/en, locale/en_CA, locale/en_US, etc.). If there is no language for specific country I would expect to use the default…
Jordan Jambazov
  • 3,460
  • 1
  • 19
  • 40
13
votes
1 answer

Django i18n blocktrans vs trans

In Django templates, what exactly is the difference between these two: {% blocktrans %}My Text{% endblocktrans %} {% trans 'My Text' %}
tzenderman
  • 2,523
  • 3
  • 21
  • 24
12
votes
1 answer

Translating formatted strings in Django not working

I have problem with translating formatted strings in Django using django.utils.translations. Only strings without format (%s or {}) are working. My locale/en/LC_MESSAGES/django.po file: msgid "foo" msgstr "bar" #, python-format msgid "foo…
bns
  • 182
  • 2
  • 11
12
votes
3 answers

How to save `LANGUAGE_CODE` to database with i18n switcher so that the language is not changed in different browsers in Django?

Is there any way to change the value of LANGUAGE_CODE variable in settings.py dynamically on clicking a button (sending a request)? I want the user to have their own "default language" set for their account. Right now the user can select their…
12
votes
3 answers

Some strings not translated in django i18n module

I have some strange troubles with django's internationalization module. Most of strings are translated as they must be and some other aren't. Let me show you and example:
  • {% trans "Upload Score" %}
  • {% trans "Profile" %}
  • {%…
  • arthur
    • 950
    • 1
    • 5
    • 18
    11
    votes
    2 answers

    Empty catalog when internationalizing JavaScript code

    I'm trying to set up Internationalization of JavaScript code in my Django application. My Django app has a locale subdirectory with a properly generated djangojs.po file. The package definition is as follows: # urls.py js_info_dict = { …
    kingsley
    • 305
    • 3
    • 12
    11
    votes
    3 answers

    Django translation escape % sign

    I'm trying to translate some text that contains a percent sign like so: {% trans "100% butterfly" %} When I run the makemessages command, I get the following output in my german .po file: #: .\appName\templates\appName\butterflies.html:54 #,…
    tayden
    • 570
    • 7
    • 20
    11
    votes
    1 answer

    Django i18n: recommended size and formatting for {% blocktrans %} blocks?

    I am just getting started with Django internationalization and trying to understand the best practices for using {% blocktrans %}. Is it preferable to use one {% blocktrans %} for each paragraph, or should I have one big {% blocktrans %} that…
    RexE
    • 17,085
    • 16
    • 58
    • 81
    10
    votes
    1 answer

    How to make spaces and indentation insignificant in Django blocktrans?

    Image the following blocktrans in some Django template: {% blocktrans %} Some Text {% endblocktrans %} After some changes in the templates, you might like to indent the block:
    {% blocktrans %} Some Text {% endblocktrans…
    Jordan Jambazov
    • 3,460
    • 1
    • 19
    • 40
    8
    votes
    1 answer

    Django translation not working on production

    I've made translation of the site for different cities and it works fine on dev machine. But when published on production server it didn't show any translation. But it shows available languages and current language correctly. Here's my…
    8
    votes
    1 answer

    When to use the locale name and when the language code in Django?

    According to Django Documentation: locale name A locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC. Examples: it, de_AT, es, pt_BR. The language part is always in lower…
    nalzok
    • 14,965
    • 21
    • 72
    • 139
    8
    votes
    3 answers

    Django makemessages javascript (xgettext)

    I want to use django i18n support to translate my javascript files. I have the following javascript file: var test_text = gettext('example'); @withStyles(styles) export default class HomePage { static contextTypes = { i18n: PropTypes.object …
    ilse2005
    • 11,189
    • 5
    • 51
    • 75
    8
    votes
    1 answer

    Collecting messages from 3rd party apps in Django

    How can I generate messages (manage.py makemessages) from 3rd party library which is located in virtualenv directory? I tried simply add the messages to the .po file, but everytime I run makemessages command my translation vanishes. Many thanks
    n1_
    • 4,227
    • 4
    • 34
    • 35
    1
    2
    3
    23 24