Simpler i18n for Python / Django

My question is about i18n in Python. From what I understand, this includes:

  • Create a message file in the language (ONLY ONE ?!).
  • in this file, each message will have the format
    • English message here
    • Message en Francais ici (yeah shitty french ..)
  • then this file is compiled into another faster binary format
  • repeat for all other required languages
  • in the application code ( Django) use the translation method with the English (or default) language, which will be correctly translated to the locales ...tr('English message Here')

I guess I'm a little staggered, but does that seem like common sense?

I am wondering if there is an easier way? I mean, in the java webapp world, you are setting up message package files in a format bundleName_locale.properties. Each of them usually has a key to the relation to the message, for example greeting = Hello World., you can have many different properties files for different subnets of your site / application. All locale files are hierarchical, and the missing keys in the subdirectory fall into the parent element, etc. All this is done automatically by Java, with no configuration required.

Is there anything similar in the Django / Python world? Is it really crazy to follow this path? Can I fake this using the module as a stand for the java.properties file? Sorry for the long question and thanks for any input.

+3
1

, , .

:

  • Django i18n gettext, .
  • , Django .
  • , Django, .
    • 5 , -, , .
  • .
    • _("My String") .py from django.utils.translation import ugettext as _.
    • {% trans "My String" %} . , .
    • bundle.getString("My String") , , .
  • Django i18n JavaScript, .
  • - .
  • , .
    • "" Java?
  • .
  • .properties - , , .

.po:

#: templates/inquiries/settings/new_field.html:12
#: templates/inquiries/settings/new_form.html:4
msgid "Save"
msgstr ""

, , .

+13

Source: https://habr.com/ru/post/1758414/


All Articles