{"title":"번역","version":"6.0","locale":"ko","docname":"topics/i18n/translation","url":"/ko/6.0/topics/i18n/translation/","canonical":"https://djangodocs.dev/ko/6.0/topics/i18n/translation/","summary":"개요 Link to this heading # Django 프로젝트를 번역가능하게 하기 위해, 사용자는 파이선 코드와 템플릿에 최소한의 훅(hook)을 추가해야 한다. 이 훅은 :term: ` 번역 문자열 <translation string>`이라고 한다. 이 문자열은 Django에 다음과…","html":"<h1>번역<a class=\"heading-anchor\" href=\"#translation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\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>Django 프로젝트를 번역가능하게 하기 위해, 사용자는 파이선 코드와 템플릿에 최소한의 훅(hook)을 추가해야 한다. 이 훅은 :term:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>번역 문자열 &lt;translation string&gt;`이라고 한다. 이 문자열은 Django에 다음과 같은 메시지를 전달한다: “이 텍스트는 가능하다면 최종 사용자의 언어로 번역되어야 한다.” 번역 가능한 문자열을 표시하는 것은 사용자의 책임이다. 시스템은 오직 알고 있는 문자열만을 번역할 수 있기 때문이다.</p>\n<p>이때 Django는 번역 문자열을 :term:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>메시지 파일`로 추출하는 유틸리티를 제공한다. 이 파일은 번역기가 대상 언어로 된 번역 문자열을 쉽게 제공할 수 있게 한다. 번역기가 메시지 파일을 기입하면, 그것은 컴파일되어야 한다. 이 과정은 GNU gettext 툴세트를 통해 이루어진다.</p>\n<p>Once this is done, Django takes care of translating web apps on the fly in each\navailable language, according to users’ language preferences.</p>\n<p>Django의 국제화 훅은 켜져 있는 것이 디폴트이며, 이는 프레임워크의 특정 장소에 i18n과 관련된 오버헤드가 있음을 의미한다. 만일 국제화 기능을 사용하지 않는다면, 2초 정도를 할애하여 설정 파일에서 :setting:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>USE_I18N = False &lt;USE_I18N&gt;`로 세팅하면 된다. 그러면 Django는 국제화 기능을 로드하지 않도록 몇 가지 최적화 작업을 수행한다.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>Make sure you’ve activated translation for your project (the fastest way is\nto check if <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> includes\n<a class=\"reference internal\" href=\"/ko/6.0/ref/middleware/#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-mod docutils literal notranslate\">django.middleware.locale.LocaleMiddleware</code></a>). If you haven’t yet,\nsee <a class=\"reference internal\" href=\"#how-django-discovers-language-preference\"><span class=\"std std-ref\">How Django discovers language preference</span></a>.</p>\n</aside>\n</section>\n<section id=\"internationalization-in-python-code\">\n<h2>Internationalization: in Python code<a class=\"heading-anchor\" href=\"#internationalization-in-python-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"standard-translation\">\n<h3>Standard translation<a class=\"heading-anchor\" href=\"#standard-translation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Specify a translation string by using the function\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\">gettext()</code></a>. It’s convention to import this\nas a shorter alias, <code class=\"docutils literal notranslate\">_</code>, to save typing.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>Python’s standard library <code class=\"docutils literal notranslate\">gettext</code> module installs <code class=\"docutils literal notranslate\">_()</code> into the\nglobal namespace, as an alias for <code class=\"docutils literal notranslate\">gettext()</code>. In Django, we have chosen\nnot to follow this practice, for a couple of reasons:</p>\n<ol class=\"arabic simple\">\n<li><p>Sometimes, you should use <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\">gettext_lazy()</code></a>\nas the default translation method for a particular file. Without <code class=\"docutils literal notranslate\">_()</code>\nin the global namespace, the developer has to think about which is the\nmost appropriate translation function.</p></li>\n<li><p>The underscore character (<code class=\"docutils literal notranslate\">_</code>) is used to represent “the previous\nresult” in Python’s interactive shell and doctest tests. Installing a\nglobal <code class=\"docutils literal notranslate\">_()</code> function causes interference. Explicitly importing\n<code class=\"docutils literal notranslate\">gettext()</code> as <code class=\"docutils literal notranslate\">_()</code> avoids this problem.</p></li>\n</ol>\n</aside>\n<aside class=\"admonition-what-functions-may-be-aliased-as admonition\" role=\"note\">\n<p class=\"admonition-title\">What functions may be aliased as <code class=\"docutils literal notranslate\">_</code>?</p>\n<p>Because of how <code class=\"docutils literal notranslate\">xgettext</code> (used by <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a>) works, only\nfunctions that take a single string argument can be imported as <code class=\"docutils literal notranslate\">_</code>:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\">gettext()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\">gettext_lazy()</code></a></p></li>\n</ul>\n</aside>\n<p>In this example, the text <code class=\"docutils literal notranslate\">&quot;Welcome to my site.&quot;</code> is marked as a translation\nstring:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext <span class=\"k\">as</span> _\n\n\n<span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    output <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome to my site.&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>output<span class=\"p\">)</span>\n</code></pre></div>\n<p>You could code this without using the alias. This example is identical to the\nprevious one:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext\n\n\n<span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    output <span class=\"o\">=</span> gettext<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome to my site.&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>output<span class=\"p\">)</span>\n</code></pre></div>\n<p>Translation works on computed values. This example is identical to the previous\ntwo:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    words <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;Welcome&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;to&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;my&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;site.&quot;</span><span class=\"p\">]</span>\n    output <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot; &quot;</span><span class=\"o\">.</span>join<span class=\"p\">(</span>words<span class=\"p\">))</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>output<span class=\"p\">)</span>\n</code></pre></div>\n<p>Translation works on variables. Again, here’s an identical example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    sentence <span class=\"o\">=</span> <span class=\"s2\">&quot;Welcome to my site.&quot;</span>\n    output <span class=\"o\">=</span> _<span class=\"p\">(</span>sentence<span class=\"p\">)</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>output<span class=\"p\">)</span>\n</code></pre></div>\n<p>(The caveat with using variables or computed values, as in the previous two\nexamples, is that Django’s translation-string-detecting utility,\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a>, won’t be able to find\nthese strings. More on <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> later.)</p>\n<p>The strings you pass to <code class=\"docutils literal notranslate\">_()</code> or <code class=\"docutils literal notranslate\">gettext()</code> can take placeholders,\nspecified with Python’s standard named-string interpolation syntax. Example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">,</span> m<span class=\"p\">,</span> d<span class=\"p\">):</span>\n    output <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;Today is </span><span class=\"si\">%(month)s</span><span class=\"s2\"> </span><span class=\"si\">%(day)s</span><span class=\"s2\">.&quot;</span><span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span><span class=\"s2\">&quot;month&quot;</span><span class=\"p\">:</span> m<span class=\"p\">,</span> <span class=\"s2\">&quot;day&quot;</span><span class=\"p\">:</span> d<span class=\"p\">}</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>output<span class=\"p\">)</span>\n</code></pre></div>\n<p>This technique lets language-specific translations reorder the placeholder\ntext. For example, an English translation may be <code class=\"docutils literal notranslate\">&quot;Today is November 26.&quot;</code>,\nwhile a Spanish translation may be <code class=\"docutils literal notranslate\">&quot;Hoy es 26 de noviembre.&quot;</code> – with the\nmonth and the day placeholders swapped.</p>\n<p>For this reason, you should use named-string interpolation (e.g., <code class=\"docutils literal notranslate\">%(day)s</code>)\ninstead of positional interpolation (e.g., <code class=\"docutils literal notranslate\">%s</code> or <code class=\"docutils literal notranslate\">%d</code>) whenever you\nhave more than a single parameter. If you used positional interpolation,\ntranslations wouldn’t be able to reorder placeholder text.</p>\n<p>Since string extraction is done by the <code class=\"docutils literal notranslate\">xgettext</code> command, only syntaxes\nsupported by <code class=\"docutils literal notranslate\">gettext</code> are supported by Django. Python <a class=\"reference external\" href=\"https://docs.python.org/3/reference/lexical_analysis.html#f-strings\" title=\"(Python v3.14에서)\"><span class=\"xref std std-ref\">f-strings</span></a> cannot be used directly with <code class=\"docutils literal notranslate\">gettext</code> functions because\nf-string expressions are evaluated before they reach <code class=\"docutils literal notranslate\">gettext</code>. This means\n<code class=\"docutils literal notranslate\">_(f&quot;Welcome {name}&quot;)</code> will not work as expected, as the variable is\nsubstituted before translation occurs. Instead, use named-string\ninterpolation:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"c1\"># Good</span>\n_<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome </span><span class=\"si\">%(name)s</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span><span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> name<span class=\"p\">}</span>\n\n<span class=\"c1\"># Good</span>\n_<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome </span><span class=\"si\">{name}</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span><span class=\"o\">.</span>format<span class=\"p\">(</span>name<span class=\"o\">=</span>name<span class=\"p\">)</span>\n\n<span class=\"c1\"># Bad</span>\n_<span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s2\">&quot;Welcome </span><span class=\"si\">{</span>name<span class=\"si\">}</span><span class=\"s2\">&quot;</span><span class=\"p\">)</span>  <span class=\"c1\"># f-string evaluated before translation.</span>\n</code></pre></div>\n<p>JavaScript template strings need <code class=\"docutils literal notranslate\">gettext</code> 0.21+.</p>\n</section>\n<section id=\"comments-for-translators\">\n<span id=\"translator-comments\"></span><h3>Comments for translators<a class=\"heading-anchor\" href=\"#comments-for-translators\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you would like to give translators hints about a translatable string, you\ncan add a comment prefixed with the <code class=\"docutils literal notranslate\">Translators</code> keyword on the line\npreceding the string, e.g.:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"c1\"># Translators: This message appears on the home page only</span>\n    output <span class=\"o\">=</span> gettext<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome to my site.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>The comment will then appear in the resulting <code class=\"docutils literal notranslate\">.po</code> file associated with the\ntranslatable construct located below it and should also be displayed by most\ntranslation tools.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>Just for completeness, this is the corresponding fragment of the\nresulting <code class=\"docutils literal notranslate\">.po</code> file:</p>\n<div class=\"code-block\" data-language=\"po\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Po</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Po code\"><code><span class=\"c1\">#. Translators: This message appears on the home page only</span>\n<span class=\"c1\"># path/to/python/file.py:123</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;Welcome to my site.&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n</code></pre></div>\n</aside>\n<p>This also works in templates. See <a class=\"reference internal\" href=\"#translator-comments-in-templates\"><span class=\"std std-ref\">Comments for translators in templates</span></a> for\nmore details.</p>\n</section>\n<section id=\"marking-strings-as-no-op\">\n<h3>Marking strings as no-op<a class=\"heading-anchor\" href=\"#marking-strings-as-no-op\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Use the function <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_noop\" title=\"django.utils.translation.gettext_noop\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.gettext_noop()</code></a> to mark a\nstring as a translation string without translating it. The string is later\ntranslated from a variable.</p>\n<p>Use this if you have constant strings that should be stored in the source\nlanguage because they are exchanged over systems or users – such as strings\nin a database – but should be translated at the last possible point in time,\nsuch as when the string is presented to the user.</p>\n</section>\n<section id=\"pluralization\">\n<h3>Pluralization<a class=\"heading-anchor\" href=\"#pluralization\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Use the function <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.ngettext\" title=\"django.utils.translation.ngettext\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.ngettext()</code></a> to specify\npluralized messages.</p>\n<p><code class=\"docutils literal notranslate\">ngettext()</code> takes three arguments: the singular translation string, the\nplural translation string and the number of objects.</p>\n<p>This function is useful when you need your Django application to be localizable\nto languages where the number and complexity of <a class=\"reference external\" href=\"https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms\">plural forms</a> is\ngreater than the two forms used in English (‘object’ for the singular and\n‘objects’ for all the cases where <code class=\"docutils literal notranslate\">count</code> is different from one, irrespective\nof its value.)</p>\n<p>예시:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> ngettext\n\n\n<span class=\"k\">def</span> <span class=\"nf\">hello_world</span><span class=\"p\">(</span>request<span class=\"p\">,</span> count<span class=\"p\">):</span>\n    page <span class=\"o\">=</span> ngettext<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;there is </span><span class=\"si\">%(count)d</span><span class=\"s2\"> object&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;there are </span><span class=\"si\">%(count)d</span><span class=\"s2\"> objects&quot;</span><span class=\"p\">,</span>\n        count<span class=\"p\">,</span>\n    <span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;count&quot;</span><span class=\"p\">:</span> count<span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span>page<span class=\"p\">)</span>\n</code></pre></div>\n<p>In this example the number of objects is passed to the translation\nlanguages as the <code class=\"docutils literal notranslate\">count</code> variable.</p>\n<p>Note that pluralization is complicated and works differently in each language.\nComparing <code class=\"docutils literal notranslate\">count</code> to 1 isn’t always the correct rule. This code looks\nsophisticated, but will produce incorrect results for some languages:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> ngettext\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.models</span> <span class=\"kn\">import</span> Report\n\ncount <span class=\"o\">=</span> Report<span class=\"o\">.</span>objects<span class=\"o\">.</span>count<span class=\"p\">()</span>\n<span class=\"k\">if</span> count <span class=\"o\">==</span> <span class=\"mi\">1</span><span class=\"p\">:</span>\n    name <span class=\"o\">=</span> Report<span class=\"o\">.</span>_meta<span class=\"o\">.</span>verbose_name\n<span class=\"k\">else</span><span class=\"p\">:</span>\n    name <span class=\"o\">=</span> Report<span class=\"o\">.</span>_meta<span class=\"o\">.</span>verbose_name_plural\n\ntext <span class=\"o\">=</span> ngettext<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;There is </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(name)s</span><span class=\"s2\"> available.&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;There are </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(name)s</span><span class=\"s2\"> available.&quot;</span><span class=\"p\">,</span>\n    count<span class=\"p\">,</span>\n<span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span><span class=\"s2\">&quot;count&quot;</span><span class=\"p\">:</span> count<span class=\"p\">,</span> <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> name<span class=\"p\">}</span>\n</code></pre></div>\n<p>Don’t try to implement your own singular-or-plural logic; it won’t be correct.\nIn a case like this, consider something like the following:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>text <span class=\"o\">=</span> ngettext<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;There is </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(name)s</span><span class=\"s2\"> object available.&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;There are </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(name)s</span><span class=\"s2\"> objects available.&quot;</span><span class=\"p\">,</span>\n    count<span class=\"p\">,</span>\n<span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;count&quot;</span><span class=\"p\">:</span> count<span class=\"p\">,</span>\n    <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> Report<span class=\"o\">.</span>_meta<span class=\"o\">.</span>verbose_name<span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" id=\"pluralization-var-notes\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>When using <code class=\"docutils literal notranslate\">ngettext()</code>, make sure you use a single name for every\nextrapolated variable included in the literal. In the examples above, note\nhow we used the <code class=\"docutils literal notranslate\">name</code> Python variable in both translation strings. This\nexample, besides being incorrect in some languages as noted above, would\nfail:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>text <span class=\"o\">=</span> ngettext<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;There is </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(name)s</span><span class=\"s2\"> available.&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;There are </span><span class=\"si\">%(count)d</span><span class=\"s2\"> </span><span class=\"si\">%(plural_name)s</span><span class=\"s2\"> available.&quot;</span><span class=\"p\">,</span>\n    count<span class=\"p\">,</span>\n<span class=\"p\">)</span> <span class=\"o\">%</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;count&quot;</span><span class=\"p\">:</span> Report<span class=\"o\">.</span>objects<span class=\"o\">.</span>count<span class=\"p\">(),</span>\n    <span class=\"s2\">&quot;name&quot;</span><span class=\"p\">:</span> Report<span class=\"o\">.</span>_meta<span class=\"o\">.</span>verbose_name<span class=\"p\">,</span>\n    <span class=\"s2\">&quot;plural_name&quot;</span><span class=\"p\">:</span> Report<span class=\"o\">.</span>_meta<span class=\"o\">.</span>verbose_name_plural<span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>You would get an error when running <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin\ncompilemessages</code></a>:</p>\n<div class=\"code-block\" data-language=\"pytb\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Pytb</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Pytb code\"><code><span class=\"x\">a format specification for argument &#39;name&#39;, as in &#39;msgstr[0]&#39;, doesn&#39;t exist in &#39;msgid&#39;</span>\n</code></pre></div>\n</aside>\n</section>\n<section id=\"contextual-markers\">\n<span id=\"id1\"></span><h3>Contextual markers<a class=\"heading-anchor\" href=\"#contextual-markers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Sometimes words have several meanings, such as <code class=\"docutils literal notranslate\">&quot;May&quot;</code> in English, which\nrefers to a month name and to a verb. To enable translators to translate\nthese words correctly in different contexts, you can use the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.pgettext\" title=\"django.utils.translation.pgettext\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.pgettext()</code></a> function, or the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.npgettext\" title=\"django.utils.translation.npgettext\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.npgettext()</code></a> function if the string needs\npluralization. Both take a context string as the first variable.</p>\n<p>In the resulting <code class=\"docutils literal notranslate\">.po</code> file, the string will then appear as often as there\nare different contextual markers for the same string (the context will appear\non the <code class=\"docutils literal notranslate\">msgctxt</code> line), allowing the translator to give a different\ntranslation for each of them.</p>\n<p>예시:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> pgettext\n\nmonth <span class=\"o\">=</span> pgettext<span class=\"p\">(</span><span class=\"s2\">&quot;month name&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;May&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>or:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> pgettext_lazy\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>\n        help_text<span class=\"o\">=</span>pgettext_lazy<span class=\"p\">(</span><span class=\"s2\">&quot;help text for MyThing model&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;This is the help text&quot;</span><span class=\"p\">)</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<p>will appear in the <code class=\"docutils literal notranslate\">.po</code> file as:</p>\n<div class=\"code-block\" data-language=\"po\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Po</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Po code\"><code><span class=\"nv\">msgctxt</span> <span class=\"s\">&quot;month name&quot;</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;May&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n</code></pre></div>\n<p>Contextual markers are also supported by the <a class=\"reference internal\" href=\"#std-templatetag-translate\"><code class=\"xref std std-ttag docutils literal notranslate\">translate</code></a> and\n<a class=\"reference internal\" href=\"#std-templatetag-blocktranslate\"><code class=\"xref std std-ttag docutils literal notranslate\">blocktranslate</code></a> template tags.</p>\n</section>\n<section id=\"lazy-translation\">\n<span id=\"lazy-translations\"></span><h3>Lazy translation<a class=\"heading-anchor\" href=\"#lazy-translation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Use the lazy versions of translation functions in\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#module-django.utils.translation\" title=\"django.utils.translation: Internationalization support.\"><code class=\"xref py py-mod docutils literal notranslate\">django.utils.translation</code></a> (easily recognizable by the <code class=\"docutils literal notranslate\">lazy</code> suffix in\ntheir names) to translate strings lazily – when the value is accessed rather\nthan when they’re called.</p>\n<p>These functions store a lazy reference to the string – not the actual\ntranslation. The translation itself will be done when the string is used in a\nstring context, such as in template rendering.</p>\n<p>This is essential when calls to these functions are located in code paths that\nare executed at module load time.</p>\n<p>This is something that can easily happen when defining models, forms and\nmodel forms, because Django implements these such that their fields are\nactually class-level attributes. For that reason, make sure to use lazy\ntranslations in the following cases:</p>\n<section id=\"model-fields-and-relationships-verbose-name-and-help-text-option-values\">\n<h4>Model fields and relationships <code class=\"docutils literal notranslate\">verbose_name</code> and <code class=\"docutils literal notranslate\">help_text</code> option values<a class=\"heading-anchor\" href=\"#model-fields-and-relationships-verbose-name-and-help-text-option-values\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>For example, to translate the help text of the <em>name</em> field in the following\nmodel, do the following:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>help_text<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;This is the help text&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n<p>You can mark names of <a class=\"reference internal\" href=\"/ko/6.0/ref/models/fields/#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a>,\n<a class=\"reference internal\" href=\"/ko/6.0/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> or\n<a class=\"reference internal\" href=\"/ko/6.0/ref/models/fields/#django.db.models.OneToOneField\" title=\"django.db.models.OneToOneField\"><code class=\"xref py py-class docutils literal notranslate\">OneToOneField</code></a> relationship as translatable by using\ntheir <a class=\"reference internal\" href=\"/ko/6.0/ref/models/options/#django.db.models.Options.verbose_name\" title=\"django.db.models.Options.verbose_name\"><code class=\"xref py py-attr docutils literal notranslate\">verbose_name</code></a> options:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    kind <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        ThingKind<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n        related_name<span class=\"o\">=</span><span class=\"s2\">&quot;kinds&quot;</span><span class=\"p\">,</span>\n        verbose_name<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;kind&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<p>Just like you would do in <a class=\"reference internal\" href=\"/ko/6.0/ref/models/options/#django.db.models.Options.verbose_name\" title=\"django.db.models.Options.verbose_name\"><code class=\"xref py py-attr docutils literal notranslate\">verbose_name</code></a> you\nshould provide a lowercase verbose name text for the relation as Django will\nautomatically titlecase it when required.</p>\n</section>\n<section id=\"model-verbose-names-values\">\n<h4>Model verbose names values<a class=\"heading-anchor\" href=\"#model-verbose-names-values\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>It is recommended to always provide explicit\n<a class=\"reference internal\" href=\"/ko/6.0/ref/models/options/#django.db.models.Options.verbose_name\" title=\"django.db.models.Options.verbose_name\"><code class=\"xref py py-attr docutils literal notranslate\">verbose_name</code></a> and\n<a class=\"reference internal\" href=\"/ko/6.0/ref/models/options/#django.db.models.Options.verbose_name_plural\" title=\"django.db.models.Options.verbose_name_plural\"><code class=\"xref py py-attr docutils literal notranslate\">verbose_name_plural</code></a> options rather than\nrelying on the fallback English-centric and somewhat naïve determination of\nverbose names Django performs by looking at the model’s class name:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;name&quot;</span><span class=\"p\">),</span> help_text<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;This is the help text&quot;</span><span class=\"p\">))</span>\n\n    <span class=\"k\">class</span> <span class=\"nc\">Meta</span><span class=\"p\">:</span>\n        verbose_name <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;my thing&quot;</span><span class=\"p\">)</span>\n        verbose_name_plural <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;my things&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"model-methods-description-argument-to-the-display-decorator\">\n<h4>Model methods <code class=\"docutils literal notranslate\">description</code> argument to the <code class=\"docutils literal notranslate\">&#64;display</code> decorator<a class=\"heading-anchor\" href=\"#model-methods-description-argument-to-the-display-decorator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>For model methods, you can provide translations to Django and the admin site\nwith the <code class=\"docutils literal notranslate\">description</code> argument to the <a class=\"reference internal\" href=\"/ko/6.0/ref/contrib/admin/#django.contrib.admin.display\" title=\"django.contrib.admin.display\"><code class=\"xref py py-func docutils literal notranslate\">display()</code></a>\ndecorator:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n<span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    kind <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>\n        ThingKind<span class=\"p\">,</span>\n        on_delete<span class=\"o\">=</span>models<span class=\"o\">.</span>CASCADE<span class=\"p\">,</span>\n        related_name<span class=\"o\">=</span><span class=\"s2\">&quot;kinds&quot;</span><span class=\"p\">,</span>\n        verbose_name<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;kind&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">)</span>\n\n    <span class=\"nd\">@admin</span><span class=\"o\">.</span>display<span class=\"p\">(</span>description<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;Is it a mouse?&quot;</span><span class=\"p\">))</span>\n    <span class=\"k\">def</span> <span class=\"nf\">is_mouse</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span>kind<span class=\"o\">.</span>type <span class=\"o\">==</span> MOUSE_TYPE\n</code></pre></div>\n</section>\n</section>\n<section id=\"working-with-lazy-translation-objects\">\n<h3>Working with lazy translation objects<a class=\"heading-anchor\" href=\"#working-with-lazy-translation-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The result of a <code class=\"docutils literal notranslate\">gettext_lazy()</code> call can be used wherever you would use a\nstring (a <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str\" title=\"(Python v3.14에서)\"><code class=\"xref py py-class docutils literal notranslate\">str</code></a> object) in other Django code, but it may not work with\narbitrary Python code. For example, the following won’t work because the\n<a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/requests/\">requests</a> library doesn’t handle <code class=\"docutils literal notranslate\">gettext_lazy</code> objects:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>body <span class=\"o\">=</span> gettext_lazy<span class=\"p\">(</span><span class=\"s2\">&quot;I </span><span class=\"se\">\\u2764</span><span class=\"s2\"> Django&quot;</span><span class=\"p\">)</span>  <span class=\"c1\"># (Unicode :heart:)</span>\nrequests<span class=\"o\">.</span>post<span class=\"p\">(</span><span class=\"s2\">&quot;https://example.com/send&quot;</span><span class=\"p\">,</span> data<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;body&quot;</span><span class=\"p\">:</span> body<span class=\"p\">})</span>\n</code></pre></div>\n<p>You can avoid such problems by casting <code class=\"docutils literal notranslate\">gettext_lazy()</code> objects to text\nstrings before passing them to non-Django code:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>requests<span class=\"o\">.</span>post<span class=\"p\">(</span><span class=\"s2\">&quot;https://example.com/send&quot;</span><span class=\"p\">,</span> data<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;body&quot;</span><span class=\"p\">:</span> <span class=\"nb\">str</span><span class=\"p\">(</span>body<span class=\"p\">)})</span>\n</code></pre></div>\n<p>If you don’t like the long <code class=\"docutils literal notranslate\">gettext_lazy</code> name, you can alias it as <code class=\"docutils literal notranslate\">_</code>\n(underscore), like so:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.db</span> <span class=\"kn\">import</span> models\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyThing</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    name <span class=\"o\">=</span> models<span class=\"o\">.</span>CharField<span class=\"p\">(</span>help_text<span class=\"o\">=</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;This is the help text&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n<p>Using <code class=\"docutils literal notranslate\">gettext_lazy()</code> and <code class=\"docutils literal notranslate\">ngettext_lazy()</code> to mark strings in models\nand utility functions is a common operation. When you’re working with these\nobjects elsewhere in your code, you should ensure that you don’t accidentally\nconvert them to strings, because they should be converted as late as possible\n(so that the correct locale is in effect). This necessitates the use of the\nhelper function described next.</p>\n<section id=\"lazy-translations-and-plural\">\n<span id=\"lazy-plural-translations\"></span><h4>Lazy translations and plural<a class=\"heading-anchor\" href=\"#lazy-translations-and-plural\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>When using lazy translation for a plural string (<code class=\"docutils literal notranslate\">n[p]gettext_lazy</code>), you\ngenerally don’t know the <code class=\"docutils literal notranslate\">number</code> argument at the time of the string\ndefinition. Therefore, you are authorized to pass a key name instead of an\ninteger as the <code class=\"docutils literal notranslate\">number</code> argument. Then <code class=\"docutils literal notranslate\">number</code> will be looked up in the\ndictionary under that key during string interpolation. Here’s example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django</span> <span class=\"kn\">import</span> forms\n<span class=\"kn\">from</span> <span class=\"nn\">django.core.exceptions</span> <span class=\"kn\">import</span> ValidationError\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> ngettext_lazy\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyForm</span><span class=\"p\">(</span>forms<span class=\"o\">.</span>Form<span class=\"p\">):</span>\n    error_message <span class=\"o\">=</span> ngettext_lazy<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;You only provided </span><span class=\"si\">%(num)d</span><span class=\"s2\"> argument&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;You only provided </span><span class=\"si\">%(num)d</span><span class=\"s2\"> arguments&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;num&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">clean</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"k\">if</span> error<span class=\"p\">:</span>\n            <span class=\"k\">raise</span> ValidationError<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>error_message <span class=\"o\">%</span> <span class=\"p\">{</span><span class=\"s2\">&quot;num&quot;</span><span class=\"p\">:</span> number<span class=\"p\">})</span>\n</code></pre></div>\n<p>If the string contains exactly one unnamed placeholder, you can interpolate\ndirectly with the <code class=\"docutils literal notranslate\">number</code> argument:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">MyForm</span><span class=\"p\">(</span>forms<span class=\"o\">.</span>Form<span class=\"p\">):</span>\n    error_message <span class=\"o\">=</span> ngettext_lazy<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;You provided </span><span class=\"si\">%d</span><span class=\"s2\"> argument&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;You provided </span><span class=\"si\">%d</span><span class=\"s2\"> arguments&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">clean</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"k\">if</span> error<span class=\"p\">:</span>\n            <span class=\"k\">raise</span> ValidationError<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>error_message <span class=\"o\">%</span> number<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"formatting-strings-format-lazy\">\n<h4>Formatting strings: <code class=\"docutils literal notranslate\">format_lazy()</code><a class=\"heading-anchor\" href=\"#formatting-strings-format-lazy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Python’s <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str.format\" title=\"(Python v3.14에서)\"><code class=\"xref py py-meth docutils literal notranslate\">str.format()</code></a> method will not work when either the\n<code class=\"docutils literal notranslate\">format_string</code> or any of the arguments to <a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str.format\" title=\"(Python v3.14에서)\"><code class=\"xref py py-meth docutils literal notranslate\">str.format()</code></a>\ncontains lazy translation objects. Instead, you can use\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.text.format_lazy\" title=\"django.utils.text.format_lazy\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.text.format_lazy()</code></a>, which creates a lazy object\nthat runs the <code class=\"docutils literal notranslate\">str.format()</code> method only when the result is included\nin a string. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.text</span> <span class=\"kn\">import</span> format_lazy\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy\n\n<span class=\"o\">...</span>\nname <span class=\"o\">=</span> gettext_lazy<span class=\"p\">(</span><span class=\"s2\">&quot;John Lennon&quot;</span><span class=\"p\">)</span>\ninstrument <span class=\"o\">=</span> gettext_lazy<span class=\"p\">(</span><span class=\"s2\">&quot;guitar&quot;</span><span class=\"p\">)</span>\nresult <span class=\"o\">=</span> format_lazy<span class=\"p\">(</span><span class=\"s2\">&quot;</span><span class=\"si\">{name}</span><span class=\"s2\">: </span><span class=\"si\">{instrument}</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span> name<span class=\"o\">=</span>name<span class=\"p\">,</span> instrument<span class=\"o\">=</span>instrument<span class=\"p\">)</span>\n</code></pre></div>\n<p>In this case, the lazy translations in <code class=\"docutils literal notranslate\">result</code> will only be converted to\nstrings when <code class=\"docutils literal notranslate\">result</code> itself is used in a string (usually at template\nrendering time).</p>\n</section>\n<section id=\"other-uses-of-lazy-in-delayed-translations\">\n<h4>Other uses of lazy in delayed translations<a class=\"heading-anchor\" href=\"#other-uses-of-lazy-in-delayed-translations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>For any other case where you would like to delay the translation, but have to\npass the translatable string as argument to another function, you can wrap\nthis function inside a lazy call yourself. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.functional</span> <span class=\"kn\">import</span> lazy\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n\n<span class=\"k\">def</span> <span class=\"nf\">to_lower</span><span class=\"p\">(</span>string<span class=\"p\">):</span>\n    <span class=\"k\">return</span> string<span class=\"o\">.</span>lower<span class=\"p\">()</span>\n\n\nto_lower_lazy <span class=\"o\">=</span> lazy<span class=\"p\">(</span>to_lower<span class=\"p\">,</span> <span class=\"nb\">str</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>And then later:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>lazy_string <span class=\"o\">=</span> to_lower_lazy<span class=\"p\">(</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;My STRING!&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"localized-names-of-languages\">\n<h3>Localized names of languages<a class=\"heading-anchor\" href=\"#localized-names-of-languages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.utils.translation.get_language_info\">\n<span class=\"sig-name descname\">get_language_info</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">lang_code</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.utils.translation.get_language_info\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The <code class=\"docutils literal notranslate\">get_language_info()</code> function provides detailed information about\nlanguages:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> activate<span class=\"p\">,</span> get_language_info\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;fr&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>li <span class=\"o\">=</span> get_language_info<span class=\"p\">(</span><span class=\"s2\">&quot;de&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">print</span><span class=\"p\">(</span>li<span class=\"p\">[</span><span class=\"s2\">&quot;name&quot;</span><span class=\"p\">],</span> li<span class=\"p\">[</span><span class=\"s2\">&quot;name_local&quot;</span><span class=\"p\">],</span> li<span class=\"p\">[</span><span class=\"s2\">&quot;name_translated&quot;</span><span class=\"p\">],</span> li<span class=\"p\">[</span><span class=\"s2\">&quot;bidi&quot;</span><span class=\"p\">])</span>\n<span class=\"go\">German Deutsch Allemand False</span>\n</code></pre></div>\n<p>The <code class=\"docutils literal notranslate\">name</code>, <code class=\"docutils literal notranslate\">name_local</code>, and <code class=\"docutils literal notranslate\">name_translated</code> attributes of the\ndictionary contain the name of the language in English, in the language\nitself, and in your current active language respectively. The <code class=\"docutils literal notranslate\">bidi</code>\nattribute is True only for bi-directional languages.</p>\n<p>The source of the language information is the <code class=\"docutils literal notranslate\">django.conf.locale</code> module.\nSimilar access to this information is available for template code. See below.</p>\n</section>\n</section>\n<section id=\"internationalization-in-template-code\">\n<span id=\"specifying-translation-strings-in-template-code\"></span><h2>Internationalization: in template code<a class=\"heading-anchor\" href=\"#internationalization-in-template-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Translations in <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/language/\"><span class=\"doc\">Django templates</span></a> uses two\ntemplate tags and a slightly different syntax than in Python code. To give your\ntemplate access to these tags, put <code class=\"docutils literal notranslate\">{% load i18n %}</code> toward the top of your\ntemplate. As with all template tags, this tag needs to be loaded in all\ntemplates which use translations, even those templates that extend from other\ntemplates which have already loaded the <code class=\"docutils literal notranslate\">i18n</code> tag.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>Translated strings will not be escaped when rendered in a template.\nThis allows you to include HTML in translations, for example for emphasis,\nbut potentially dangerous characters (e.g. <code class=\"docutils literal notranslate\">&quot;</code>) will also be rendered\nunchanged.</p>\n</aside>\n<section id=\"translate-template-tag\">\n<span id=\"std-templatetag-translate\"></span><span id=\"std-templatetag-trans\"></span><h3><code class=\"docutils literal notranslate\">translate</code> template tag<a class=\"heading-anchor\" href=\"#translate-template-tag\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The <code class=\"docutils literal notranslate\">{% translate %}</code> template tag translates either a constant string\n(enclosed in single or double quotes) or variable content:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;This is the title.&quot;</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"nv\">myvar</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>If the <code class=\"docutils literal notranslate\">noop</code> option is present, variable lookup still takes place but the\ntranslation is skipped. This is useful when “stubbing out” content that will\nrequire translation in the future:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;myvar&quot;</span> <span class=\"nv\">noop</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>Internally, inline translations use a\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\">gettext()</code></a> call.</p>\n<p>In case a template var (<code class=\"docutils literal notranslate\">myvar</code> above) is passed to the tag, the tag will\nfirst resolve such variable to a string at run-time and then look up that\nstring in the message catalogs.</p>\n<p>It’s not possible to mix a template variable inside a string within\n<code class=\"docutils literal notranslate\">{% translate %}</code>. If your translations require strings with variables\n(placeholders), use <a class=\"reference internal\" href=\"#std-templatetag-blocktranslate\"><code class=\"xref std std-ttag docutils literal notranslate\">{% blocktranslate %}</code></a> instead.</p>\n<p>If you’d like to retrieve a translated string without displaying it, you can\nuse the following syntax:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;This is the title&quot;</span> <span class=\"k\">as</span> <span class=\"nv\">the_title</span> <span class=\"cp\">%}</span>\n\n<span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">the_title</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">meta</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;description&quot;</span> <span class=\"na\">content</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{{</span> <span class=\"nv\">the_title</span> <span class=\"cp\">}}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>In practice you’ll use this to get a string you can use in multiple places in a\ntemplate or so you can use the output as an argument for other template tags or\nfilters:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;starting point&quot;</span> <span class=\"k\">as</span> <span class=\"nv\">start</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;end point&quot;</span> <span class=\"k\">as</span> <span class=\"nv\">end</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;La Grande Boucle&quot;</span> <span class=\"k\">as</span> <span class=\"nv\">race</span> <span class=\"cp\">%}</span>\n\n<span class=\"p\">&lt;</span><span class=\"nt\">h1</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">&quot;/&quot;</span> <span class=\"na\">title</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"cp\">%}</span><span class=\"s\">Back to &#39;</span><span class=\"cp\">{{</span> <span class=\"nv\">race</span> <span class=\"cp\">}}</span><span class=\"s\">&#39; homepage</span><span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">race</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">h1</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n<span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">stage</span> <span class=\"k\">in</span> <span class=\"nv\">tour_stages</span> <span class=\"cp\">%}</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">cycle</span> <span class=\"nv\">start</span> <span class=\"nv\">end</span> <span class=\"cp\">%}</span>: <span class=\"cp\">{{</span> <span class=\"nv\">stage</span> <span class=\"cp\">}}{%</span> <span class=\"k\">if</span> <span class=\"nb\">forloop</span><span class=\"nv\">.counter</span><span class=\"o\">|</span><span class=\"nf\">divisibleby</span><span class=\"o\">:</span><span class=\"m\">2</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;</span><span class=\"nt\">br</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">else</span> <span class=\"cp\">%}</span>, <span class=\"cp\">{%</span> <span class=\"k\">endif</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">{% translate %}</code> also supports <a class=\"reference internal\" href=\"#contextual-markers\"><span class=\"std std-ref\">contextual markers</span></a>\nusing the <code class=\"docutils literal notranslate\">context</code> keyword:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;May&quot;</span> <span class=\"nv\">context</span> <span class=\"s2\">&quot;month name&quot;</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n</section>\n<section id=\"blocktranslate-template-tag\">\n<span id=\"std-templatetag-blocktranslate\"></span><span id=\"std-templatetag-blocktrans\"></span><h3><code class=\"docutils literal notranslate\">blocktranslate</code> template tag<a class=\"heading-anchor\" href=\"#blocktranslate-template-tag\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Contrarily to the <a class=\"reference internal\" href=\"#std-templatetag-translate\"><code class=\"xref std std-ttag docutils literal notranslate\">translate</code></a> tag, the <code class=\"docutils literal notranslate\">blocktranslate</code> tag allows you\nto mark complex sentences consisting of literals and variable content for\ntranslation by making use of placeholders:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"cp\">%}</span>This string will have <span class=\"cp\">{{</span> <span class=\"nv\">value</span> <span class=\"cp\">}}</span> inside.<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>To translate a template expression – say, accessing object attributes or\nusing template filters – you need to bind the expression to a local variable\nfor use within the translation block. Examples:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"k\">with</span> <span class=\"nv\">amount</span><span class=\"o\">=</span><span class=\"nv\">article.price</span> <span class=\"cp\">%}</span>\nThat will cost $ <span class=\"cp\">{{</span> <span class=\"nv\">amount</span> <span class=\"cp\">}}</span>.\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"k\">with</span> <span class=\"nv\">myvar</span><span class=\"o\">=</span><span class=\"nv\">value</span><span class=\"o\">|</span><span class=\"nf\">filter</span> <span class=\"cp\">%}</span>\nThis will have <span class=\"cp\">{{</span> <span class=\"nv\">myvar</span> <span class=\"cp\">}}</span> inside.\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>You can use multiple expressions inside a single <code class=\"docutils literal notranslate\">blocktranslate</code> tag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"k\">with</span> <span class=\"nv\">book_t</span><span class=\"o\">=</span><span class=\"nv\">book</span><span class=\"o\">|</span><span class=\"nf\">title</span> <span class=\"nv\">author_t</span><span class=\"o\">=</span><span class=\"nv\">author</span><span class=\"o\">|</span><span class=\"nf\">title</span> <span class=\"cp\">%}</span>\nThis is <span class=\"cp\">{{</span> <span class=\"nv\">book_t</span> <span class=\"cp\">}}</span> by <span class=\"cp\">{{</span> <span class=\"nv\">author_t</span> <span class=\"cp\">}}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>The previous more verbose format is still supported:\n<code class=\"docutils literal notranslate\">{% blocktranslate with book|title as book_t and author|title as author_t %}</code></p>\n</aside>\n<p>Other block tags (for example <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/builtins/#std-templatetag-for\"><code class=\"xref std std-ttag docutils literal notranslate\">{% for %}</code></a> or <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/builtins/#std-templatetag-if\"><code class=\"xref std std-ttag docutils literal notranslate\">{% if %}</code></a>)\nare not allowed inside a <code class=\"docutils literal notranslate\">blocktranslate</code> tag.</p>\n<p>If resolving one of the block arguments fails, <code class=\"docutils literal notranslate\">blocktranslate</code> will fall\nback to the default language by deactivating the currently active language\ntemporarily with the <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.deactivate_all\" title=\"django.utils.translation.deactivate_all\"><code class=\"xref py py-func docutils literal notranslate\">deactivate_all()</code></a>\nfunction.</p>\n<p>This tag also provides for pluralization. To use it:</p>\n<ul class=\"simple\">\n<li><p>Designate and bind a counter value with the name <code class=\"docutils literal notranslate\">count</code>. This value will\nbe the one used to select the right plural form.</p></li>\n<li><p>Specify both the singular and plural forms separating them with the\n<code class=\"docutils literal notranslate\">{% plural %}</code> tag within the <code class=\"docutils literal notranslate\">{% blocktranslate %}</code> and\n<code class=\"docutils literal notranslate\">{% endblocktranslate %}</code> tags.</p></li>\n</ul>\n<p>An example:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"nv\">count</span> <span class=\"nv\">counter</span><span class=\"o\">=</span><span class=\"nv\">list</span><span class=\"o\">|</span><span class=\"nf\">length</span> <span class=\"cp\">%}</span>\nThere is <span class=\"cp\">{{</span> <span class=\"nv\">counter</span> <span class=\"cp\">}}</span> <span class=\"cp\">{{</span> <span class=\"nv\">name</span> <span class=\"cp\">}}</span> object.\n<span class=\"cp\">{%</span> <span class=\"k\">plural</span> <span class=\"cp\">%}</span>\nThere are <span class=\"cp\">{{</span> <span class=\"nv\">counter</span> <span class=\"cp\">}}</span> <span class=\"cp\">{{</span> <span class=\"nv\">name</span> <span class=\"cp\">}}</span> objects.\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>A more complex example:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"k\">with</span> <span class=\"nv\">amount</span><span class=\"o\">=</span><span class=\"nv\">article.price</span> <span class=\"nv\">count</span> <span class=\"nv\">years</span><span class=\"o\">=</span><span class=\"nv\">i.length</span> <span class=\"cp\">%}</span>\nThat will cost $ <span class=\"cp\">{{</span> <span class=\"nv\">amount</span> <span class=\"cp\">}}</span> per year.\n<span class=\"cp\">{%</span> <span class=\"k\">plural</span> <span class=\"cp\">%}</span>\nThat will cost $ <span class=\"cp\">{{</span> <span class=\"nv\">amount</span> <span class=\"cp\">}}</span> per <span class=\"cp\">{{</span> <span class=\"nv\">years</span> <span class=\"cp\">}}</span> years.\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>When you use both the pluralization feature and bind values to local variables\nin addition to the counter value, keep in mind that the <code class=\"docutils literal notranslate\">blocktranslate</code>\nconstruct is internally converted to an <code class=\"docutils literal notranslate\">ngettext</code> call. This means the\nsame <a class=\"reference internal\" href=\"#pluralization-var-notes\"><span class=\"std std-ref\">notes regarding ngettext variables</span></a>\napply.</p>\n<p>Reverse URL lookups cannot be carried out within the <code class=\"docutils literal notranslate\">blocktranslate</code> and\nshould be retrieved (and stored) beforehand:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">url</span> <span class=\"s1\">&#39;path.to.view&#39;</span> <span class=\"nv\">arg</span> <span class=\"nv\">arg2</span> <span class=\"k\">as</span> <span class=\"nv\">the_url</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"cp\">%}</span>\nThis is a URL: <span class=\"cp\">{{</span> <span class=\"nv\">the_url</span> <span class=\"cp\">}}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>If you’d like to retrieve a translated string without displaying it, you can\nuse the following syntax:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"nv\">asvar</span> <span class=\"nv\">the_title</span> <span class=\"cp\">%}</span>The title is <span class=\"cp\">{{</span> <span class=\"nv\">title</span> <span class=\"cp\">}}</span>.<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">the_title</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">meta</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;description&quot;</span> <span class=\"na\">content</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{{</span> <span class=\"nv\">the_title</span> <span class=\"cp\">}}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>In practice you’ll use this to get a string you can use in multiple places in a\ntemplate or so you can use the output as an argument for other template tags or\nfilters.</p>\n<p><code class=\"docutils literal notranslate\">{% blocktranslate %}</code> also supports <a class=\"reference internal\" href=\"#contextual-markers\"><span class=\"std std-ref\">contextual\nmarkers</span></a> using the <code class=\"docutils literal notranslate\">context</code> keyword:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"k\">with</span> <span class=\"nv\">name</span><span class=\"o\">=</span><span class=\"nv\">user.username</span> <span class=\"nv\">context</span> <span class=\"s2\">&quot;greeting&quot;</span> <span class=\"cp\">%}</span>Hi <span class=\"cp\">{{</span> <span class=\"nv\">name</span> <span class=\"cp\">}}{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>Another feature <code class=\"docutils literal notranslate\">{% blocktranslate %}</code> supports is the <code class=\"docutils literal notranslate\">trimmed</code> option.\nThis option will remove newline characters from the beginning and the end of\nthe content of the <code class=\"docutils literal notranslate\">{% blocktranslate %}</code> tag, replace any whitespace at the\nbeginning and end of a line and merge all lines into one using a space\ncharacter to separate them. This is quite useful for indenting the content of a\n<code class=\"docutils literal notranslate\">{% blocktranslate %}</code> tag without having the indentation characters end up\nin the corresponding entry in the <code class=\"docutils literal notranslate\">.po</code> file, which makes the translation\nprocess easier.</p>\n<p>For instance, the following <code class=\"docutils literal notranslate\">{% blocktranslate %}</code> tag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"nv\">trimmed</span> <span class=\"cp\">%}</span>\n  First sentence.\n  Second paragraph.\n<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>will result in the entry <code class=\"docutils literal notranslate\">&quot;First sentence. Second paragraph.&quot;</code> in the <code class=\"docutils literal notranslate\">.po</code>\nfile, compared to <code class=\"docutils literal notranslate\">&quot;\\n&#160; First sentence.\\n&#160; Second paragraph.\\n&quot;</code>, if the\n<code class=\"docutils literal notranslate\">trimmed</code> option had not been specified.</p>\n</section>\n<section id=\"string-literals-passed-to-tags-and-filters\">\n<h3>String literals passed to tags and filters<a class=\"heading-anchor\" href=\"#string-literals-passed-to-tags-and-filters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can translate string literals passed as arguments to tags and filters\nby using the familiar <code class=\"docutils literal notranslate\">_()</code> syntax:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">some_tag</span> <span class=\"kp\">_</span><span class=\"o\">(</span><span class=\"s2\">&quot;Page not found&quot;</span><span class=\"o\">)</span> <span class=\"nv\">value</span><span class=\"o\">|</span><span class=\"nf\">yesno</span><span class=\"o\">:</span><span class=\"kp\">_</span><span class=\"o\">(</span><span class=\"s2\">&quot;yes,no&quot;</span><span class=\"o\">)</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>In this case, both the tag and the filter will see the translated string,\nso they don’t need to be aware of translations.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>In this example, the translation infrastructure will be passed the string\n<code class=\"docutils literal notranslate\">&quot;yes,no&quot;</code>, not the individual strings <code class=\"docutils literal notranslate\">&quot;yes&quot;</code> and <code class=\"docutils literal notranslate\">&quot;no&quot;</code>. The\ntranslated string will need to contain the comma so that the filter\nparsing code knows how to split up the arguments. For example, a German\ntranslator might translate the string <code class=\"docutils literal notranslate\">&quot;yes,no&quot;</code> as <code class=\"docutils literal notranslate\">&quot;ja,nein&quot;</code>\n(keeping the comma intact).</p>\n</aside>\n</section>\n<section id=\"comments-for-translators-in-templates\">\n<span id=\"translator-comments-in-templates\"></span><h3>Comments for translators in templates<a class=\"heading-anchor\" href=\"#comments-for-translators-in-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Just like with <a class=\"reference internal\" href=\"#translator-comments\"><span class=\"std std-ref\">Python code</span></a>, these notes for\ntranslators can be specified using comments, either with the <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/builtins/#std-templatetag-comment\"><code class=\"xref std std-ttag docutils literal notranslate\">comment</code></a>\ntag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">comment</span> <span class=\"cp\">%}</span><span class=\"c\">Translators: View verb</span><span class=\"cp\">{%</span> <span class=\"k\">endcomment</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;View&quot;</span> <span class=\"cp\">%}</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">comment</span> <span class=\"cp\">%}</span><span class=\"c\">Translators: Short intro blurb</span><span class=\"cp\">{%</span> <span class=\"k\">endcomment</span> <span class=\"cp\">%}</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"cp\">%}</span>A multiline translatable\nliteral.<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>or with the <code class=\"docutils literal notranslate\">{#</code> … <code class=\"docutils literal notranslate\">#}</code>\n<a class=\"reference internal\" href=\"/ko/6.0/ref/templates/language/#template-comments\"><span class=\"std std-ref\">one-line comment constructs</span></a>:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"c\">{# Translators: Label of a button that triggers search #}</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">button</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">&quot;submit&quot;</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;Go&quot;</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">button</span><span class=\"p\">&gt;</span>\n\n<span class=\"c\">{# Translators: This is a text of the base template #}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">blocktranslate</span> <span class=\"cp\">%}</span>Ambiguous translatable block of text<span class=\"cp\">{%</span> <span class=\"k\">endblocktranslate</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>Just for completeness, these are the corresponding fragments of the\nresulting <code class=\"docutils literal notranslate\">.po</code> file:</p>\n<div class=\"code-block\" data-language=\"po\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Po</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Po code\"><code><span class=\"c1\">#. Translators: View verb</span>\n<span class=\"c1\"># path/to/template/file.html:10</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;View&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n\n<span class=\"c1\">#. Translators: Short intro blurb</span>\n<span class=\"c1\"># path/to/template/file.html:13</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;&quot;</span>\n<span class=\"s\">&quot;A multiline translatable&quot;</span>\n<span class=\"s\">&quot;literal.&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n\n<span class=\"c1\"># ...</span>\n\n<span class=\"c1\">#. Translators: Label of a button that triggers search</span>\n<span class=\"c1\"># path/to/template/file.html:100</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;Go&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n\n<span class=\"c1\">#. Translators: This is a text of the base template</span>\n<span class=\"c1\"># path/to/template/file.html:103</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;Ambiguous translatable block of text&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n</code></pre></div>\n</aside>\n</section>\n<section id=\"switching-language-in-templates\">\n<span id=\"std-templatetag-language\"></span><h3>Switching language in templates<a class=\"heading-anchor\" href=\"#switching-language-in-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you want to select a language within a template, you can use the\n<code class=\"docutils literal notranslate\">language</code> template tag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">load</span> <span class=\"nv\">i18n</span> <span class=\"cp\">%}</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">get_current_language</span> <span class=\"k\">as</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">%}</span>\n<span class=\"cm\">&lt;!-- Current language: </span><span class=\"cp\">{{</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">}}</span><span class=\"cm\"> --&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;Welcome to our page&quot;</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">language</span> <span class=\"s1\">&#39;en&#39;</span> <span class=\"cp\">%}</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">get_current_language</span> <span class=\"k\">as</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">%}</span>\n    <span class=\"cm\">&lt;!-- Current language: </span><span class=\"cp\">{{</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">}}</span><span class=\"cm\"> --&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;Welcome to our page&quot;</span> <span class=\"cp\">%}</span><span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endlanguage</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>While the first occurrence of “Welcome to our page” uses the current language,\nthe second will always be in English.</p>\n</section>\n<section id=\"other-tags\">\n<span id=\"i18n-template-tags\"></span><h3>Other tags<a class=\"heading-anchor\" href=\"#other-tags\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>These tags also require a <code class=\"docutils literal notranslate\">{% load i18n %}</code>.</p>\n<section id=\"get-available-languages\">\n<span id=\"std-templatetag-get_available_languages\"></span><h4><code class=\"docutils literal notranslate\">get_available_languages</code><a class=\"heading-anchor\" href=\"#get-available-languages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\">{% get_available_languages as LANGUAGES %}</code> returns a list of tuples in\nwhich the first element is the <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-language-code\"><span class=\"xref std std-term\">language code</span></a> and the second is the\nlanguage name (translated into the currently active locale).</p>\n</section>\n<section id=\"get-current-language\">\n<span id=\"std-templatetag-get_current_language\"></span><h4><code class=\"docutils literal notranslate\">get_current_language</code><a class=\"heading-anchor\" href=\"#get-current-language\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\">{% get_current_language as LANGUAGE_CODE %}</code> returns the current user’s\npreferred language as a string. Example: <code class=\"docutils literal notranslate\">en-us</code>. See\n<a class=\"reference internal\" href=\"#how-django-discovers-language-preference\"><span class=\"std std-ref\">How Django discovers language preference</span></a>.</p>\n</section>\n<section id=\"get-current-language-bidi\">\n<span id=\"std-templatetag-get_current_language_bidi\"></span><h4><code class=\"docutils literal notranslate\">get_current_language_bidi</code><a class=\"heading-anchor\" href=\"#get-current-language-bidi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\">{% get_current_language_bidi as LANGUAGE_BIDI %}</code> returns the current\nlocale’s direction. If <code class=\"docutils literal notranslate\">True</code>, it’s a right-to-left language, e.g. Hebrew,\nArabic. If <code class=\"docutils literal notranslate\">False</code> it’s a left-to-right language, e.g. English, French,\nGerman, etc.</p>\n</section>\n<section id=\"i18n-context-processor\">\n<span id=\"template-translation-vars\"></span><h4><code class=\"docutils literal notranslate\">i18n</code> context processor<a class=\"heading-anchor\" href=\"#i18n-context-processor\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If you enable the <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/api/#django.template.context_processors.i18n\" title=\"django.template.context_processors.i18n\"><code class=\"xref py py-class docutils literal notranslate\">django.template.context_processors.i18n</code></a> context\nprocessor, then each <code class=\"docutils literal notranslate\">RequestContext</code> will have access to <code class=\"docutils literal notranslate\">LANGUAGES</code>,\n<code class=\"docutils literal notranslate\">LANGUAGE_CODE</code>, and <code class=\"docutils literal notranslate\">LANGUAGE_BIDI</code> as defined above.</p>\n</section>\n<section id=\"get-language-info\">\n<span id=\"std-templatetag-get_language_info\"></span><h4><code class=\"docutils literal notranslate\">get_language_info</code><a class=\"heading-anchor\" href=\"#get-language-info\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>You can also retrieve information about any of the available languages using\nprovided template tags and filters. To get information about a single language,\nuse the <code class=\"docutils literal notranslate\">{% get_language_info %}</code> tag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">get_language_info</span> <span class=\"nv\">for</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"k\">as</span> <span class=\"nv\">lang</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">get_language_info</span> <span class=\"nv\">for</span> <span class=\"s2\">&quot;pl&quot;</span> <span class=\"k\">as</span> <span class=\"nv\">lang</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>You can then access the information:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code>Language code: <span class=\"cp\">{{</span> <span class=\"nv\">lang.code</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;</span><span class=\"nt\">br</span><span class=\"p\">&gt;</span>\nName of language: <span class=\"cp\">{{</span> <span class=\"nv\">lang.name_local</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;</span><span class=\"nt\">br</span><span class=\"p\">&gt;</span>\nName in English: <span class=\"cp\">{{</span> <span class=\"nv\">lang.name</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;</span><span class=\"nt\">br</span><span class=\"p\">&gt;</span>\nBi-directional: <span class=\"cp\">{{</span> <span class=\"nv\">lang.bidi</span> <span class=\"cp\">}}</span>\nName in the active language: <span class=\"cp\">{{</span> <span class=\"nv\">lang.name_translated</span> <span class=\"cp\">}}</span>\n</code></pre></div>\n</section>\n<section id=\"get-language-info-list\">\n<span id=\"std-templatetag-get_language_info_list\"></span><h4><code class=\"docutils literal notranslate\">get_language_info_list</code><a class=\"heading-anchor\" href=\"#get-language-info-list\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>You can also use the <code class=\"docutils literal notranslate\">{% get_language_info_list %}</code> template tag to retrieve\ninformation for a list of languages (e.g. active languages as specified in\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGES</code></a>). See <a class=\"reference internal\" href=\"#set-language-redirect-view\"><span class=\"std std-ref\">the section about the set_language redirect\nview</span></a> for an example of how to display a language\nselector using <code class=\"docutils literal notranslate\">{% get_language_info_list %}</code>.</p>\n<p>In addition to <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGES</code></a> style list of tuples,\n<code class=\"docutils literal notranslate\">{% get_language_info_list %}</code> supports lists of language codes.\nIf you do this in your view:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code>context <span class=\"o\">=</span> <span class=\"p\">{</span><span class=\"s2\">&quot;available_languages&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;es&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;fr&quot;</span><span class=\"p\">]}</span>\n<span class=\"k\">return</span> render<span class=\"p\">(</span>request<span class=\"p\">,</span> <span class=\"s2\">&quot;mytemplate.html&quot;</span><span class=\"p\">,</span> context<span class=\"p\">)</span>\n</code></pre></div>\n<p>you can iterate over those languages in the template:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">get_language_info_list</span> <span class=\"nv\">for</span> <span class=\"nv\">available_languages</span> <span class=\"k\">as</span> <span class=\"nv\">langs</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">lang</span> <span class=\"k\">in</span> <span class=\"nv\">langs</span> <span class=\"cp\">%}</span> ... <span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n</section>\n<section id=\"template-filters\">\n<span id=\"std-templatefilter-language_name_translated\"></span><span id=\"std-templatefilter-language_bidi\"></span><span id=\"std-templatefilter-language_name_local\"></span><span id=\"std-templatefilter-language_name\"></span><h4>템플릿 필터<a class=\"heading-anchor\" href=\"#template-filters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>There are also some filters available for convenience:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">{{ LANGUAGE_CODE|language_name }}</code> (“German”)</p></li>\n<li><p><code class=\"docutils literal notranslate\">{{ LANGUAGE_CODE|language_name_local }}</code> (“Deutsch”)</p></li>\n<li><p><code class=\"docutils literal notranslate\">{{ LANGUAGE_CODE|language_bidi }}</code> (False)</p></li>\n<li><p><code class=\"docutils literal notranslate\">{{ LANGUAGE_CODE|language_name_translated }}</code> (“německy”, when active\nlanguage is Czech)</p></li>\n</ul>\n</section>\n</section>\n</section>\n<section id=\"internationalization-in-javascript-code\">\n<h2>Internationalization: in JavaScript code<a class=\"heading-anchor\" href=\"#internationalization-in-javascript-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Adding translations to JavaScript poses some problems:</p>\n<ul class=\"simple\">\n<li><p>JavaScript code doesn’t have access to a <code class=\"docutils literal notranslate\">gettext</code> implementation.</p></li>\n<li><p>JavaScript code doesn’t have access to <code class=\"docutils literal notranslate\">.po</code> or <code class=\"docutils literal notranslate\">.mo</code> files; they need to\nbe delivered by the server.</p></li>\n<li><p>The translation catalogs for JavaScript should be kept as small as\npossible.</p></li>\n</ul>\n<p>Django provides an integrated solution for these problems: It passes the\ntranslations into JavaScript, so you can call <code class=\"docutils literal notranslate\">gettext</code>, etc., from within\nJavaScript.</p>\n<p>The main solution to these problems is the following <code class=\"docutils literal notranslate\">JavaScriptCatalog</code>\nview, which generates a JavaScript code library with functions that mimic the\n<code class=\"docutils literal notranslate\">gettext</code> interface, plus an array of translation strings.</p>\n<section id=\"module-django.views.i18n\">\n<span id=\"the-javascriptcatalog-view\"></span><h3>The <code class=\"docutils literal notranslate\">JavaScriptCatalog</code> view<a class=\"heading-anchor\" href=\"#module-django.views.i18n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.i18n.JavaScriptCatalog\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">JavaScriptCatalog</span><a class=\"heading-anchor\" href=\"#django.views.i18n.JavaScriptCatalog\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A view that produces a JavaScript code library with functions that mimic\nthe <code class=\"docutils literal notranslate\">gettext</code> interface, plus an array of translation strings.</p>\n<p><strong>Attributes</strong></p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.i18n.JavaScriptCatalog.domain\">\n<span class=\"sig-name descname\">domain</span><a class=\"heading-anchor\" href=\"#django.views.i18n.JavaScriptCatalog.domain\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Translation domain containing strings to add in the view output.\nDefaults to <code class=\"docutils literal notranslate\">'djangojs'</code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.i18n.JavaScriptCatalog.packages\">\n<span class=\"sig-name descname\">packages</span><a class=\"heading-anchor\" href=\"#django.views.i18n.JavaScriptCatalog.packages\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A list of <a class=\"reference internal\" href=\"/ko/6.0/ref/applications/#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\">application names</code></a> among\ninstalled applications. Those apps should contain a <code class=\"docutils literal notranslate\">locale</code>\ndirectory. All those catalogs plus all catalogs found in\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> (which are always included) are merged into one\ncatalog. Defaults to <code class=\"docutils literal notranslate\">None</code>, which means that all available\ntranslations from all <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> are provided in the\nJavaScript output.</p>\n</dd></dl>\n\n<p><strong>Example with default values</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.views.i18n</span> <span class=\"kn\">import</span> JavaScriptCatalog\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;jsi18n/&quot;</span><span class=\"p\">,</span> JavaScriptCatalog<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;javascript-catalog&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p><strong>Example with custom packages</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>urlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;jsi18n/myapp/&quot;</span><span class=\"p\">,</span>\n        JavaScriptCatalog<span class=\"o\">.</span>as_view<span class=\"p\">(</span>packages<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;your.app.label&quot;</span><span class=\"p\">]),</span>\n        name<span class=\"o\">=</span><span class=\"s2\">&quot;javascript-catalog&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>If your root URLconf uses <a class=\"reference internal\" href=\"#django.conf.urls.i18n.i18n_patterns\" title=\"django.conf.urls.i18n.i18n_patterns\"><code class=\"xref py py-func docutils literal notranslate\">i18n_patterns()</code></a>,\n<code class=\"docutils literal notranslate\">JavaScriptCatalog</code> must also be wrapped by <code class=\"docutils literal notranslate\">i18n_patterns()</code> for the\ncatalog to be correctly generated.</p>\n<p><strong>Example with</strong> <code class=\"docutils literal notranslate\">i18n_patterns()</code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls.i18n</span> <span class=\"kn\">import</span> i18n_patterns\n\nurlpatterns <span class=\"o\">=</span> i18n_patterns<span class=\"p\">(</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;jsi18n/&quot;</span><span class=\"p\">,</span> JavaScriptCatalog<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;javascript-catalog&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n<p>The precedence of translations is such that the packages appearing later in the\n<code class=\"docutils literal notranslate\">packages</code> argument have higher precedence than the ones appearing at the\nbeginning. This is important in the case of clashing translations for the same\nliteral.</p>\n<p>If you use more than one <code class=\"docutils literal notranslate\">JavaScriptCatalog</code> view on a site and some of them\ndefine the same strings, the strings in the catalog that was loaded last take\nprecedence.</p>\n</section>\n<section id=\"using-the-javascript-translation-catalog\">\n<h3>Using the JavaScript translation catalog<a class=\"heading-anchor\" href=\"#using-the-javascript-translation-catalog\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>To use the catalog, pull in the dynamically generated script like this:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">script</span> <span class=\"na\">src</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">url</span> <span class=\"s1\">&#39;javascript-catalog&#39;</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">script</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>This uses reverse URL lookup to find the URL of the JavaScript catalog view.\nWhen the catalog is loaded, your JavaScript code can use the following methods:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">gettext</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">ngettext</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">interpolate</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">get_format</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">gettext_noop</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">pgettext</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">npgettext</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">pluralidx</code></p></li>\n</ul>\n<section id=\"gettext\">\n<h4><code class=\"docutils literal notranslate\">gettext</code><a class=\"heading-anchor\" href=\"#gettext\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">gettext</code> function behaves similarly to the standard <code class=\"docutils literal notranslate\">gettext</code>\ninterface within your Python code:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>document<span class=\"o\">.</span>write<span class=\"p\">(</span>gettext<span class=\"p\">(</span><span class=\"s2\">&quot;this is to be translated&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n</section>\n<section id=\"ngettext\">\n<h4><code class=\"docutils literal notranslate\">ngettext</code><a class=\"heading-anchor\" href=\"#ngettext\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">ngettext</code> function provides an interface to pluralize words and\nphrases:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"kd\">const</span> <span class=\"nx\">objectCount</span> <span class=\"o\">=</span> <span class=\"mf\">1</span> <span class=\"c1\">// or 0, or 2, or 3, ...</span>\n<span class=\"kd\">const</span> <span class=\"nx\">string</span> <span class=\"o\">=</span> <span class=\"nx\">ngettext</span><span class=\"p\">(</span>\n    <span class=\"s1\">&#39;literal for the singular case&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;literal for the plural case&#39;</span><span class=\"p\">,</span>\n    <span class=\"nx\">objectCount</span>\n<span class=\"p\">);</span>\n</code></pre></div>\n</section>\n<section id=\"interpolate\">\n<h4><code class=\"docutils literal notranslate\">interpolate</code><a class=\"heading-anchor\" href=\"#interpolate\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">interpolate</code> function supports dynamically populating a format string.\nThe interpolation syntax is borrowed from Python, so the <code class=\"docutils literal notranslate\">interpolate</code>\nfunction supports both positional and named interpolation:</p>\n<ul>\n<li><p>Positional interpolation: <code class=\"docutils literal notranslate\">obj</code> contains a JavaScript Array object\nwhose elements values are then sequentially interpolated in their\ncorresponding <code class=\"docutils literal notranslate\">fmt</code> placeholders in the same order they appear.\nFor example:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"kd\">const</span> <span class=\"nx\">formats</span> <span class=\"o\">=</span> <span class=\"nx\">ngettext</span><span class=\"p\">(</span>\n  <span class=\"s1\">&#39;There is %s object. Remaining: %s&#39;</span><span class=\"p\">,</span>\n  <span class=\"s1\">&#39;There are %s objects. Remaining: %s&#39;</span><span class=\"p\">,</span>\n  <span class=\"mf\">11</span>\n<span class=\"p\">);</span>\n<span class=\"kd\">const</span> <span class=\"nx\">string</span> <span class=\"o\">=</span> <span class=\"nx\">interpolate</span><span class=\"p\">(</span><span class=\"nx\">formats</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"mf\">11</span><span class=\"p\">,</span> <span class=\"mf\">20</span><span class=\"p\">]);</span>\n<span class=\"c1\">// string is &#39;There are 11 objects. Remaining: 20&#39;</span>\n</code></pre></div>\n</li>\n<li><p>Named interpolation: This mode is selected by passing the optional\nboolean <code class=\"docutils literal notranslate\">named</code> parameter as <code class=\"docutils literal notranslate\">true</code>. <code class=\"docutils literal notranslate\">obj</code> contains a JavaScript\nobject or associative array. For example:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"kd\">const</span> <span class=\"nx\">data</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n  <span class=\"nx\">count</span><span class=\"o\">:</span> <span class=\"mf\">10</span><span class=\"p\">,</span>\n  <span class=\"nx\">total</span><span class=\"o\">:</span> <span class=\"mf\">50</span>\n<span class=\"p\">};</span>\n\n<span class=\"kd\">const</span> <span class=\"nx\">formats</span> <span class=\"o\">=</span> <span class=\"nx\">ngettext</span><span class=\"p\">(</span>\n    <span class=\"s1\">&#39;Total: %(total)s, there is %(count)s object&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;there are %(count)s of a total of %(total)s objects&#39;</span><span class=\"p\">,</span>\n    <span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">count</span>\n<span class=\"p\">);</span>\n<span class=\"kd\">const</span> <span class=\"nx\">string</span> <span class=\"o\">=</span> <span class=\"nx\">interpolate</span><span class=\"p\">(</span><span class=\"nx\">formats</span><span class=\"p\">,</span> <span class=\"nx\">data</span><span class=\"p\">,</span> <span class=\"kc\">true</span><span class=\"p\">);</span>\n</code></pre></div>\n</li>\n</ul>\n<p>You shouldn’t go over the top with string interpolation, though: this is still\nJavaScript, so the code has to make repeated regular-expression substitutions.\nThis isn’t as fast as string interpolation in Python, so keep it to those\ncases where you really need it (for example, in conjunction with <code class=\"docutils literal notranslate\">ngettext</code>\nto produce proper pluralizations).</p>\n</section>\n<section id=\"get-format\">\n<h4><code class=\"docutils literal notranslate\">get_format</code><a class=\"heading-anchor\" href=\"#get-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">get_format</code> function has access to the configured i18n formatting\nsettings and can retrieve the format string for a given setting name:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">get_format</span><span class=\"p\">(</span><span class=\"s1\">&#39;DATE_FORMAT&#39;</span><span class=\"p\">));</span>\n<span class=\"c1\">// &#39;N j, Y&#39;</span>\n</code></pre></div>\n<p>It has access to the following settings:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">DATE_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\">DATE_INPUT_FORMATS</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">DATETIME_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-DATETIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\">DATETIME_INPUT_FORMATS</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\">DECIMAL_SEPARATOR</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-FIRST_DAY_OF_WEEK\"><code class=\"xref std std-setting docutils literal notranslate\">FIRST_DAY_OF_WEEK</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-MONTH_DAY_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">MONTH_DAY_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\">NUMBER_GROUPING</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-SHORT_DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">SHORT_DATE_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-SHORT_DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">SHORT_DATETIME_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\">THOUSAND_SEPARATOR</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">TIME_FORMAT</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-TIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\">TIME_INPUT_FORMATS</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-YEAR_MONTH_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\">YEAR_MONTH_FORMAT</code></a></p></li>\n</ul>\n<p>This is useful for maintaining formatting consistency with the Python-rendered\nvalues.</p>\n</section>\n<section id=\"gettext-noop\">\n<h4><code class=\"docutils literal notranslate\">gettext_noop</code><a class=\"heading-anchor\" href=\"#gettext-noop\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>This emulates the <code class=\"docutils literal notranslate\">gettext</code> function but does nothing, returning whatever\nis passed to it:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>document<span class=\"o\">.</span>write<span class=\"p\">(</span>gettext_noop<span class=\"p\">(</span><span class=\"s2\">&quot;this will not be translated&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n<p>This is useful for stubbing out portions of the code that will need translation\nin the future.</p>\n</section>\n<section id=\"pgettext\">\n<h4><code class=\"docutils literal notranslate\">pgettext</code><a class=\"heading-anchor\" href=\"#pgettext\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">pgettext</code> function behaves like the Python variant\n(<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.pgettext\" title=\"django.utils.translation.pgettext\"><code class=\"xref py py-func docutils literal notranslate\">pgettext()</code></a>), providing a contextually\ntranslated word:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>document<span class=\"o\">.</span>write<span class=\"p\">(</span>pgettext<span class=\"p\">(</span><span class=\"s2\">&quot;month name&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;May&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n</section>\n<section id=\"npgettext\">\n<h4><code class=\"docutils literal notranslate\">npgettext</code><a class=\"heading-anchor\" href=\"#npgettext\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">npgettext</code> function also behaves like the Python variant\n(<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.npgettext\" title=\"django.utils.translation.npgettext\"><code class=\"xref py py-func docutils literal notranslate\">npgettext()</code></a>), providing a <strong>pluralized</strong>\ncontextually translated word:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">npgettext</span><span class=\"p\">(</span><span class=\"s1\">&#39;group&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;party&#39;</span><span class=\"p\">,</span> <span class=\"mf\">1</span><span class=\"p\">));</span>\n<span class=\"c1\">// party</span>\n<span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">npgettext</span><span class=\"p\">(</span><span class=\"s1\">&#39;group&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;party&#39;</span><span class=\"p\">,</span> <span class=\"mf\">2</span><span class=\"p\">));</span>\n<span class=\"c1\">// parties</span>\n</code></pre></div>\n</section>\n<section id=\"pluralidx\">\n<h4><code class=\"docutils literal notranslate\">pluralidx</code><a class=\"heading-anchor\" href=\"#pluralidx\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\">pluralidx</code> function works in a similar way to the <a class=\"reference internal\" href=\"/ko/6.0/ref/templates/builtins/#std-templatefilter-pluralize\"><code class=\"xref std std-tfilter docutils literal notranslate\">pluralize</code></a>\ntemplate filter, determining if a given <code class=\"docutils literal notranslate\">count</code> should use a plural form of\na word or not:</p>\n<div class=\"code-block\" data-language=\"javascript\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">JavaScript</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"JavaScript code\"><code><span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">pluralidx</span><span class=\"p\">(</span><span class=\"mf\">0</span><span class=\"p\">));</span>\n<span class=\"c1\">// true</span>\n<span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">pluralidx</span><span class=\"p\">(</span><span class=\"mf\">1</span><span class=\"p\">));</span>\n<span class=\"c1\">// false</span>\n<span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">write</span><span class=\"p\">(</span><span class=\"nx\">pluralidx</span><span class=\"p\">(</span><span class=\"mf\">2</span><span class=\"p\">));</span>\n<span class=\"c1\">// true</span>\n</code></pre></div>\n<p>In the simplest case, if no custom pluralization is needed, this returns\n<code class=\"docutils literal notranslate\">false</code> for the integer <code class=\"docutils literal notranslate\">1</code> and <code class=\"docutils literal notranslate\">true</code> for all other numbers.</p>\n<p>However, pluralization is not this simple in all languages. If the language\ndoes not support pluralization, an empty value is provided.</p>\n<p>Additionally, if there are complex rules around pluralization, the catalog view\nwill render a conditional expression. This will evaluate to either a <code class=\"docutils literal notranslate\">true</code>\n(should pluralize) or <code class=\"docutils literal notranslate\">false</code> (should <strong>not</strong> pluralize) value.</p>\n</section>\n</section>\n<section id=\"the-jsoncatalog-view\">\n<h3>The <code class=\"docutils literal notranslate\">JSONCatalog</code> view<a class=\"heading-anchor\" href=\"#the-jsoncatalog-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.i18n.JSONCatalog\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">JSONCatalog</span><a class=\"heading-anchor\" href=\"#django.views.i18n.JSONCatalog\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>In order to use another client-side library to handle translations, you may\nwant to take advantage of the <code class=\"docutils literal notranslate\">JSONCatalog</code> view. It’s similar to\n<a class=\"reference internal\" href=\"#django.views.i18n.JavaScriptCatalog\" title=\"django.views.i18n.JavaScriptCatalog\"><code class=\"xref py py-class docutils literal notranslate\">JavaScriptCatalog</code></a> but returns a JSON response.</p>\n<p>See the documentation for <a class=\"reference internal\" href=\"#django.views.i18n.JavaScriptCatalog\" title=\"django.views.i18n.JavaScriptCatalog\"><code class=\"xref py py-class docutils literal notranslate\">JavaScriptCatalog</code></a>\nto learn about possible values and use of the <code class=\"docutils literal notranslate\">domain</code> and <code class=\"docutils literal notranslate\">packages</code>\nattributes.</p>\n<p>The response format is as follows:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>{\n    &quot;catalog&quot;: {\n        # Translations catalog\n    },\n    &quot;formats&quot;: {\n        # Language formats for date, time, etc.\n    },\n    &quot;plural&quot;: &quot;...&quot;  # Expression for plural forms, or null.\n}\n</code></pre></div>\n</dd></dl>\n\n</section>\n<section id=\"note-on-performance\">\n<h3>Note on performance<a class=\"heading-anchor\" href=\"#note-on-performance\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The various JavaScript/JSON i18n views generate the catalog from <code class=\"docutils literal notranslate\">.mo</code> files\non every request. Since its output is constant, at least for a given version\nof a site, it’s a good candidate for caching.</p>\n<p>Server-side caching will reduce CPU load. It’s easily implemented with the\n<a class=\"reference internal\" href=\"/ko/6.0/topics/cache/#django.views.decorators.cache.cache_page\" title=\"django.views.decorators.cache.cache_page\"><code class=\"xref py py-func docutils literal notranslate\">cache_page()</code></a> decorator. To trigger cache\ninvalidation when your translations change, provide a version-dependent key\nprefix, as shown in the example below, or map the view at a version-dependent\nURL:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.views.decorators.cache</span> <span class=\"kn\">import</span> cache_page\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.i18n</span> <span class=\"kn\">import</span> JavaScriptCatalog\n\n<span class=\"c1\"># The value returned by get_version() must change when translations change.</span>\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;jsi18n/&quot;</span><span class=\"p\">,</span>\n        cache_page<span class=\"p\">(</span><span class=\"mi\">86400</span><span class=\"p\">,</span> key_prefix<span class=\"o\">=</span><span class=\"s2\">&quot;jsi18n-</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> get_version<span class=\"p\">())(</span>\n            JavaScriptCatalog<span class=\"o\">.</span>as_view<span class=\"p\">()</span>\n        <span class=\"p\">),</span>\n        name<span class=\"o\">=</span><span class=\"s2\">&quot;javascript-catalog&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Client-side caching will save bandwidth and make your site load faster. If\nyou’re using ETags (<a class=\"reference internal\" href=\"/ko/6.0/ref/middleware/#django.middleware.http.ConditionalGetMiddleware\" title=\"django.middleware.http.ConditionalGetMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">ConditionalGetMiddleware</code></a>),\nyou’re already covered. Otherwise, you can apply <a class=\"reference internal\" href=\"/ko/6.0/topics/conditional-view-processing/#conditional-decorators\"><span class=\"std std-ref\">conditional decorators</span></a>. In the following example, the cache is invalidated\nwhenever you restart your application server:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils</span> <span class=\"kn\">import</span> timezone\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.decorators.http</span> <span class=\"kn\">import</span> last_modified\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.i18n</span> <span class=\"kn\">import</span> JavaScriptCatalog\n\nlast_modified_date <span class=\"o\">=</span> timezone<span class=\"o\">.</span>now<span class=\"p\">()</span>\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;jsi18n/&quot;</span><span class=\"p\">,</span>\n        last_modified<span class=\"p\">(</span><span class=\"k\">lambda</span> req<span class=\"p\">,</span> <span class=\"o\">**</span>kw<span class=\"p\">:</span> last_modified_date<span class=\"p\">)(</span>\n            JavaScriptCatalog<span class=\"o\">.</span>as_view<span class=\"p\">()</span>\n        <span class=\"p\">),</span>\n        name<span class=\"o\">=</span><span class=\"s2\">&quot;javascript-catalog&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>You can even pre-generate the JavaScript catalog as part of your deployment\nprocedure and serve it as a static file. This radical technique is implemented\nin <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/django-statici18n/\">django-statici18n</a>.</p>\n</section>\n</section>\n<section id=\"module-django.conf.urls.i18n\">\n<span id=\"internationalization-in-url-patterns\"></span><span id=\"url-internationalization\"></span><h2>Internationalization: in URL patterns<a class=\"heading-anchor\" href=\"#module-django.conf.urls.i18n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django provides two mechanisms to internationalize URL patterns:</p>\n<ul class=\"simple\">\n<li><p>Adding the language prefix to the root of the URL patterns to make it\npossible for <a class=\"reference internal\" href=\"/ko/6.0/ref/middleware/#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">LocaleMiddleware</code></a> to detect\nthe language to activate from the requested URL.</p></li>\n<li><p>Making URL patterns themselves translatable via the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.gettext_lazy()</code></a> function.</p></li>\n</ul>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>Using either one of these features requires that an active language be set\nfor each request; in other words, you need to have\n<a class=\"reference internal\" href=\"/ko/6.0/ref/middleware/#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">django.middleware.locale.LocaleMiddleware</code></a> in your\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> setting.</p>\n</aside>\n<section id=\"language-prefix-in-url-patterns\">\n<h3>Language prefix in URL patterns<a class=\"heading-anchor\" href=\"#language-prefix-in-url-patterns\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.conf.urls.i18n.i18n_patterns\">\n<span class=\"sig-name descname\">i18n_patterns</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">*</span>urls</em>, <em class=\"sig-param\">prefix_default_language<span class=\"o\">=</span><span class=\"default_value\">True</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.conf.urls.i18n.i18n_patterns\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>This function can be used in a root URLconf and Django will automatically\nprepend the current active language code to all URL patterns defined within\n<a class=\"reference internal\" href=\"#django.conf.urls.i18n.i18n_patterns\" title=\"django.conf.urls.i18n.i18n_patterns\"><code class=\"xref py py-func docutils literal notranslate\">i18n_patterns()</code></a>.</p>\n<p>Setting <code class=\"docutils literal notranslate\">prefix_default_language</code> to <code class=\"docutils literal notranslate\">False</code> removes the prefix from the\ndefault language (<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a>). This can be useful when adding\ntranslations to existing site so that the current URLs won’t change.</p>\n<p>Example URL patterns:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls.i18n</span> <span class=\"kn\">import</span> i18n_patterns\n<span class=\"kn\">from</span> <span class=\"nn\">django.urls</span> <span class=\"kn\">import</span> include<span class=\"p\">,</span> path\n\n<span class=\"kn\">from</span> <span class=\"nn\">about</span> <span class=\"kn\">import</span> views <span class=\"k\">as</span> about_views\n<span class=\"kn\">from</span> <span class=\"nn\">news</span> <span class=\"kn\">import</span> views <span class=\"k\">as</span> news_views\n<span class=\"kn\">from</span> <span class=\"nn\">sitemap.views</span> <span class=\"kn\">import</span> sitemap\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;sitemap.xml&quot;</span><span class=\"p\">,</span> sitemap<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;sitemap-xml&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n\nnews_patterns <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"p\">[</span>\n        path<span class=\"p\">(</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span> news_views<span class=\"o\">.</span>index<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;index&quot;</span><span class=\"p\">),</span>\n        path<span class=\"p\">(</span><span class=\"s2\">&quot;category/&lt;slug:slug&gt;/&quot;</span><span class=\"p\">,</span> news_views<span class=\"o\">.</span>category<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;category&quot;</span><span class=\"p\">),</span>\n        path<span class=\"p\">(</span><span class=\"s2\">&quot;&lt;slug:slug&gt;/&quot;</span><span class=\"p\">,</span> news_views<span class=\"o\">.</span>details<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;detail&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">],</span>\n    <span class=\"s2\">&quot;news&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n\nurlpatterns <span class=\"o\">+=</span> i18n_patterns<span class=\"p\">(</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;about/&quot;</span><span class=\"p\">,</span> about_views<span class=\"o\">.</span>main<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;about&quot;</span><span class=\"p\">),</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;news/&quot;</span><span class=\"p\">,</span> include<span class=\"p\">(</span>news_patterns<span class=\"p\">,</span> namespace<span class=\"o\">=</span><span class=\"s2\">&quot;news&quot;</span><span class=\"p\">)),</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>After defining these URL patterns, Django will automatically add the\nlanguage prefix to the URL patterns that were added by the <code class=\"docutils literal notranslate\">i18n_patterns</code>\nfunction. Example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.urls</span> <span class=\"kn\">import</span> reverse\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> activate\n\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;sitemap-xml&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">&#39;/sitemap.xml&#39;</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:index&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">&#39;/en/news/&#39;</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;nl&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:detail&quot;</span><span class=\"p\">,</span> kwargs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;slug&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;news-slug&quot;</span><span class=\"p\">})</span>\n<span class=\"go\">&#39;/nl/news/news-slug/&#39;</span>\n</code></pre></div>\n<p>With <code class=\"docutils literal notranslate\">prefix_default_language=False</code> and  <code class=\"docutils literal notranslate\">LANGUAGE_CODE='en'</code>, the URLs\nwill be:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:index&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">&#39;/news/&#39;</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;nl&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:index&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">&#39;/nl/news/&#39;</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p><a class=\"reference internal\" href=\"#django.conf.urls.i18n.i18n_patterns\" title=\"django.conf.urls.i18n.i18n_patterns\"><code class=\"xref py py-func docutils literal notranslate\">i18n_patterns()</code></a> is only allowed in a root\nURLconf. Using it within an included URLconf will throw an\n<a class=\"reference internal\" href=\"/ko/6.0/ref/exceptions/#django.core.exceptions.ImproperlyConfigured\" title=\"django.core.exceptions.ImproperlyConfigured\"><code class=\"xref py py-exc docutils literal notranslate\">ImproperlyConfigured</code></a> exception.</p>\n</aside>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>Ensure that you don’t have non-prefixed URL patterns that might collide\nwith an automatically-added language prefix.</p>\n</aside>\n</section>\n<section id=\"translating-url-patterns\">\n<span id=\"translating-urlpatterns\"></span><h3>Translating URL patterns<a class=\"heading-anchor\" href=\"#translating-url-patterns\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>URL patterns can also be marked translatable using the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\">gettext_lazy()</code></a> function. Example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls.i18n</span> <span class=\"kn\">import</span> i18n_patterns\n<span class=\"kn\">from</span> <span class=\"nn\">django.urls</span> <span class=\"kn\">import</span> include<span class=\"p\">,</span> path\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\n<span class=\"kn\">from</span> <span class=\"nn\">about</span> <span class=\"kn\">import</span> views <span class=\"k\">as</span> about_views\n<span class=\"kn\">from</span> <span class=\"nn\">news</span> <span class=\"kn\">import</span> views <span class=\"k\">as</span> news_views\n<span class=\"kn\">from</span> <span class=\"nn\">sitemaps.views</span> <span class=\"kn\">import</span> sitemap\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;sitemap.xml&quot;</span><span class=\"p\">,</span> sitemap<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;sitemap-xml&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n\nnews_patterns <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"p\">[</span>\n        path<span class=\"p\">(</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span> news_views<span class=\"o\">.</span>index<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;index&quot;</span><span class=\"p\">),</span>\n        path<span class=\"p\">(</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;category/&lt;slug:slug&gt;/&quot;</span><span class=\"p\">),</span> news_views<span class=\"o\">.</span>category<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;category&quot;</span><span class=\"p\">),</span>\n        path<span class=\"p\">(</span><span class=\"s2\">&quot;&lt;slug:slug&gt;/&quot;</span><span class=\"p\">,</span> news_views<span class=\"o\">.</span>details<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;detail&quot;</span><span class=\"p\">),</span>\n    <span class=\"p\">],</span>\n    <span class=\"s2\">&quot;news&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n\nurlpatterns <span class=\"o\">+=</span> i18n_patterns<span class=\"p\">(</span>\n    path<span class=\"p\">(</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;about/&quot;</span><span class=\"p\">),</span> about_views<span class=\"o\">.</span>main<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;about&quot;</span><span class=\"p\">),</span>\n    path<span class=\"p\">(</span>_<span class=\"p\">(</span><span class=\"s2\">&quot;news/&quot;</span><span class=\"p\">),</span> include<span class=\"p\">(</span>news_patterns<span class=\"p\">,</span> namespace<span class=\"o\">=</span><span class=\"s2\">&quot;news&quot;</span><span class=\"p\">)),</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>After you’ve created the translations, the <a class=\"reference internal\" href=\"/ko/6.0/ref/urlresolvers/#django.urls.reverse\" title=\"django.urls.reverse\"><code class=\"xref py py-func docutils literal notranslate\">reverse()</code></a>\nfunction will return the URL in the active language. Example:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.urls</span> <span class=\"kn\">import</span> reverse\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> activate\n\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:category&quot;</span><span class=\"p\">,</span> kwargs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;slug&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;recent&quot;</span><span class=\"p\">})</span>\n<span class=\"go\">&#39;/en/news/category/recent/&#39;</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>activate<span class=\"p\">(</span><span class=\"s2\">&quot;nl&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>reverse<span class=\"p\">(</span><span class=\"s2\">&quot;news:category&quot;</span><span class=\"p\">,</span> kwargs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;slug&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;recent&quot;</span><span class=\"p\">})</span>\n<span class=\"go\">&#39;/nl/nieuws/categorie/recent/&#39;</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>In most cases, it’s best to use translated URLs only within a language code\nprefixed block of patterns (using\n<a class=\"reference internal\" href=\"#django.conf.urls.i18n.i18n_patterns\" title=\"django.conf.urls.i18n.i18n_patterns\"><code class=\"xref py py-func docutils literal notranslate\">i18n_patterns()</code></a>), to avoid the possibility\nthat a carelessly translated URL causes a collision with a non-translated\nURL pattern.</p>\n</aside>\n</section>\n<section id=\"reversing-in-templates\">\n<span id=\"id2\"></span><h3>Reversing in templates<a class=\"heading-anchor\" href=\"#reversing-in-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If localized URLs get reversed in templates they always use the current\nlanguage. To link to a URL in another language use the <a class=\"reference internal\" href=\"#std-templatetag-language\"><code class=\"xref std std-ttag docutils literal notranslate\">language</code></a>\ntemplate tag. It enables the given language in the enclosed template section:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">load</span> <span class=\"nv\">i18n</span> <span class=\"cp\">%}</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">get_available_languages</span> <span class=\"k\">as</span> <span class=\"nv\">languages</span> <span class=\"cp\">%}</span>\n\n<span class=\"cp\">{%</span> <span class=\"k\">translate</span> <span class=\"s2\">&quot;View this category in:&quot;</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">lang_code</span><span class=\"o\">,</span> <span class=\"nv\">lang_name</span> <span class=\"k\">in</span> <span class=\"nv\">languages</span> <span class=\"cp\">%}</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">language</span> <span class=\"nv\">lang_code</span> <span class=\"cp\">%}</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">url</span> <span class=\"s1\">&#39;category&#39;</span> <span class=\"nv\">slug</span><span class=\"o\">=</span><span class=\"nv\">category.slug</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">lang_name</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">endlanguage</span> <span class=\"cp\">%}</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>The <a class=\"reference internal\" href=\"#std-templatetag-language\"><code class=\"xref std std-ttag docutils literal notranslate\">language</code></a> tag expects the language code as the only argument.</p>\n</section>\n</section>\n<section id=\"localization-how-to-create-language-files\">\n<span id=\"how-to-create-language-files\"></span><h2>Localization: how to create language files<a class=\"heading-anchor\" href=\"#localization-how-to-create-language-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Once the string literals of an application have been tagged for later\ntranslation, the translation themselves need to be written (or obtained).\nHere’s how that works.</p>\n<section id=\"message-files\">\n<h3>Message files<a class=\"heading-anchor\" href=\"#message-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The first step is to create a <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-message-file\"><span class=\"xref std std-term\">message file</span></a> for a new language. A\nmessage file is a plain-text file, representing a single language, that\ncontains all available translation strings and how they should be represented\nin the given language. Message files have a <code class=\"docutils literal notranslate\">.po</code> file extension.</p>\n<p>Django comes with a tool, <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a>, that automates the creation and upkeep of these files.</p>\n<aside class=\"admonition-gettext-utilities admonition\" role=\"note\">\n<p class=\"admonition-title\">Gettext utilities</p>\n<p>The <code class=\"docutils literal notranslate\">makemessages</code> command (and <code class=\"docutils literal notranslate\">compilemessages</code> discussed later) use\ncommands from the GNU gettext toolset: <code class=\"docutils literal notranslate\">xgettext</code>, <code class=\"docutils literal notranslate\">msgfmt</code>,\n<code class=\"docutils literal notranslate\">msgmerge</code> and <code class=\"docutils literal notranslate\">msguniq</code>.</p>\n<p>The minimum version of the <code class=\"docutils literal notranslate\">gettext</code> utilities supported is 0.19.</p>\n</aside>\n<p>To create or update a message file, run this command:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin makemessages -l de\n</code></pre></div>\n<p>…where <code class=\"docutils literal notranslate\">de</code> is the <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-locale-name\"><span class=\"xref std std-term\">locale name</span></a> for the message file you want to\ncreate. For example, <code class=\"docutils literal notranslate\">pt_BR</code> for Brazilian Portuguese, <code class=\"docutils literal notranslate\">de_AT</code> for Austrian\nGerman or <code class=\"docutils literal notranslate\">id</code> for Indonesian.</p>\n<p>The script should be run from one of two places:</p>\n<ul class=\"simple\">\n<li><p>The root directory of your Django project (the one that contains\n<code class=\"docutils literal notranslate\">manage.py</code>).</p></li>\n<li><p>The root directory of one of your Django apps.</p></li>\n</ul>\n<p>The script runs over your project source tree or your application source tree\nand pulls out all strings marked for translation (see\n<a class=\"reference internal\" href=\"#how-django-discovers-translations\"><span class=\"std std-ref\">How Django discovers translations</span></a> and be sure <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a>\nis configured correctly). It creates (or updates) a message file in the\ndirectory <code class=\"docutils literal notranslate\">locale/LANG/LC_MESSAGES</code>. In the <code class=\"docutils literal notranslate\">de</code> example, the file will be\n<code class=\"docutils literal notranslate\">locale/de/LC_MESSAGES/django.po</code>.</p>\n<p>When you run <code class=\"docutils literal notranslate\">makemessages</code> from the root directory of your project, the\nextracted strings will be automatically distributed to the proper message\nfiles. That is, a string extracted from a file of an app containing a\n<code class=\"docutils literal notranslate\">locale</code> directory will go in a message file under that directory. A string\nextracted from a file of an app without any <code class=\"docutils literal notranslate\">locale</code> directory will either go\nin a message file under the directory listed first in <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a>\nor will generate an error if <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> is empty.</p>\n<p>By default <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a> examines every\nfile that has the <code class=\"docutils literal notranslate\">.html</code>, <code class=\"docutils literal notranslate\">.txt</code> or <code class=\"docutils literal notranslate\">.py</code> file extension. If you want to\noverride that default, use the <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#cmdoption-makemessages-extension\"><code class=\"xref std std-option docutils literal notranslate\">--extension</code></a>\nor <code class=\"docutils literal notranslate\">-e</code> option to specify the file extensions to examine:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin makemessages -l de -e txt\n</code></pre></div>\n<p>Separate multiple extensions with commas and/or use <code class=\"docutils literal notranslate\">-e</code> or <code class=\"docutils literal notranslate\">--extension</code>\nmultiple times:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin makemessages -l de -e html,txt -e xml\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>When <a class=\"reference internal\" href=\"#creating-message-files-from-js-code\"><span class=\"std std-ref\">creating message files from JavaScript source code</span></a> you need to use the special\n<code class=\"docutils literal notranslate\">djangojs</code> domain, <strong>not</strong> <code class=\"docutils literal notranslate\">-e js</code>.</p>\n</aside>\n<aside class=\"admonition-using-jinja2-templates admonition\" role=\"note\">\n<p class=\"admonition-title\">Using Jinja2 templates?</p>\n<p><a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> doesn’t understand the syntax of Jinja2 templates.\nTo extract strings from a project containing Jinja2 templates, use <a class=\"reference external\" href=\"https://babel.pocoo.org/en/latest/messages.html#message-extraction\">Message\nExtracting</a> from <a class=\"reference external\" href=\"https://babel.pocoo.org/en/latest/\">Babel</a> instead.</p>\n<p>Here’s an example <code class=\"docutils literal notranslate\">babel.cfg</code> configuration file:</p>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Ini code\"><code><span class=\"c1\"># Extraction from Python source files</span>\n<span class=\"k\">[python: **.py]</span>\n\n<span class=\"c1\"># Extraction from Jinja2 templates</span>\n<span class=\"k\">[jinja2: **.jinja]</span>\n<span class=\"na\">extensions</span> <span class=\"o\">=</span> <span class=\"s\">jinja2.ext.with_</span>\n</code></pre></div>\n<p>Make sure you list all extensions you’re using! Otherwise Babel won’t\nrecognize the tags defined by these extensions and will ignore Jinja2\ntemplates containing them entirely.</p>\n<p>Babel provides similar features to <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a>, can replace it\nin general, and doesn’t depend on <code class=\"docutils literal notranslate\">gettext</code>. For more information, read\nits documentation about <a class=\"reference external\" href=\"https://babel.pocoo.org/en/latest/messages.html\">working with message catalogs</a>.</p>\n</aside>\n<aside class=\"admonition-no-gettext admonition\" role=\"note\">\n<p class=\"admonition-title\">No gettext?</p>\n<p>If you don’t have the <code class=\"docutils literal notranslate\">gettext</code> utilities installed,\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> will create empty files. If that’s the case, either\ninstall the <code class=\"docutils literal notranslate\">gettext</code> utilities or copy the English message file\n(<code class=\"docutils literal notranslate\">locale/en/LC_MESSAGES/django.po</code>) if available and use it as a starting\npoint, which is an empty translation file.</p>\n</aside>\n<aside class=\"admonition-working-on-windows admonition\" role=\"note\">\n<p class=\"admonition-title\">Working on Windows?</p>\n<p>If you’re using Windows and need to install the GNU gettext utilities so\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> works, see <a class=\"reference internal\" href=\"#gettext-on-windows\"><span class=\"std std-ref\">gettext on Windows</span></a> for more\ninformation.</p>\n</aside>\n<p>Each <code class=\"docutils literal notranslate\">.po</code> file contains a small bit of metadata, such as the translation\nmaintainer’s contact information, but the bulk of the file is a list of\n<strong>messages</strong> – mappings between translation strings and the actual translated\ntext for the particular language.</p>\n<p>For example, if your Django app contained a translation string for the text\n<code class=\"docutils literal notranslate\">&quot;Welcome to my site.&quot;</code>, like so:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>_<span class=\"p\">(</span><span class=\"s2\">&quot;Welcome to my site.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>…then <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a> will have created\na <code class=\"docutils literal notranslate\">.po</code> file containing the following snippet – a message:</p>\n<div class=\"code-block\" data-language=\"po\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Po</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Po code\"><code><span class=\"kd\">#: path/to/python/module.py:23</span>\n<span class=\"nv\">msgid</span> <span class=\"s\">&quot;Welcome to my site.&quot;</span>\n<span class=\"nv\">msgstr</span> <span class=\"s\">&quot;&quot;</span>\n</code></pre></div>\n<p>A quick explanation:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">msgid</code> is the translation string, which appears in the source. Don’t\nchange it.</p></li>\n<li><p><code class=\"docutils literal notranslate\">msgstr</code> is where you put the language-specific translation. It starts\nout empty, so it’s your responsibility to change it. Make sure you keep\nthe quotes around your translation.</p></li>\n<li><p>As a convenience, each message includes, in the form of a comment line\nprefixed with <code class=\"docutils literal notranslate\">#</code> and located above the <code class=\"docutils literal notranslate\">msgid</code> line, the filename and\nline number from which the translation string was gleaned.</p></li>\n</ul>\n<p>Long messages are a special case. There, the first string directly after the\n<code class=\"docutils literal notranslate\">msgstr</code> (or <code class=\"docutils literal notranslate\">msgid</code>) is an empty string. Then the content itself will be\nwritten over the next few lines as one string per line. Those strings are\ndirectly concatenated. Don’t forget trailing spaces within the strings;\notherwise, they’ll be tacked together without whitespace!</p>\n<aside class=\"admonition-mind-your-charset admonition\" role=\"note\">\n<p class=\"admonition-title\">Mind your charset</p>\n<p>Due to the way the <code class=\"docutils literal notranslate\">gettext</code> tools work internally and because we want to\nallow non-ASCII source strings in Django’s core and your applications, you\n<strong>must</strong> use UTF-8 as the encoding for your <code class=\"docutils literal notranslate\">.po</code> files (the default when\n<code class=\"docutils literal notranslate\">.po</code> files are created). This means that everybody will be using the\nsame encoding, which is important when Django processes the <code class=\"docutils literal notranslate\">.po</code> files.</p>\n</aside>\n<aside class=\"admonition-fuzzy-entries admonition\" role=\"note\">\n<p class=\"admonition-title\">Fuzzy entries</p>\n<p><a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> sometimes generates translation entries marked as\nfuzzy, e.g. when translations are inferred from previously translated\nstrings. By default, fuzzy entries are <strong>not</strong> processed by\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">compilemessages</code></a>.</p>\n</aside>\n<p>To reexamine all source code and templates for new translation strings and\nupdate all message files for <strong>all</strong> languages, run this:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin makemessages -a\n</code></pre></div>\n</section>\n<section id=\"compiling-message-files\">\n<h3>Compiling message files<a class=\"heading-anchor\" href=\"#compiling-message-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>After you create your message file – and each time you make changes to it –\nyou’ll need to compile it into a more efficient form, for use by <code class=\"docutils literal notranslate\">gettext</code>.\nDo this with the <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages</code></a>\nutility.</p>\n<p>This tool runs over all available <code class=\"docutils literal notranslate\">.po</code> files and creates <code class=\"docutils literal notranslate\">.mo</code> files,\nwhich are binary files optimized for use by <code class=\"docutils literal notranslate\">gettext</code>. In the same directory\nfrom which you ran <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a>, run\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages</code></a> like this:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin compilemessages\n</code></pre></div>\n<p>That’s it. Your translations are ready for use.</p>\n<aside class=\"admonition-working-on-windows admonition\" role=\"note\">\n<p class=\"admonition-title\">Working on Windows?</p>\n<p>If you’re using Windows and need to install the GNU gettext utilities so\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages</code></a> works see\n<a class=\"reference internal\" href=\"#gettext-on-windows\"><span class=\"std std-ref\">gettext on Windows</span></a> for more information.</p>\n</aside>\n<aside class=\"admonition-po-files-encoding-and-bom-usage admonition\" role=\"note\">\n<p class=\"admonition-title\"><code class=\"docutils literal notranslate\">.po</code> files: Encoding and BOM usage.</p>\n<p>Django only supports <code class=\"docutils literal notranslate\">.po</code> files encoded in UTF-8 and without any BOM\n(Byte Order Mark) so if your text editor adds such marks to the beginning of\nfiles by default then you will need to reconfigure it.</p>\n</aside>\n</section>\n<section id=\"troubleshooting-gettext-incorrectly-detects-python-format-in-strings-with-percent-signs\">\n<h3>Troubleshooting: <code class=\"docutils literal notranslate\">gettext()</code> incorrectly detects <code class=\"docutils literal notranslate\">python-format</code> in strings with percent signs<a class=\"heading-anchor\" href=\"#troubleshooting-gettext-incorrectly-detects-python-format-in-strings-with-percent-signs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>In some cases, such as strings with a percent sign followed by a space and a\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#old-string-formatting\" title=\"(Python v3.14에서)\"><span class=\"xref std std-ref\">string conversion type</span></a> (e.g.\n<code class=\"docutils literal notranslate\">_(&quot;10% interest&quot;)</code>), <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\">gettext()</code></a> incorrectly\nflags strings with <code class=\"docutils literal notranslate\">python-format</code>.</p>\n<p>If you try to compile message files with incorrectly flagged strings, you’ll\nget an error message like <code class=\"docutils literal notranslate\">number of format specifications in 'msgid' and\n'msgstr' does not match</code> or <code class=\"docutils literal notranslate\">'msgstr' is not a valid Python format string,\nunlike 'msgid'</code>.</p>\n<p>To workaround this, you can escape percent signs by adding a second percent\nsign:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext <span class=\"k\">as</span> _\n\noutput <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;10</span><span class=\"si\">%%</span><span class=\"s2\"> interest&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Or you can use <code class=\"docutils literal notranslate\">no-python-format</code> so that all percent signs are treated as\nliterals:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"c1\"># xgettext:no-python-format</span>\noutput <span class=\"o\">=</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;10</span><span class=\"si\">% i</span><span class=\"s2\">nterest&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"creating-message-files-from-javascript-source-code\">\n<span id=\"creating-message-files-from-js-code\"></span><h3>Creating message files from JavaScript source code<a class=\"heading-anchor\" href=\"#creating-message-files-from-javascript-source-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You create and update the message files the same way as the other Django\nmessage files – with the <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a>\ntool. The only difference is you need to explicitly specify what in gettext\nparlance is known as a domain in this case the <code class=\"docutils literal notranslate\">djangojs</code> domain, by\nproviding a <code class=\"docutils literal notranslate\">-d djangojs</code> parameter, like this:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>django-admin makemessages -d djangojs -l de\n</code></pre></div>\n<p>This would create or update the message file for JavaScript for German. After\nupdating message files, run <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages</code></a> the same way as you do with normal Django message files.</p>\n</section>\n<section id=\"gettext-on-windows\">\n<span id=\"id3\"></span><h3><code class=\"docutils literal notranslate\">gettext</code> on Windows<a class=\"heading-anchor\" href=\"#gettext-on-windows\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>This is only needed for people who either want to extract message IDs or\ncompile message files (<code class=\"docutils literal notranslate\">.po</code>). Translation work itself involves editing\nexisting files of this type, but if you want to create your own message files,\nor want to test or compile a changed message file, download <a class=\"reference external\" href=\"https://mlocati.github.io/articles/gettext-iconv-windows.html\">a precompiled\nbinary installer</a>.</p>\n<p>You may also use <code class=\"docutils literal notranslate\">gettext</code> binaries you have obtained elsewhere, so long as\nthe <code class=\"docutils literal notranslate\">xgettext --version</code> command works properly. Do not attempt to use Django\ntranslation utilities with a <code class=\"docutils literal notranslate\">gettext</code> package if the command <code class=\"docutils literal notranslate\">xgettext\n--version</code> entered at a Windows command prompt causes a popup window saying\n“<code class=\"docutils literal notranslate\">xgettext.exe</code> has generated errors and will be closed by Windows”.</p>\n</section>\n<section id=\"customizing-the-makemessages-command\">\n<span id=\"customizing-makemessages\"></span><h3>Customizing the <code class=\"docutils literal notranslate\">makemessages</code> command<a class=\"heading-anchor\" href=\"#customizing-the-makemessages-command\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you want to pass additional parameters to <code class=\"docutils literal notranslate\">xgettext</code>, you need to create a\ncustom <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> command and override its <code class=\"docutils literal notranslate\">xgettext_options</code>\nattribute:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.management.commands</span> <span class=\"kn\">import</span> makemessages\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Command</span><span class=\"p\">(</span>makemessages<span class=\"o\">.</span>Command<span class=\"p\">):</span>\n    xgettext_options <span class=\"o\">=</span> makemessages<span class=\"o\">.</span>Command<span class=\"o\">.</span>xgettext_options <span class=\"o\">+</span> <span class=\"p\">[</span><span class=\"s2\">&quot;--keyword=mytrans&quot;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>If you need more flexibility, you could also add a new argument to your custom\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">makemessages</code></a> command:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.management.commands</span> <span class=\"kn\">import</span> makemessages\n\n\n<span class=\"k\">class</span> <span class=\"nc\">Command</span><span class=\"p\">(</span>makemessages<span class=\"o\">.</span>Command<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">add_arguments</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> parser<span class=\"p\">):</span>\n        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>add_arguments<span class=\"p\">(</span>parser<span class=\"p\">)</span>\n        parser<span class=\"o\">.</span>add_argument<span class=\"p\">(</span>\n            <span class=\"s2\">&quot;--extra-keyword&quot;</span><span class=\"p\">,</span>\n            dest<span class=\"o\">=</span><span class=\"s2\">&quot;xgettext_keywords&quot;</span><span class=\"p\">,</span>\n            action<span class=\"o\">=</span><span class=\"s2\">&quot;append&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">handle</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>options<span class=\"p\">):</span>\n        xgettext_keywords <span class=\"o\">=</span> options<span class=\"o\">.</span>pop<span class=\"p\">(</span><span class=\"s2\">&quot;xgettext_keywords&quot;</span><span class=\"p\">)</span>\n        <span class=\"k\">if</span> xgettext_keywords<span class=\"p\">:</span>\n            <span class=\"bp\">self</span><span class=\"o\">.</span>xgettext_options <span class=\"o\">=</span> makemessages<span class=\"o\">.</span>Command<span class=\"o\">.</span>xgettext_options<span class=\"p\">[:]</span> <span class=\"o\">+</span> <span class=\"p\">[</span>\n                <span class=\"s2\">&quot;--keyword=</span><span class=\"si\">%s</span><span class=\"s2\">&quot;</span> <span class=\"o\">%</span> kwd <span class=\"k\">for</span> kwd <span class=\"ow\">in</span> xgettext_keywords\n            <span class=\"p\">]</span>\n        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>handle<span class=\"p\">(</span><span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>options<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"miscellaneous\">\n<h2>기타<a class=\"heading-anchor\" href=\"#miscellaneous\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"the-set-language-redirect-view\">\n<span id=\"set-language-redirect-view\"></span><h3>The <code class=\"docutils literal notranslate\">set_language</code> redirect view<a class=\"heading-anchor\" href=\"#the-set-language-redirect-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.views.i18n.set_language\">\n<span class=\"sig-name descname\">set_language</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.i18n.set_language\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>As a convenience, Django comes with a view,\n<a class=\"reference internal\" href=\"#django.views.i18n.set_language\" title=\"django.views.i18n.set_language\"><code class=\"xref py py-func docutils literal notranslate\">django.views.i18n.set_language()</code></a>, that sets a user’s language preference\nand redirects to a given URL or, by default, back to the previous page.</p>\n<p>Activate this view by adding the following line to your URLconf:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>path<span class=\"p\">(</span><span class=\"s2\">&quot;i18n/&quot;</span><span class=\"p\">,</span> include<span class=\"p\">(</span><span class=\"s2\">&quot;django.conf.urls.i18n&quot;</span><span class=\"p\">)),</span>\n</code></pre></div>\n<p>(Note that this example makes the view available at <code class=\"docutils literal notranslate\">/i18n/setlang/</code>.)</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p>Make sure that you don’t include the above URL within\n<a class=\"reference internal\" href=\"#django.conf.urls.i18n.i18n_patterns\" title=\"django.conf.urls.i18n.i18n_patterns\"><code class=\"xref py py-func docutils literal notranslate\">i18n_patterns()</code></a> - it needs to be\nlanguage-independent itself to work correctly.</p>\n</aside>\n<p>The view expects to be called via the <code class=\"docutils literal notranslate\">POST</code> method, with a <code class=\"docutils literal notranslate\">language</code>\nparameter set in request. The view saves the language choice in a cookie that\nis named <code class=\"docutils literal notranslate\">django_language</code> by default. (The name can be changed through the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_NAME</code></a> setting.)</p>\n<p>After setting the language choice, Django looks for a <code class=\"docutils literal notranslate\">next</code> parameter in the\n<code class=\"docutils literal notranslate\">POST</code> or <code class=\"docutils literal notranslate\">GET</code> data. If that is found and Django considers it to be a safe\nURL (i.e. it doesn’t point to a different host and uses a safe scheme), a\nredirect to that URL will be performed. Otherwise, Django may fall back to\nredirecting the user to the URL from the <code class=\"docutils literal notranslate\">Referer</code> header or, if it is not\nset, to <code class=\"docutils literal notranslate\">/</code>, depending on the nature of the request:</p>\n<ul class=\"simple\">\n<li><p>If the request accepts HTML content (based on its <code class=\"docutils literal notranslate\">Accept</code> HTTP header),\nthe fallback will always be performed.</p></li>\n<li><p>If the request doesn’t accept HTML, the fallback will be performed only if\nthe <code class=\"docutils literal notranslate\">next</code> parameter was set. Otherwise a 204 status code (No Content) will\nbe returned.</p></li>\n</ul>\n<p>Here’s example HTML template code:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">load</span> <span class=\"nv\">i18n</span> <span class=\"cp\">%}</span>\n\n<span class=\"p\">&lt;</span><span class=\"nt\">form</span> <span class=\"na\">action</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">url</span> <span class=\"s1\">&#39;set_language&#39;</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span> <span class=\"na\">method</span><span class=\"o\">=</span><span class=\"s\">&quot;post&quot;</span><span class=\"p\">&gt;</span><span class=\"cp\">{%</span> <span class=\"k\">csrf_token</span> <span class=\"cp\">%}</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">input</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;next&quot;</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">&quot;hidden&quot;</span> <span class=\"na\">value</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{{</span> <span class=\"nv\">redirect_to</span> <span class=\"cp\">}}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">select</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;language&quot;</span><span class=\"p\">&gt;</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">get_current_language</span> <span class=\"k\">as</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">%}</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">get_available_languages</span> <span class=\"k\">as</span> <span class=\"nv\">LANGUAGES</span> <span class=\"cp\">%}</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">get_language_info_list</span> <span class=\"nv\">for</span> <span class=\"nv\">LANGUAGES</span> <span class=\"k\">as</span> <span class=\"nv\">languages</span> <span class=\"cp\">%}</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">language</span> <span class=\"k\">in</span> <span class=\"nv\">languages</span> <span class=\"cp\">%}</span>\n            <span class=\"p\">&lt;</span><span class=\"nt\">option</span> <span class=\"na\">value</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{{</span> <span class=\"nv\">language.code</span> <span class=\"cp\">}}</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">if</span> <span class=\"nv\">language.code</span> <span class=\"o\">==</span> <span class=\"nv\">LANGUAGE_CODE</span> <span class=\"cp\">%}</span> <span class=\"na\">selected</span><span class=\"cp\">{%</span> <span class=\"k\">endif</span> <span class=\"cp\">%}</span><span class=\"p\">&gt;</span>\n                <span class=\"cp\">{{</span> <span class=\"nv\">language.name_local</span> <span class=\"cp\">}}</span> (<span class=\"cp\">{{</span> <span class=\"nv\">language.code</span> <span class=\"cp\">}}</span>)\n            <span class=\"p\">&lt;/</span><span class=\"nt\">option</span><span class=\"p\">&gt;</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">select</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">input</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">&quot;submit&quot;</span> <span class=\"na\">value</span><span class=\"o\">=</span><span class=\"s\">&quot;Go&quot;</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">form</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>In this example, Django looks up the URL of the page to which the user will be\nredirected in the <code class=\"docutils literal notranslate\">redirect_to</code> context variable.</p>\n</section>\n<section id=\"explicitly-setting-the-active-language\">\n<span id=\"id4\"></span><h3>Explicitly setting the active language<a class=\"heading-anchor\" href=\"#explicitly-setting-the-active-language\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You may want to set the active language for the current session explicitly.\nPerhaps a user’s language preference is retrieved from another system, for\nexample. You’ve already been introduced to\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.activate\" title=\"django.utils.translation.activate\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.activate()</code></a>. That applies to the current thread\nonly. To persist the language for the entire session in a cookie, set the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_NAME</code></a> cookie on the response:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf</span> <span class=\"kn\">import</span> settings\n<span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.utils</span> <span class=\"kn\">import</span> translation\n\nuser_language <span class=\"o\">=</span> <span class=\"s2\">&quot;fr&quot;</span>\ntranslation<span class=\"o\">.</span>activate<span class=\"p\">(</span>user_language<span class=\"p\">)</span>\nresponse <span class=\"o\">=</span> HttpResponse<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\nresponse<span class=\"o\">.</span>set_cookie<span class=\"p\">(</span>settings<span class=\"o\">.</span>LANGUAGE_COOKIE_NAME<span class=\"p\">,</span> user_language<span class=\"p\">)</span>\n</code></pre></div>\n<p>You would typically want to use both: <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.activate\" title=\"django.utils.translation.activate\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.activate()</code></a>\nchanges the language for this thread, and setting the cookie makes this\npreference persist in future requests.</p>\n</section>\n<section id=\"using-translations-outside-views-and-templates\">\n<h3>Using translations outside views and templates<a class=\"heading-anchor\" href=\"#using-translations-outside-views-and-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>While Django provides a rich set of i18n tools for use in views and templates,\nit does not restrict the usage to Django-specific code. The Django translation\nmechanisms can be used to translate arbitrary texts to any language that is\nsupported by Django (as long as an appropriate translation catalog exists, of\ncourse). You can load a translation catalog, activate it and translate text to\nlanguage of your choice, but remember to switch back to original language, as\nactivating a translation catalog is done on per-thread basis and such change\nwill affect code running in the same thread.</p>\n<p>예시:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils</span> <span class=\"kn\">import</span> translation\n\n\n<span class=\"k\">def</span> <span class=\"nf\">welcome_translated</span><span class=\"p\">(</span>language<span class=\"p\">):</span>\n    cur_language <span class=\"o\">=</span> translation<span class=\"o\">.</span>get_language<span class=\"p\">()</span>\n    <span class=\"k\">try</span><span class=\"p\">:</span>\n        translation<span class=\"o\">.</span>activate<span class=\"p\">(</span>language<span class=\"p\">)</span>\n        text <span class=\"o\">=</span> translation<span class=\"o\">.</span>gettext<span class=\"p\">(</span><span class=\"s2\">&quot;welcome&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">finally</span><span class=\"p\">:</span>\n        translation<span class=\"o\">.</span>activate<span class=\"p\">(</span>cur_language<span class=\"p\">)</span>\n    <span class=\"k\">return</span> text\n</code></pre></div>\n<p>Calling this function with the value <code class=\"docutils literal notranslate\">'de'</code> will give you <code class=\"docutils literal notranslate\">&quot;Willkommen&quot;</code>,\nregardless of <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a> and language set by middleware.</p>\n<p>Functions of particular interest are\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.get_language\" title=\"django.utils.translation.get_language\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.get_language()</code></a> which returns the language used\nin the current thread, <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.activate\" title=\"django.utils.translation.activate\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.activate()</code></a> which\nactivates a translation catalog for the current thread, and\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.check_for_language\" title=\"django.utils.translation.check_for_language\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.check_for_language()</code></a>\nwhich checks if the given language is supported by Django.</p>\n<p>To help write more concise code, there is also a context manager\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.override\" title=\"django.utils.translation.override\"><code class=\"xref py py-func docutils literal notranslate\">django.utils.translation.override()</code></a> that stores the current language on\nenter and restores it on exit. With it, the above example becomes:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils</span> <span class=\"kn\">import</span> translation\n\n\n<span class=\"k\">def</span> <span class=\"nf\">welcome_translated</span><span class=\"p\">(</span>language<span class=\"p\">):</span>\n    <span class=\"k\">with</span> translation<span class=\"o\">.</span>override<span class=\"p\">(</span>language<span class=\"p\">):</span>\n        <span class=\"k\">return</span> translation<span class=\"o\">.</span>gettext<span class=\"p\">(</span><span class=\"s2\">&quot;welcome&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"language-cookie\">\n<h3>Language cookie<a class=\"heading-anchor\" href=\"#language-cookie\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>A number of settings can be used to adjust language cookie options:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_NAME</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_AGE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_AGE</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_DOMAIN\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_DOMAIN</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_HTTPONLY\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_HTTPONLY</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_PATH</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_SAMESITE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_SAMESITE</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_SECURE</code></a></p></li>\n</ul>\n</section>\n</section>\n<section id=\"implementation-notes\">\n<h2>Implementation notes<a class=\"heading-anchor\" href=\"#implementation-notes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"specialties-of-django-translation\">\n<span id=\"specialties-of-django-i18n\"></span><h3>Specialties of Django translation<a class=\"heading-anchor\" href=\"#specialties-of-django-translation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django’s translation machinery uses the standard <code class=\"docutils literal notranslate\">gettext</code> module that comes\nwith Python. If you know <code class=\"docutils literal notranslate\">gettext</code>, you might note these specialties in the\nway Django does translation:</p>\n<ul class=\"simple\">\n<li><p>The string domain is <code class=\"docutils literal notranslate\">django</code> or <code class=\"docutils literal notranslate\">djangojs</code>. This string domain is\nused to differentiate between different programs that store their data\nin a common message-file library (usually <code class=\"docutils literal notranslate\">/usr/share/locale/</code>). The\n<code class=\"docutils literal notranslate\">django</code> domain is used for Python and template translation strings\nand is loaded into the global translation catalogs. The <code class=\"docutils literal notranslate\">djangojs</code>\ndomain is only used for JavaScript translation catalogs to make sure\nthat those are as small as possible.</p></li>\n<li><p>Django doesn’t use <code class=\"docutils literal notranslate\">xgettext</code> alone. It uses Python wrappers around\n<code class=\"docutils literal notranslate\">xgettext</code> and <code class=\"docutils literal notranslate\">msgfmt</code>. This is mostly for convenience.</p></li>\n</ul>\n</section>\n<section id=\"how-django-discovers-language-preference\">\n<span id=\"id5\"></span><h3>How Django discovers language preference<a class=\"heading-anchor\" href=\"#how-django-discovers-language-preference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Once you’ve prepared your translations – or, if you want to use the\ntranslations that come with Django – you’ll need to activate translation for\nyour app.</p>\n<p>Behind the scenes, Django has a very flexible model of deciding which language\nshould be used – installation-wide, for a particular user, or both.</p>\n<p>To set an installation-wide language preference, set <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a>.\nDjango uses this language as the default translation – the final attempt if no\nbetter matching translation is found through one of the methods employed by the\nlocale middleware (see below).</p>\n<p>If all you want is to run Django with your native language all you need to do\nis set <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a> and make sure the corresponding <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-message-file\"><span class=\"xref std std-term\">message\nfiles</span></a> and their compiled versions (<code class=\"docutils literal notranslate\">.mo</code>) exist.</p>\n<p>If you want to let each individual user specify which language they\nprefer, then you also need to use the <code class=\"docutils literal notranslate\">LocaleMiddleware</code>.\n<code class=\"docutils literal notranslate\">LocaleMiddleware</code> enables language selection based on data from the request.\nIt customizes content for each user.</p>\n<p>To use <code class=\"docutils literal notranslate\">LocaleMiddleware</code>, add\n<code class=\"docutils literal notranslate\">'django.middleware.locale.LocaleMiddleware'</code> to your <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a>\nsetting. Because middleware order matters, follow these guidelines:</p>\n<ul class=\"simple\">\n<li><p>Make sure it’s one of the first middleware installed.</p></li>\n<li><p>It should come after <code class=\"docutils literal notranslate\">SessionMiddleware</code>, because <code class=\"docutils literal notranslate\">LocaleMiddleware</code>\nmakes use of session data. And it should come before <code class=\"docutils literal notranslate\">CommonMiddleware</code>\nbecause <code class=\"docutils literal notranslate\">CommonMiddleware</code> needs an activated language in order\nto resolve the requested URL.</p></li>\n<li><p>If you use <code class=\"docutils literal notranslate\">CacheMiddleware</code>, put <code class=\"docutils literal notranslate\">LocaleMiddleware</code> after it.</p></li>\n</ul>\n<p>For example, your <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> might look like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MIDDLEWARE <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django.contrib.sessions.middleware.SessionMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.middleware.locale.LocaleMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.middleware.common.CommonMiddleware&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>(For more on middleware, see the <a class=\"reference internal\" href=\"/ko/6.0/topics/http/middleware/\"><span class=\"doc\">middleware documentation</span></a>.)</p>\n<p><code class=\"docutils literal notranslate\">LocaleMiddleware</code> tries to determine the user’s language preference by\nfollowing this algorithm:</p>\n<ul>\n<li><p>First, it looks for the language prefix in the requested URL. This is\nonly performed when you are using the <code class=\"docutils literal notranslate\">i18n_patterns</code> function in your\nroot URLconf. See <a class=\"reference internal\" href=\"#url-internationalization\"><span class=\"std std-ref\">Internationalization: in URL patterns</span></a> for more information\nabout the language prefix and how to internationalize URL patterns.</p></li>\n<li><p>Failing that, it looks for a cookie.</p>\n<p>The name of the cookie used is set by the <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_COOKIE_NAME</code></a>\nsetting. (The default name is <code class=\"docutils literal notranslate\">django_language</code>.)</p>\n</li>\n<li><p>Failing that, it looks at the <code class=\"docutils literal notranslate\">Accept-Language</code> HTTP header. This\nheader is sent by your browser and tells the server which language(s) you\nprefer, in order by priority. Django tries each language in the header\nuntil it finds one with available translations.</p></li>\n<li><p>Failing that, it uses the global <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a> setting.</p></li>\n</ul>\n<p id=\"locale-middleware-notes\">각주:</p>\n<ul>\n<li><p>In each of these places, the language preference is expected to be in the\nstandard <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-language-code\"><span class=\"xref std std-term\">language format</span></a>, as a string. For example,\nBrazilian Portuguese is <code class=\"docutils literal notranslate\">pt-br</code>.</p></li>\n<li><p>If a base language is available but the sublanguage specified is not,\nDjango uses the base language. For example, if a user specifies <code class=\"docutils literal notranslate\">de-at</code>\n(Austrian German) but Django only has <code class=\"docutils literal notranslate\">de</code> available, Django uses\n<code class=\"docutils literal notranslate\">de</code>.</p></li>\n<li><p>Only languages listed in the <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGES</code></a> setting can be selected.\nIf you want to restrict the language selection to a subset of provided\nlanguages (because your application doesn’t provide all those languages),\nset <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGES</code></a> to a list of languages. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>LANGUAGES <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;de&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;German&quot;</span><span class=\"p\">)),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;English&quot;</span><span class=\"p\">)),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>This example restricts languages that are available for automatic\nselection to German and English (and any sublanguage, like <code class=\"docutils literal notranslate\">de-ch</code> or\n<code class=\"docutils literal notranslate\">en-us</code>).</p>\n</li>\n<li><p>If you define a custom <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGES</code></a> setting, as explained in the\nprevious bullet, you can mark the language names as translation strings\n– but use <a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\">gettext_lazy()</code></a> instead of\n<a class=\"reference internal\" href=\"/ko/6.0/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\">gettext()</code></a> to avoid a circular import.</p>\n<p>샘플 설정 파일이 있습니다:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.utils.translation</span> <span class=\"kn\">import</span> gettext_lazy <span class=\"k\">as</span> _\n\nLANGUAGES <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;de&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;German&quot;</span><span class=\"p\">)),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">,</span> _<span class=\"p\">(</span><span class=\"s2\">&quot;English&quot;</span><span class=\"p\">)),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n</li>\n</ul>\n<p>Once <code class=\"docutils literal notranslate\">LocaleMiddleware</code> determines the user’s preference, it makes this\npreference available as <code class=\"docutils literal notranslate\">request.LANGUAGE_CODE</code> for each\n<a class=\"reference internal\" href=\"/ko/6.0/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\">HttpRequest</code></a>. Feel free to read this value in your view\ncode. Here’s an example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n\n\n<span class=\"k\">def</span> <span class=\"nf\">hello_world</span><span class=\"p\">(</span>request<span class=\"p\">,</span> count<span class=\"p\">):</span>\n    <span class=\"k\">if</span> request<span class=\"o\">.</span>LANGUAGE_CODE <span class=\"o\">==</span> <span class=\"s2\">&quot;de-at&quot;</span><span class=\"p\">:</span>\n        <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;You prefer to read Austrian German.&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;You prefer to read another language.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Note that, with static (middleware-less) translation, the language is in\n<code class=\"docutils literal notranslate\">settings.LANGUAGE_CODE</code>, while with dynamic (middleware) translation, it’s\nin <code class=\"docutils literal notranslate\">request.LANGUAGE_CODE</code>.</p>\n</section>\n<section id=\"how-django-discovers-translations\">\n<span id=\"id6\"></span><h3>How Django discovers translations<a class=\"heading-anchor\" href=\"#how-django-discovers-translations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>At runtime, Django builds an in-memory unified catalog of\nliterals-translations. To achieve this it looks for translations by following\nthis algorithm regarding the order in which it examines the different file\npaths to load the compiled <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-message-file\"><span class=\"xref std std-term\">message files</span></a> (<code class=\"docutils literal notranslate\">.mo</code>) and\nthe precedence of multiple translations for the same literal:</p>\n<ol class=\"arabic simple\">\n<li><p>The directories listed in <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> have the highest\nprecedence, with the ones appearing first having higher precedence than\nthe ones appearing later.</p></li>\n<li><p>Then, it looks for and uses if it exists a <code class=\"docutils literal notranslate\">locale</code> directory in each\nof the installed apps listed in <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a>. The ones\nappearing first have higher precedence than the ones appearing later.</p></li>\n<li><p>Finally, the Django-provided base translation in\n<a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.0.x/django/conf/locale\">django/conf/locale</a> is used as a fallback.</p></li>\n</ol>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">더 보기</p>\n<p>The translations for literals included in JavaScript assets are looked up\nfollowing a similar but not identical algorithm. See\n<a class=\"reference internal\" href=\"#django.views.i18n.JavaScriptCatalog\" title=\"django.views.i18n.JavaScriptCatalog\"><code class=\"xref py py-class docutils literal notranslate\">JavaScriptCatalog</code></a> for more details.</p>\n<p>You can also put <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/formatting/#custom-format-files\"><span class=\"std std-ref\">custom format files</span></a> in the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> directories if you also set\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-FORMAT_MODULE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">FORMAT_MODULE_PATH</code></a>.</p>\n</aside>\n<p>In all cases the name of the directory containing the translation is expected\nto be named using <a class=\"reference internal\" href=\"/ko/6.0/topics/i18n/#term-locale-name\"><span class=\"xref std std-term\">locale name</span></a> notation. E.g. <code class=\"docutils literal notranslate\">de</code>, <code class=\"docutils literal notranslate\">pt_BR</code>,\n<code class=\"docutils literal notranslate\">es_AR</code>, etc. Untranslated strings for territorial language variants use the\ntranslations of the generic language. For example, untranslated <code class=\"docutils literal notranslate\">pt_BR</code>\nstrings use <code class=\"docutils literal notranslate\">pt</code> translations.</p>\n<p>This way, you can write applications that include their own translations, and\nyou can override base translations in your project. Or, you can build a big\nproject out of several apps and put all translations into one big common\nmessage file specific to the project you are composing. The choice is yours.</p>\n<p>All message file repositories are structured the same way. They are:</p>\n<ul class=\"simple\">\n<li><p>All paths listed in <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> in your settings file are\nsearched for <code class=\"docutils literal notranslate\">&lt;language&gt;/LC_MESSAGES/django.(po|mo)</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">$APPPATH/locale/&lt;language&gt;/LC_MESSAGES/django.(po|mo)</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">$PYTHONPATH/django/conf/locale/&lt;language&gt;/LC_MESSAGES/django.(po|mo)</code></p></li>\n</ul>\n<p>To create message files, you use the\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-makemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin makemessages</code></a> tool. And you use\n<a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages</code></a> to produce the binary\n<code class=\"docutils literal notranslate\">.mo</code> files that are used by <code class=\"docutils literal notranslate\">gettext</code>.</p>\n<p>You can also run <a class=\"reference internal\" href=\"/ko/6.0/ref/django-admin/#django-admin-compilemessages\"><code class=\"xref std std-djadmin docutils literal notranslate\">django-admin compilemessages\n--settings=path.to.settings</code></a> to make the compiler process all\nthe directories in your <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\">LOCALE_PATHS</code></a> setting.</p>\n</section>\n<section id=\"using-a-non-english-base-language\">\n<h3>Using a non-English base language<a class=\"heading-anchor\" href=\"#using-a-non-english-base-language\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django makes the general assumption that the original strings in a translatable\nproject are written in English. You can choose another language, but you must\nbe aware of certain limitations:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">gettext</code> only provides two plural forms for the original messages, so you\nwill also need to provide a translation for the base language to include all\nplural forms if the plural rules for the base language are different from\nEnglish.</p></li>\n<li><p>When an English variant is activated and English strings are missing, the\nfallback language will not be the <a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a> of the project,\nbut the original strings. For example, an English user visiting a site with\n<a class=\"reference internal\" href=\"/ko/6.0/ref/settings/#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\">LANGUAGE_CODE</code></a> set to Spanish and original strings written in\nRussian will see Russian text rather than Spanish.</p></li>\n</ul>\n</section>\n</section>","rootId":"translation","toc":[{"title":"개요","anchor":"overview","children":[]},{"title":"Internationalization: in Python code","anchor":"internationalization-in-python-code","children":[{"title":"Standard translation","anchor":"standard-translation","children":[]},{"title":"Comments for translators","anchor":"comments-for-translators","children":[]},{"title":"Marking strings as no-op","anchor":"marking-strings-as-no-op","children":[]},{"title":"Pluralization","anchor":"pluralization","children":[]},{"title":"Contextual markers","anchor":"contextual-markers","children":[]},{"title":"Lazy translation","anchor":"lazy-translation","children":[{"title":"Model fields and relationships verbose_name and help_text option values","anchor":"model-fields-and-relationships-verbose-name-and-help-text-option-values","children":[]},{"title":"Model verbose names values","anchor":"model-verbose-names-values","children":[]},{"title":"Model methods description argument to the @display decorator","anchor":"model-methods-description-argument-to-the-display-decorator","children":[]}]},{"title":"Working with lazy translation objects","anchor":"working-with-lazy-translation-objects","children":[{"title":"Lazy translations and plural","anchor":"lazy-translations-and-plural","children":[]},{"title":"Formatting strings: format_lazy()","anchor":"formatting-strings-format-lazy","children":[]},{"title":"Other uses of lazy in delayed translations","anchor":"other-uses-of-lazy-in-delayed-translations","children":[]}]},{"title":"Localized names of languages","anchor":"localized-names-of-languages","children":[]}]},{"title":"Internationalization: in template code","anchor":"internationalization-in-template-code","children":[{"title":"translate template tag","anchor":"translate-template-tag","children":[]},{"title":"blocktranslate template tag","anchor":"blocktranslate-template-tag","children":[]},{"title":"String literals passed to tags and filters","anchor":"string-literals-passed-to-tags-and-filters","children":[]},{"title":"Comments for translators in templates","anchor":"comments-for-translators-in-templates","children":[]},{"title":"Switching language in templates","anchor":"switching-language-in-templates","children":[]},{"title":"Other tags","anchor":"other-tags","children":[{"title":"get_available_languages","anchor":"get-available-languages","children":[]},{"title":"get_current_language","anchor":"get-current-language","children":[]},{"title":"get_current_language_bidi","anchor":"get-current-language-bidi","children":[]},{"title":"i18n context processor","anchor":"i18n-context-processor","children":[]},{"title":"get_language_info","anchor":"get-language-info","children":[]},{"title":"get_language_info_list","anchor":"get-language-info-list","children":[]},{"title":"템플릿 필터","anchor":"template-filters","children":[]}]}]},{"title":"Internationalization: in JavaScript code","anchor":"internationalization-in-javascript-code","children":[{"title":"The JavaScriptCatalog view","anchor":"module-django.views.i18n","children":[]},{"title":"Using the JavaScript translation catalog","anchor":"using-the-javascript-translation-catalog","children":[{"title":"gettext","anchor":"gettext","children":[]},{"title":"ngettext","anchor":"ngettext","children":[]},{"title":"interpolate","anchor":"interpolate","children":[]},{"title":"get_format","anchor":"get-format","children":[]},{"title":"gettext_noop","anchor":"gettext-noop","children":[]},{"title":"pgettext","anchor":"pgettext","children":[]},{"title":"npgettext","anchor":"npgettext","children":[]},{"title":"pluralidx","anchor":"pluralidx","children":[]}]},{"title":"The JSONCatalog view","anchor":"the-jsoncatalog-view","children":[]},{"title":"Note on performance","anchor":"note-on-performance","children":[]}]},{"title":"Internationalization: in URL patterns","anchor":"module-django.conf.urls.i18n","children":[{"title":"Language prefix in URL patterns","anchor":"language-prefix-in-url-patterns","children":[]},{"title":"Translating URL patterns","anchor":"translating-url-patterns","children":[]},{"title":"Reversing in templates","anchor":"reversing-in-templates","children":[]}]},{"title":"Localization: how to create language files","anchor":"localization-how-to-create-language-files","children":[{"title":"Message files","anchor":"message-files","children":[]},{"title":"Compiling message files","anchor":"compiling-message-files","children":[]},{"title":"Troubleshooting: gettext() incorrectly detects python-format in strings with percent signs","anchor":"troubleshooting-gettext-incorrectly-detects-python-format-in-strings-with-percent-signs","children":[]},{"title":"Creating message files from JavaScript source code","anchor":"creating-message-files-from-javascript-source-code","children":[]},{"title":"gettext on Windows","anchor":"gettext-on-windows","children":[]},{"title":"Customizing the makemessages command","anchor":"customizing-the-makemessages-command","children":[]}]},{"title":"기타","anchor":"miscellaneous","children":[{"title":"The set_language redirect view","anchor":"the-set-language-redirect-view","children":[]},{"title":"Explicitly setting the active language","anchor":"explicitly-setting-the-active-language","children":[]},{"title":"Using translations outside views and templates","anchor":"using-translations-outside-views-and-templates","children":[]},{"title":"Language cookie","anchor":"language-cookie","children":[]}]},{"title":"Implementation notes","anchor":"implementation-notes","children":[{"title":"Specialties of Django translation","anchor":"specialties-of-django-translation","children":[]},{"title":"How Django discovers language preference","anchor":"how-django-discovers-language-preference","children":[]},{"title":"How Django discovers translations","anchor":"how-django-discovers-translations","children":[]},{"title":"Using a non-English base language","anchor":"using-a-non-english-base-language","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Django 사용하기","url":"/ko/6.0/topics/"},{"docname":"topics/i18n/index","title":"국제화와 현지화","url":"/ko/6.0/topics/i18n/"}],"prev":{"docname":"topics/i18n/index","title":"국제화와 현지화","url":"/ko/6.0/topics/i18n/"},"next":{"docname":"topics/i18n/formatting","title":"Format localization","url":"/ko/6.0/topics/i18n/formatting/"},"formats":{"html":"/ko/6.0/topics/i18n/translation/","markdown":"/ko/6.0/topics/i18n/translation.md","json":"/ko/6.0/topics/i18n/translation.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/topics/i18n/translation.txt","official":"https://docs.djangoproject.com/ko/6.0/topics/i18n/translation/","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","1.11"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}