{"title":"国际化和本地化","version":"2.2","locale":"zh-hans","docname":"topics/i18n/index","url":"/zh-hans/2.2/topics/i18n/","canonical":"https://djangodocs.dev/zh-hans/2.2/topics/i18n/","summary":"国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。Django 完整支持翻译文本，格式化日期，时间和数字以及时区。","html":"<h1>国际化和本地化<a class=\"heading-anchor\" href=\"#internationalization-and-localization\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<div class=\"toctree-wrapper compound\">\n</div>\n<section id=\"overview\">\n<h2>概况<a class=\"heading-anchor\" href=\"#overview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。</p>\n<p>Django 完整支持 <a class=\"reference internal\" href=\"/zh-hans/2.2/topics/i18n/translation/\"><span class=\"doc\">翻译文本</span></a>， <a class=\"reference internal\" href=\"/zh-hans/2.2/topics/i18n/formatting/\"><span class=\"doc\">格式化日期，时间和数字</span></a> 以及 <a class=\"reference internal\" href=\"/zh-hans/2.2/topics/i18n/timezones/\"><span class=\"doc\">时区</span></a>。</p>\n<p>实际上，Django 做了两件事：</p>\n<ul class=\"simple\">\n<li><p>它允许开发者和模板作者指定应用的哪个部分应该被翻译或格式化为本地语言，符合本地文化。</p></li>\n<li><p>它根据用户的配置利用钩子本地化 Web 应用。</p></li>\n</ul>\n<p>显而易见，翻译依赖于目标语言，而格式化规则依赖于目标国家。此信息由浏览器的 <code class=\"docutils literal notranslate\">Accept-Language</code> 头提供。但是，时区并不容易获得。</p>\n</section>\n<section id=\"definitions\">\n<h2>定义<a class=\"heading-anchor\" href=\"#definitions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>单词国际化（internationalization）和本地化（localization）总是令人迷惑；以下是个简单的定义：</p>\n<dl class=\"simple glossary\">\n<dt id=\"term-internationalization\">国际化<a class=\"heading-anchor\" href=\"#term-internationalization\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>Preparing the software for localization. Usually done by developers.</p>\n</dd>\n<dt id=\"term-localization\">本地化<a class=\"heading-anchor\" href=\"#term-localization\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>Writing the translations and local formats. Usually done by translators.</p>\n</dd>\n</dl>\n<p>More details can be found in the <a class=\"reference external\" href=\"https://www.w3.org/International/questions/qa-i18n\">W3C Web Internationalization FAQ</a>, the <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Internationalization_and_localization\">Wikipedia article</a> or the <a class=\"reference external\" href=\"https://www.gnu.org/software/gettext/manual/gettext.html#Concepts\">GNU gettext documentation</a>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>Translation and formatting are controlled by <a class=\"reference internal\" href=\"/zh-hans/2.2/ref/settings/#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\">USE_I18N</code></a> and\n<a class=\"reference internal\" href=\"/zh-hans/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\">USE_L10N</code></a> settings respectively. However, both features involve\ninternationalization and localization. The names of the settings are an\nunfortunate result of Django's history.</p>\n</aside>\n<p>Here are some other terms that will help us to handle a common language:</p>\n<dl class=\"simple glossary\">\n<dt id=\"term-locale-name\">locale name<a class=\"heading-anchor\" href=\"#term-locale-name\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>A locale name, either a language specification of the form <code class=\"docutils literal notranslate\">ll</code> or a\ncombined language and country specification of the form <code class=\"docutils literal notranslate\">ll_CC</code>.\nExamples: <code class=\"docutils literal notranslate\">it</code>, <code class=\"docutils literal notranslate\">de_AT</code>, <code class=\"docutils literal notranslate\">es</code>, <code class=\"docutils literal notranslate\">pt_BR</code>. The language part is\nalways in lowercase and the country part in upper case. The separator is\nan underscore.</p>\n</dd>\n<dt id=\"term-language-code\">language code<a class=\"heading-anchor\" href=\"#term-language-code\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>Represents the name of a language. Browsers send the names of the\nlanguages they accept in the <code class=\"docutils literal notranslate\">Accept-Language</code> HTTP header using this\nformat. Examples: <code class=\"docutils literal notranslate\">it</code>, <code class=\"docutils literal notranslate\">de-at</code>, <code class=\"docutils literal notranslate\">es</code>, <code class=\"docutils literal notranslate\">pt-br</code>. Language codes\nare generally represented in lowercase, but the HTTP <code class=\"docutils literal notranslate\">Accept-Language</code>\nheader is case-insensitive. The separator is a dash.</p>\n</dd>\n<dt id=\"term-message-file\">message file<a class=\"heading-anchor\" href=\"#term-message-file\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>A message file is a plain-text file, representing a single language,\nthat contains all available <a class=\"reference internal\" href=\"#term-translation-string\"><span class=\"xref std std-term\">translation strings</span></a> and how they should be represented in the given\nlanguage. Message files have a <code class=\"docutils literal notranslate\">.po</code> file extension.</p>\n</dd>\n<dt id=\"term-translation-string\">translation string<a class=\"heading-anchor\" href=\"#term-translation-string\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>A literal that can be translated.</p>\n</dd>\n<dt id=\"term-format-file\">format file<a class=\"heading-anchor\" href=\"#term-format-file\"><span class=\"visually-hidden\">Link to this term</span><span aria-hidden=\"true\">#</span></a></dt><dd><p>A format file is a Python module that defines the data formats for a given\nlocale.</p>\n</dd>\n</dl>\n</section>","rootId":"internationalization-and-localization","toc":[{"title":"概况","anchor":"overview","children":[]},{"title":"定义","anchor":"definitions","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"使用 Django","url":"/zh-hans/2.2/topics/"}],"prev":{"docname":"topics/email","title":"发送邮件","url":"/zh-hans/2.2/topics/email/"},"next":{"docname":"topics/i18n/translation","title":"翻译","url":"/zh-hans/2.2/topics/i18n/translation/"},"formats":{"html":"/zh-hans/2.2/topics/i18n/","markdown":"/zh-hans/2.2/topics/i18n.md","json":"/zh-hans/2.2/topics/i18n.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/topics/i18n/index.txt","official":"https://docs.djangoproject.com/zh-hans/2.2/topics/i18n/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}