2010-02-16 20:12:53 +08:00
|
|
|
=====================================
|
|
|
|
Internationalization and localization
|
|
|
|
=====================================
|
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
.. toctree::
|
|
|
|
:hidden:
|
|
|
|
:maxdepth: 1
|
|
|
|
|
|
|
|
translation
|
|
|
|
formatting
|
2011-11-18 21:01:06 +08:00
|
|
|
timezones
|
2011-10-23 01:17:57 +08:00
|
|
|
|
2010-02-16 20:12:53 +08:00
|
|
|
Overview
|
|
|
|
========
|
|
|
|
|
2021-07-23 14:48:16 +08:00
|
|
|
The goal of internationalization and localization is to allow a single web
|
2011-10-23 01:17:57 +08:00
|
|
|
application to offer its content in languages and formats tailored to the
|
|
|
|
audience.
|
|
|
|
|
|
|
|
Django has full support for :doc:`translation of text
|
2011-11-18 21:01:06 +08:00
|
|
|
</topics/i18n/translation>`, :doc:`formatting of dates, times and numbers
|
|
|
|
</topics/i18n/formatting>`, and :doc:`time zones </topics/i18n/timezones>`.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
|
|
|
Essentially, Django does two things:
|
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
* It allows developers and template authors to specify which parts of their apps
|
|
|
|
should be translated or formatted for local languages and cultures.
|
2021-07-23 14:48:16 +08:00
|
|
|
* It uses these hooks to localize web apps for particular users according to
|
2011-10-23 01:17:57 +08:00
|
|
|
their preferences.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2019-06-17 22:54:55 +08:00
|
|
|
Translation depends on the target language, and formatting usually depends on
|
|
|
|
the target country. This information is provided by browsers in the
|
|
|
|
``Accept-Language`` header. However, the time zone isn't readily available.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
Definitions
|
|
|
|
===========
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
The words "internationalization" and "localization" often cause confusion;
|
|
|
|
here's a simplified definition:
|
|
|
|
|
|
|
|
.. glossary::
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
internationalization
|
|
|
|
Preparing the software for localization. Usually done by developers.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
localization
|
|
|
|
Writing the translations and local formats. Usually done by translators.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
More details can be found in the `W3C Web Internationalization FAQ`_, the `Wikipedia article`_ or the `GNU gettext documentation`_.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2018-01-07 21:28:41 +08:00
|
|
|
.. _W3C Web Internationalization FAQ: https://www.w3.org/International/questions/qa-i18n
|
2015-11-30 00:29:46 +08:00
|
|
|
.. _GNU gettext documentation: https://www.gnu.org/software/gettext/manual/gettext.html#Concepts
|
2015-08-08 18:02:32 +08:00
|
|
|
.. _Wikipedia article: https://en.wikipedia.org/wiki/Internationalization_and_localization
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
.. warning::
|
2010-02-16 20:12:53 +08:00
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
Translation and formatting are controlled by :setting:`USE_I18N` and
|
|
|
|
:setting:`USE_L10N` settings respectively. However, both features involve
|
|
|
|
internationalization and localization. The names of the settings are an
|
|
|
|
unfortunate result of Django's history.
|
|
|
|
|
|
|
|
Here are some other terms that will help us to handle a common language:
|
2010-02-16 20:12:53 +08:00
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
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``.
|
2020-05-03 05:49:03 +08:00
|
|
|
Examples: ``it``, ``de_AT``, ``es``, ``pt_BR``, ``sr_Latn``. The language
|
|
|
|
part is always in lowercase. The country part is in titlecase if it has
|
|
|
|
more than 2 characters, otherwise it's in uppercase. The separator is an
|
|
|
|
underscore.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
|
|
|
language code
|
|
|
|
Represents the name of a language. Browsers send the names of the
|
|
|
|
languages they accept in the ``Accept-Language`` HTTP header using this
|
2014-10-21 02:01:01 +08:00
|
|
|
format. Examples: ``it``, ``de-at``, ``es``, ``pt-br``. Language codes
|
2018-09-25 22:30:18 +08:00
|
|
|
are generally represented in lowercase, but the HTTP ``Accept-Language``
|
2014-10-21 02:01:01 +08:00
|
|
|
header is case-insensitive. The separator is a dash.
|
2010-02-16 20:12:53 +08:00
|
|
|
|
|
|
|
message file
|
|
|
|
A message file is a plain-text file, representing a single language,
|
|
|
|
that contains all available :term:`translation strings
|
|
|
|
<translation string>` and how they should be represented in the given
|
|
|
|
language. Message files have a ``.po`` file extension.
|
|
|
|
|
|
|
|
translation string
|
|
|
|
A literal that can be translated.
|
|
|
|
|
2011-10-23 01:17:57 +08:00
|
|
|
format file
|
|
|
|
A format file is a Python module that defines the data formats for a given
|
2013-11-03 02:13:29 +08:00
|
|
|
locale.
|