国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。
Django 完整支持 翻译文本, 格式化日期,时间和数字 以及 时区。
实际上,Django 做了两件事:
显而易见,翻译依赖于目标语言,而格式化规则依赖于目标国家。此信息由浏览器的 Accept-Language
头提供。但是,时区并不容易获得。
单词国际化(internationalization)和本地化(localization)总是令人迷惑;以下是个简单的定义:
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:
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.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..po
file extension.12月 02, 2019