国际化和本地化
概况
The goal of internationalization and localization is to allow a single Webapplication to offer its content in languages and formats tailored to theaudience.
Django has full support for translation of text, formatting of dates, times and numbers, and time zones.
Essentially, Django does two things:
- It allows developers and template authors to specify which parts of their appsshould be translated or formatted for local languages and cultures.
- It uses these hooks to localize Web apps for particular users according totheir preferences.Obviously, translation depends on the target language, and formatting usuallydepends on the target country. This information is provided by browsers inthe
Accept-Language
header. However, the time zone isn't readily available.
Definitions
The words "internationalization" and "localization" often cause confusion;here's a simplified definition:
- internationalization
- Preparing the software for localization. Usually done by developers.
- localization
- 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.
Warning
Translation and formatting are controlled by USE_I18N
andUSE_L10N
settings respectively. However, both features involveinternationalization and localization. The names of the settings are anunfortunate 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 acombined language and country specification of the formll_CC
.Examples:it
,de_AT
,es
,pt_BR
. The language part isalways in lower case and the country part in upper case. The separatoris an underscore. - language code
- Represents the name of a language. Browsers send the names of thelanguages they accept in the
Accept-Language
HTTP header using thisformat. Examples:it
,de-at
,es
,pt-br
. Language codesare generally represented in lower-case, but the HTTPAccept-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 givenlanguage. 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 givenlocale.