---
title: "国际化和本地化"
version: 2.2
locale: zh-hans
source: https://docs.djangoproject.com/zh-hans/2.2/topics/i18n/
canonical: https://djangodocs.dev/zh-hans/2.2/topics/i18n/
---
# 国际化和本地化

## 概况

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

Django 完整支持 [翻译文本](/zh-hans/2.2/topics/i18n/translation/)， [格式化日期，时间和数字](/zh-hans/2.2/topics/i18n/formatting/) 以及 [时区](/zh-hans/2.2/topics/i18n/timezones/)。

实际上，Django 做了两件事：

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

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

## 定义

单词国际化（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](https://www.w3.org/International/questions/qa-i18n), the [Wikipedia article](https://en.wikipedia.org/wiki/Internationalization_and_localization) or the [GNU gettext documentation](https://www.gnu.org/software/gettext/manual/gettext.html#Concepts).

> **Warning**
>
> Translation and formatting are controlled by [`USE_I18N`](/zh-hans/2.2/ref/settings/#std-setting-USE_I18N) and
> [`USE_L10N`](/zh-hans/2.2/ref/settings/#std-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:

**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](#term-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.

**format file**

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