国际化和本地化Link to this heading

概况Link to this heading

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

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

实际上,Django 做了两件事:

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

  • 它根据用户的配置利用钩子本地化 Web 应用。

显而易见,翻译依赖于目标语言,而格式化规则依赖于目标国家。此信息由浏览器的 Accept-Language 头提供。但是,时区并不容易获得。

定义Link to this heading

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

国际化Link to this term

Preparing the software for localization. Usually done by developers.

本地化Link to this term

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.

Here are some other terms that will help us to handle a common language:

locale nameLink to this term

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 codeLink to this term

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 fileLink to this term

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 stringLink to this term

A literal that can be translated.

format fileLink to this term

A format file is a Python module that defines the data formats for a given locale.