{"title":"国际化和本地化","version":"2.1","locale":"zh-hans","docname":"topics/i18n/index","url":"/zh-hans/2.1/topics/i18n/","canonical":"https://djangodocs.dev/zh-hans/2.1/topics/i18n/","summary":"概况 Link to this heading # The goal of internationalization and localization is to allow a single Web application to offer its content in languages and formats…","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>The goal of internationalization and localization is to allow a single Web\napplication to offer its content in languages and formats tailored to the\naudience.</p>\n<p>Django has full support for <a class=\"reference internal\" href=\"/zh-hans/2.1/topics/i18n/translation/\"><span class=\"doc\">translation of text</span></a>, <a class=\"reference internal\" href=\"/zh-hans/2.1/topics/i18n/formatting/\"><span class=\"doc\">formatting of dates, times and numbers</span></a>, and <a class=\"reference internal\" href=\"/zh-hans/2.1/topics/i18n/timezones/\"><span class=\"doc\">time zones</span></a>.</p>\n<p>Essentially, Django does two things:</p>\n<ul class=\"simple\">\n<li><p>It allows developers and template authors to specify which parts of their apps\nshould be translated or formatted for local languages and cultures.</p></li>\n<li><p>It uses these hooks to localize Web apps for particular users according to\ntheir preferences.</p></li>\n</ul>\n<p>Obviously, translation depends on the target language, and formatting usually\ndepends on the target country. This information is provided by browsers in\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Language</span></code> header. However, the time zone isn't readily available.</p>\n</section>\n<section id=\"definitions\">\n<h2>Definitions<a class=\"heading-anchor\" href=\"#definitions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The words &quot;internationalization&quot; and &quot;localization&quot; often cause confusion;\nhere's a simplified definition:</p>\n<dl class=\"simple glossary\">\n<dt id=\"term-internationalization\">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\">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.1/ref/settings/#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code></a> and\n<a class=\"reference internal\" href=\"/zh-hans/2.1/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span></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\"><span class=\"pre\">ll</span></code> or a\ncombined language and country specification of the form <code class=\"docutils literal notranslate\"><span class=\"pre\">ll_CC</span></code>.\nExamples: <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>. The language part is\nalways in lower case and the country part in upper case. The separator\nis an 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\"><span class=\"pre\">Accept-Language</span></code> HTTP header using this\nformat. Examples: <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>. Language codes\nare generally represented in lower-case, but the HTTP <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Language</span></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\"><span class=\"pre\">.po</span></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":"Definitions","anchor":"definitions","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Using Django","url":"/zh-hans/2.1/topics/"}],"prev":{"docname":"topics/email","title":"Sending email","url":"/zh-hans/2.1/topics/email/"},"next":{"docname":"topics/i18n/translation","title":"Translation","url":"/zh-hans/2.1/topics/i18n/translation/"},"formats":{"html":"/zh-hans/2.1/topics/i18n/","markdown":"/zh-hans/2.1/topics/i18n.md","json":"/zh-hans/2.1/topics/i18n.json"},"source":"https://github.com/django/django/blob/stable/2.1.x/docs/topics/i18n/index.txt","official":"https://docs.djangoproject.com/zh-hans/2.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"]}