{"title":"国际化和本地化","version":"3.1","locale":"zh-hans","docname":"topics/i18n/index","url":"/zh-hans/3.1/topics/i18n/","canonical":"https://djangodocs.dev/zh-hans/3.1/topics/i18n/","summary":"概况 Link to this heading # 国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。 Django 完整支持 翻译文本 ， 格式化日期，时间和数字 以及 时区 。 实际上，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/3.1/topics/i18n/translation/\"><span class=\"doc\">翻译文本</span></a>， <a class=\"reference internal\" href=\"/zh-hans/3.1/topics/i18n/formatting/\"><span class=\"doc\">格式化日期，时间和数字</span></a> 以及 <a class=\"reference internal\" href=\"/zh-hans/3.1/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\"><span class=\"pre\">Accept-Language</span></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>为本地化准备软件。通常由开发者完成。</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>编写翻译和本地格式化。通常由翻译者完成。</p>\n</dd>\n</dl>\n<p>更多细节请查阅 <a class=\"reference external\" href=\"https://www.w3.org/International/questions/qa-i18n\">W3C Web Internationalization FAQ</a> ， <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Internationalization_and_localization\">Wikipedia article</a>  或  <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>翻译和格式化分别由 <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span></code></a> 控制。但是，这两个功能都涉及国际化和本地化。这两个配置的名字是 Django 的历史原因所导致。</p>\n</aside>\n<p>下面是一些术语，可以帮助我们处理通用语言：</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>区域名称，可以是 <code class=\"docutils literal notranslate\"><span class=\"pre\">ll</span></code> 形式的语言规范，也可以是 <code class=\"docutils literal notranslate\"><span class=\"pre\">ll_CC</span></code> 形式的语言和国家组合规范。例如：<code class=\"docutils literal notranslate\"><span class=\"pre\">it</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">de_AT</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">es</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">pt_BR</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">sr_Latn</span></code>。语言部分总是用小写。国家部分如果超过两个字符，则首字母大写，否则全部大写。分隔符为下划线。</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>代表语言名。浏览器使用这个格式来在 <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Language</span></code> HTTP header 里发送浏览器接受的语言名。比如：<code class=\"docutils literal notranslate\"><span class=\"pre\">it</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">de-at</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">es</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">pt-br</span></code> 。语言代码一般用小写表示，但是 HTTP <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Language</span></code> header 不区分大小写。用破折号来间隔。</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 class=\"reference internal\" href=\"#term-translation-string\"><span class=\"xref std std-term\">translation strings</span></a> ，以及它们如何在给定的语言里表示。消息文件的文件扩展名是 <code class=\"docutils literal notranslate\"><span class=\"pre\">.po</span></code> 。</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>可以翻译的文字。</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>格式文件是一个 Python 模块，用于定义本地数据格式。</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/3.1/topics/"}],"prev":{"docname":"topics/email","title":"发送邮件","url":"/zh-hans/3.1/topics/email/"},"next":{"docname":"topics/i18n/translation","title":"翻译","url":"/zh-hans/3.1/topics/i18n/translation/"},"formats":{"html":"/zh-hans/3.1/topics/i18n/","markdown":"/zh-hans/3.1/topics/i18n.md","json":"/zh-hans/3.1/topics/i18n.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/topics/i18n/index.txt","official":"https://docs.djangoproject.com/zh-hans/3.1/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"]}