国际化和本地化

概况

国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。

Django 完整支持 翻译文本格式化日期,时间和数字 以及 时区

实际上,Django 做了两件事:

  • 它允许开发者和模板作者指定应用的哪个部分应该被翻译或格式化为本地语言,符合本地文化。
  • 它根据用户的配置利用钩子本地化 Web 应用。

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.

定义

单词国际化(internationalization)和本地化(localization)总是令人迷惑;以下是个简单的定义:

国际化
Preparing the software for localization. Usually done by developers.
本地化
Writing the translations and local formats. Usually done by translators.

More details can be found in the W3C Web Internationalization FAQ, the Wikipedia article or the GNU gettext documentation.

警告

Translation and formatting are controlled by USE_I18N and 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:

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 lowercase and the country part in upper case. The separator is an underscore.
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 format. Examples: it, de-at, es, pt-br. Language codes are generally represented in lowercase, but the HTTP Accept-Language header is case-insensitive. The separator is a dash.
message file
A message file is a plain-text file, representing a single language, that contains all available translation strings 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.
format file
A format file is a Python module that defines the data formats for a given locale.