PageRenderTime 33ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

Plain Text | 113 lines | 85 code | 28 blank | 0 comment | 0 complexity | 39b2f328d378c317b56e340e6de1373c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. =====================================
  2. Internationalization and localization
  3. =====================================
  4. Overview
  5. ========
  6. Django has full support for internationalization of text in code and
  7. templates, and format localization of dates and numbers. Here's how it works.
  8. Essentially, Django does two things:
  9. * It allows developers and template authors to specify which parts of
  10. their apps should be translatable.
  11. * It uses these hooks to translate Web apps for particular users according
  12. to their language preferences.
  13. The complete process can be seen as divided in three stages. It is also possible
  14. to identify an identical number of roles with very well defined responsibilities
  15. associated with each of these tasks (although it's perfectly normal if you
  16. find yourself performing more than one of these roles):
  17. * For application authors wishing to make sure their Django apps can be
  18. used in different locales: :doc:`/topics/i18n/internationalization`.
  19. * For translators wanting to translate Django apps: :doc:`/topics/i18n/localization`.
  20. * For system administrators/final users setting up internationalized apps or
  21. developers integrating third party apps: :doc:`/topics/i18n/deployment`.
  22. .. toctree::
  23. :hidden:
  24. :maxdepth: 1
  25. internationalization
  26. localization
  27. deployment
  28. .. _ seealso::
  29. For more general information about the topic, see the `GNU gettext documentation`_
  30. and the `Wikipedia article`_.
  31. .. _GNU gettext documentation:
  32. .. _Wikipedia article:
  33. Glossary
  34. ========
  35. First lets define some terms that will help us to handle a common language:
  36. .. glossary::
  37. locale name
  38. A locale name, either a language specification of the form ``ll`` or a
  39. combined language and country specification of the form ``ll_CC``.
  40. Examples: ``it``, ``de_AT``, ``es``, ``pt_BR``. Note the underscore in
  41. some of them and the case of the part located to its right.
  42. language code
  43. Represents the name of a language. Browsers send the names of the
  44. languages they accept in the ``Accept-Language`` HTTP header using this
  45. format. Examples: ``it``, ``de-at``, ``es``, ``pt-br``. Note the ``-``
  46. separator.
  47. message file
  48. A message file is a plain-text file, representing a single language,
  49. that contains all available :term:`translation strings
  50. <translation string>` and how they should be represented in the given
  51. language. Message files have a ``.po`` file extension.
  52. translation string
  53. A literal that can be translated.
  54. .. _specialties-of-django-i18n:
  55. Specialties of Django translation
  56. =================================
  57. Django's translation machinery uses the standard ``gettext`` module that comes
  58. with Python. If you know ``gettext``, you might note these specialties in the
  59. way Django does translation:
  60. * The string domain is ``django`` or ``djangojs``. This string domain is
  61. used to differentiate between different programs that store their data
  62. in a common message-file library (usually ``/usr/share/locale/``). The
  63. ``django`` domain is used for python and template translation strings
  64. and is loaded into the global translation catalogs. The ``djangojs``
  65. domain is only used for JavaScript translation catalogs to make sure
  66. that those are as small as possible.
  67. * Django doesn't use ``xgettext`` alone. It uses Python wrappers around
  68. ``xgettext`` and ``msgfmt``. This is mostly for convenience.
  69. .. _technical-messages:
  70. Django technical message IDs
  71. ----------------------------
  72. .. versionchanged:: 1.2
  73. Starting with Django 1.2, technical message IDs are being replaced by :ref:`format-localization`
  74. Django uses technical message IDs to translate date formats and time formats.
  75. Technical message IDs are :term:`translation strings <translation string>` and
  76. can be easily recognized; they're all upper case. You don't translate the
  77. message ID as with other translation strings, you provide the correct local
  78. variant on the provided English value. The format is identical to the format
  79. strings used by the ``now`` template tag.
  80. For example, with ``DATETIME_FORMAT`` (or ``DATE_FORMAT`` or ``TIME_FORMAT``),
  81. this would be the format string that you want to use in your language. A Django
  82. contributor localizing it to Spanish probably would provide a ``"j N Y P"``
  83. "translation" for it in the relevant ``django.po`` file::
  84. msgid "DATETIME_FORMAT"
  85. msgstr "j N Y P"