{"id":75936,"date":"2020-01-20T12:35:43","date_gmt":"2020-01-20T07:05:43","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=75936"},"modified":"2024-04-12T14:17:42","modified_gmt":"2024-04-12T08:47:42","slug":"specifying-translation-strings-in-template-code","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/","title":{"rendered":"Specifying Translation Strings in Template Code"},"content":{"rendered":"<p>Translations in Django templates uses two template tags and a slightly different syntax than in Python code. To give your template access to these tags, put {% load i18n %} toward the top of your template. As with all template tags, this tag needs to be loaded in all templates which use translations, even those templates that extend from other templates which have already loaded the i18n tag.<\/p>\n<p>trans Template Tag<br>\nThe {% trans %} template tag translates either a constant string (enclosed in single or double quotes) or variable content:<\/p>\n<p>&lt;title&gt;{% trans &#8220;This is the title.&#8221;<br>\n%}&lt;\/title&gt;<br>\n&lt;title&gt;{% trans myvar %}&lt;\/title&gt;<\/p>\n<p>If the noop option is present, variable lookup still takes place but the translation is skipped. This is useful when stubbing out content that will require translation in the future:<\/p>\n<p>&lt;title&gt;{% trans &#8220;myvar&#8221; noop %}&lt;\/title&gt;<\/p>\n<p>Internally, inline translations use an ugettext() call.<\/p>\n<p>In case a template variable (myvar above) is passed to the tag, the tag will first resolve such variable to a string at run-time and then look up that string in the message catalogs.<\/p>\n<p>It\u2019s not possible to mix a template variable inside a string within {% trans %}. If your translations require strings with variables (placeholders), use {% blocktrans %} instead. If you\u2019d like to retrieve a translated string without displaying it, you can use the following syntax:<\/p>\n<p>{% trans &#8220;This is the title&#8221; as the_title %}<\/p>\n<p>In practice you\u2019ll use this to get strings that are used in multiple places or should be used as arguments for other template tags or filters:<\/p>\n<p>{% trans &#8220;starting point&#8221; as start %}<br>\n{% trans &#8220;end point&#8221; as end %}<br>\n{% trans &#8220;La Grande Boucle&#8221; as race %}<\/p>\n<p>&lt;h1&gt;<br>\n&lt;a href=&#8221;\/&#8221; title=&#8221;{% blocktrans %}Back to &#8216;{{ race }}&#8217;<br>\nhomepage{% endblocktrans %}&#8221;&gt;{{ race }}&lt;\/a&gt;<br>\n&lt;\/h1&gt;<br>\n&lt;p&gt;<br>\n{% for stage in tour_stages %}<br>\n{% cycle start end %}: {{ stage }}{% if forloop.counter|divisibleby:2 %}&lt;br \/&gt;{% \\<br>\nelse %}, {% endif %}<br>\n{% endfor %}<br>\n&lt;\/p&gt;<\/p>\n<p>{% trans %} also supports contextual markers using the context keyword:<\/p>\n<p>{% trans &#8220;May&#8221; context &#8220;month name&#8221; %}<br>\nblocktrans Template Tag<br>\nThe blocktrans tag allows you to mark complex sentences consisting of literals and variable content for translation by making use of placeholders:<\/p>\n<p>{% blocktrans %}This string will have {{ value }} inside.{% endblocktrans %}<\/p>\n<p><strong>To translate a template expression<\/strong> \u2013 say, accessing object attributes or using template filters \u2013 you need to bind the expression to a local variable for use within the translation block. Examples:<\/p>\n<p>{% blocktrans with amount=article.price %}<br>\nThat will cost $ {{ amount }}.<br>\n{% endblocktrans %}<\/p>\n<p>{% blocktrans with myvar=value|filter %}<br>\nThis will have {{ myvar }} inside.<br>\n{% endblocktrans %}<\/p>\n<p>You can use multiple expressions inside a single blocktrans tag:<\/p>\n<p>{% blocktrans with book_t=book|title author_t=author|title %}<br>\nThis is {{ book_t }} by {{ author_t }}<br>\n{% endblocktrans %}<\/p>\n<p>The previous more verbose format is still supported:<\/p>\n<p>{% blocktrans with book|title as book_t and author|title as author_t %}<\/p>\n<p>Other block tags (for example {% for %} or {% if %}) are not allowed inside a blocktrans tag.<\/p>\n<p>If resolving one of the block arguments fails, blocktrans will fall back to the default language by deactivating the currently active language temporarily with the deactivate_all() function.<\/p>\n<p>This tag also provides for pluralization. To use it:<\/p>\n<ul>\n<li>&nbsp;Designate and bind a counter value with the name count. This value will be the one used to select the right plural form.<\/li>\n<li>Specify both the singular and plural forms separating them with the {% plural %} tag within the {% blocktrans %} and {% endblocktrans %} tags.<\/li>\n<\/ul>\n<p>An example:<br>\n{% blocktrans count counter=list|length %}<br>\nThere is only one {{ name }} object.<br>\n{% plural %}<br>\nThere are {{ counter }} {{ name }} objects.<br>\n{% endblocktrans %}<\/p>\n<p>A more complex example:<br>\n{% blocktrans with amount=article.price count years=i.length %}<br>\nThat will cost $ {{ amount }} per year.<br>\n{% plural %}<br>\nThat will cost $ {{ amount }} per {{ years }} years.<br>\n{% endblocktrans %}<\/p>\n<p>When you use both the pluralization feature and bind values to local variables in addition to the counter value, keep in mind that the blocktrans construct is internally converted to an ungettext call. This means the same notes regarding ungettext variables apply.<\/p>\n<p>Reverse URL lookups cannot be carried out within the blocktrans and should be retrieved (and stored) beforehand:<\/p>\n<p>{% url &#8216;path.to.view&#8217; arg arg2 as the_url %}<br>\n{% blocktrans %}<br>\nThis is a URL: {{ the_url }}<br>\n{% endblocktrans %}<\/p>\n<p>{% blocktrans %} also supports contextual using the context keyword:<\/p>\n<p>{% blocktrans with name=user.username context &#8220;greeting&#8221; %}<br>\nHi {{ name }}{% endblocktrans %}<\/p>\n<p>Another feature {% blocktrans %} supports is the trimmed option. This option will remove newline characters from the beginning and the end of the content of the {% blocktrans %} tag, replace any whitespace at the beginning and end of a line and merge all lines into one using a space character to separate them.<\/p>\n<p>This is quite useful for indenting the content of a {% blocktrans %} tag without having the indentation characters end up in the corresponding entry in the PO file, which makes the translation process easier.<\/p>\n<p>For instance, the following {% blocktrans %} tag:<\/p>\n<p>{% blocktrans trimmed %}<br>\nFirst sentence.<br>\nSecond paragraph.<br>\n{% endblocktrans %}<\/p>\n<p>will result in the entry &#8220;First sentence. Second paragraph.&#8221; in the PO file, compared to &#8220;\\n First sentence.\\n Second sentence.\\n&#8221;, if the trimmed option had not been specified.<br>\nString Literals Passed to Tags and Filters<br>\nYou can translate string literals passed as arguments to tags and filters by using the familiar _() syntax:<br>\n{% some_tag _(&#8220;Page not found&#8221;) value|yesno:_(&#8220;yes,no&#8221;) %}<\/p>\n<p>In this case, both the tag and the filter will see the translated string, so they don\u2019t need to be aware of translations.<\/p>\n<p>In this example, the translation infrastructure will be passed the string \u201cyes,no\u201d, not the individual strings \u201cyes\u201d and \u201cno\u201d. The translated string will need to contain the comma so that the filter parsing code knows how to split up the arguments. For example, a German translator might translate the string \u201cyes,no\u201d as \u201cja,nein\u201d (keeping the comma intact).<\/p>\n<h3>Comments for Translators in Templates<\/h3>\n<p>Just like with Python code, these notes for translators can be specified using comments, either with the comment tag:<\/p>\n<p>{% comment %}Translators: View verb{% endcomment %}<br>\n{% trans &#8220;View&#8221; %}<\/p>\n<p>{% comment %}Translators: Short intro blurb{% endcomment %}<br>\n&lt;p&gt;{% blocktrans %}<br>\nA multiline translatable literal.<br>\n{% endblocktrans %}<br>\n&lt;\/p&gt;<\/p>\n<p>or with the {# \u2026 #} one-line comment constructs:<\/p>\n<p>{# Translators: Label of a button that triggers search #}<br>\n&lt;button type=&#8221;submit&#8221;&gt;{% trans &#8220;Go&#8221; %}&lt;\/button&gt;<\/p>\n<p>{# Translators: This is a text of the base template #}<br>\n{% blocktrans %}Ambiguous translatable block of text{% endblocktrans %}<\/p>\n<p>Just for completeness, these are the corresponding fragments of the resulting .po file:<\/p>\n<p>#. Translators: View verb<br>\n# path\/to\/template\/file.html:10<br>\nmsgid &#8220;View&#8221;<br>\nmsgstr &#8220;&#8221;<\/p>\n<p>#. Translators: Short intro blurb<br>\n# path\/to\/template\/file.html:13<br>\nmsgid &#8220;&#8221;<br>\n&#8220;A multiline translatable&#8221;<br>\n&#8220;literal.&#8221;<br>\nmsgstr &#8220;&#8221;<\/p>\n<p># &#8230;<\/p>\n<p>#. Translators: Label of a button that triggers search<br>\n# path\/to\/template\/file.html:100<br>\nmsgid &#8220;Go&#8221;<br>\nmsgstr &#8220;&#8221;<\/p>\n<p>#. Translators: This is a text of the base template<br>\n# path\/to\/template\/file.html:103<br>\nmsgid &#8220;Ambiguous translatable block of text&#8221;<br>\nmsgstr &#8220;&#8221;<\/p>\n<h3>Switching Language in Templates<\/h3>\n<p>If you want to select a language within a template, you can use the language template tag:<\/p>\n<p>{% load i18n %}<\/p>\n<p>{% get_current_language as LANGUAGE_CODE %}<br>\n&lt;!&#8211; Current language: {{ LANGUAGE_CODE }} &#8211;&gt;<br>\n&lt;p&gt;{% trans &#8220;Welcome to our page&#8221; %}&lt;\/p&gt;<\/p>\n<p>{% language &#8216;en&#8217; %}<\/p>\n<p>{% get_current_language as LANGUAGE_CODE %}<br>\n&lt;!&#8211; Current language: {{ LANGUAGE_CODE }} &#8211;&gt;<br>\n&lt;p&gt;{% trans &#8220;Welcome to our page&#8221; %}&lt;\/p&gt;<\/p>\n<p>{% endlanguage %}<\/p>\n<p>While the first occurrence of Welcome to our page uses the current language, the second will always be in English.<\/p>\n<h3>Other Tags<\/h3>\n<p>These tags also require a {% load i18n %}.<\/p>\n<ul>\n<li>&nbsp;{% get_available_languages as LANGUAGES %} returns a list of tuples in which the first element is the language code and the second is the language name (translated into the currently active locale).<\/li>\n<li>{% get_current_language as LANGUAGE_CODE %} returns the current user\u2019s preferred language, as a string.<br>\nExample: en-us.<\/li>\n<li>{% get_current_language_bidi as LANGUAGE_BIDI %} returns the current locale\u2019s direction. If True, it\u2019s a right-to-left language, e.g.: Hebrew, Arabic. If False it\u2019s a left-to-right language, e.g.: English, French, German etc.<\/li>\n<\/ul>\n<p>If you enable the django.template.context_processors.i18n context processor then each RequestContext will have access to LANGUAGES, LANGUAGE_CODE, and LANGUAGE_BIDI as defined above.<\/p>\n<p>The i18n context processor is not enabled by default for new projects.<\/p>\n<p>You can also retrieve information about any of the available languages using provided template tags and filters. To get information about a single language, use the {% get_language_info %} tag:<\/p>\n<p>{% get_language_info for LANGUAGE_CODE as lang %}<br>\n{% get_language_info for &#8220;pl&#8221; as lang %}<\/p>\n<p>You can then access the information:<\/p>\n<p>Language code: {{ lang.code }}&lt;br \/&gt;<br>\nName of language: {{ lang.name_local }}&lt;br \/&gt;<br>\nName in English: {{ lang.name }}&lt;br \/&gt;<br>\nBi-directional: {{ lang.bidi }}<\/p>\n<p>You can also use the {% get_language_info_list %} template tag to retrieve information for a list of languages (e.g. active languages as specified in LANGUAGES).<\/p>\n<p>In addition to LANGUAGES style list of tuples, {% get_language_info_list %} supports simple lists of language codes. If you do this in your view:<\/p>\n<p>context = {&#8216;available_languages&#8217;: [&#8216;en&#8217;, &#8216;es&#8217;, &#8216;fr&#8217;]}<br>\nreturn render(request, &#8216;mytemplate.html&#8217;, context)<\/p>\n<p>you can iterate over those languages in the template:<\/p>\n<p>{% get_language_info_list for available_languages as langs %}<br>\n{% for lang in langs %} &#8230; {% endfor %}<\/p>\n<p>There are also simple filters available for convenience:<br>\n{{ LANGUAGE_CODE|language_name }} (German)<br>\n{{ LANGUAGE_CODE|language_name_local }} (Deutsch)<br>\n{{ LANGUAGE_CODE|language_bidi }} (False)<\/p>\n<h3>Internationalization in URL Patterns<\/h3>\n<p>Django provides two mechanisms to internationalize URL patterns:<\/p>\n<ul>\n<li>&nbsp;Adding the language prefix to the root of the URL patterns to make it possible for LocaleMiddleware to detect the language to activate from the requested URL.<\/li>\n<li>Making URL patterns themselves translatable via the django.utils.translation.ugettext_lazy() function.<\/li>\n<\/ul>\n<p>Using either one of these features requires that an active language be set for each request; in other words, you need to have django.middleware.locale.LocaleMiddleware in your MIDDLEWARE_CLASSES setting.<\/p>\n<p><strong>Language Prefix in URL Patterns<\/strong> &#8211; This function can be used in your root URLconf and Django will automatically prepend the current active language code to all url patterns defined within i18n_patterns(). Example URL patterns:<\/p>\n<p>from django.conf.urls import include, url<br>\nfrom django.conf.urls.i18n import i18n_patterns<br>\nfrom about import views as about_views<br>\nfrom news import views as news_views<br>\nfrom sitemap.views import sitemap<\/p>\n<p>urlpatterns = [<br>\nurl(r&#8217;^sitemap\\.xml$&#8217;, sitemap, name=&#8217;sitemap_xml&#8217;),<br>\n]\n<p>news_patterns = [<br>\nurl(r&#8217;^$&#8217;, news_views.index, name=&#8217;index&#8217;),<br>\nurl(r&#8217;^category\/(?P&lt;slug&gt;[\\w-]+)\/$&#8217;,<br>\nnews_views.category,<br>\nname=&#8217;category&#8217;),<br>\nurl(r&#8217;^(?P&lt;slug&gt;[\\w-]+)\/$&#8217;, news_views.details, name=&#8217;detail&#8217;),<br>\n]\n<p>urlpatterns += i18n_patterns(<br>\nurl(r&#8217;^about\/$&#8217;, about_views.main, name=&#8217;about&#8217;),<br>\nurl(r&#8217;^news\/&#8217;, include(news_patterns, namespace=&#8217;news&#8217;)),<br>\n)<\/p>\n<p>After defining these URL patterns, Django will automatically add the language prefix to the URL patterns that were added by the i18n_patterns function. Example:<\/p>\n<p>&gt;&gt;&gt; from django.core.urlresolvers import reverse<br>\n&gt;&gt;&gt; from django.utils.translation import activate<br>\n&gt;&gt;&gt; activate(&#8216;en&#8217;)<br>\n&gt;&gt;&gt; reverse(&#8216;sitemap_xml&#8217;)<br>\n&#8216;\/sitemap.xml&#8217;<br>\n&gt;&gt;&gt; reverse(&#8216;news:index&#8217;)<br>\n&#8216;\/en\/news\/&#8217;<\/p>\n<p>&gt;&gt;&gt; activate(&#8216;nl&#8217;)<br>\n&gt;&gt;&gt; reverse(&#8216;news:detail&#8217;, kwargs={&#8216;slug&#8217;: &#8216;news-slug&#8217;})<br>\n&#8216;\/nl\/news\/news-slug\/&#8217;<\/p>\n<p>i18n_patterns() is only allowed in your root URLconf. Using it within an included URLconf will throw an ImproperlyConfigured exception.<\/p>\n<p><strong>Translating URL Patterns<\/strong> &#8211; URL patterns can also be marked translatable using the ugettext_lazy() function. Example:<\/p>\n<p>from django.conf.urls import include, url<br>\nfrom django.conf.urls.i18n import i18n_patterns<br>\nfrom django.utils.translation import ugettext_lazy as _<\/p>\n<p>from about import views as about_views<br>\nfrom news import views as news_views<br>\nfrom sitemaps.views import sitemap<\/p>\n<p>urlpatterns = [<br>\nurl(r&#8217;^sitemap\\.xml$&#8217;, sitemap, name=&#8217;sitemap_xml&#8217;),<br>\n]\nnews_patterns = [<br>\nurl(r&#8217;^$&#8217;, news_views.index, name=&#8217;index&#8217;),<br>\nurl(_(r&#8217;^category\/(?P&lt;slug&gt;[\\w-]+)\/$&#8217;),<br>\nnews_views.category,<br>\nname=&#8217;category&#8217;),<br>\nurl(r&#8217;^(?P&lt;slug&gt;[\\w-]+)\/$&#8217;, news_views.details, name=&#8217;detail&#8217;),<br>\n]\n<p>urlpatterns += i18n_patterns(<br>\nurl(_(r&#8217;^about\/$&#8217;), about_views.main, name=&#8217;about&#8217;),<br>\nurl(_(r&#8217;^news\/&#8217;), include(news_patterns, namespace=&#8217;news&#8217;)),<br>\n)<\/p>\n<p>After you\u2019ve created the translations, the reverse() function will return the URL in the active language. Example:<\/p>\n<p>from django.core.urlresolvers import reverse<br>\nfrom django.utils.translation import activate<\/p>\n<p>&gt;&gt;&gt; activate(&#8216;en&#8217;)<br>\n&gt;&gt;&gt; reverse(&#8216;news:category&#8217;, kwargs={&#8216;slug&#8217;: &#8216;recent&#8217;})<br>\n&#8216;\/en\/news\/category\/recent\/&#8217;<\/p>\n<p>&gt;&gt;&gt; activate(&#8216;nl&#8217;)<br>\n&gt;&gt;&gt; reverse(&#8216;news:category&#8217;, kwargs={&#8216;slug&#8217;: &#8216;recent&#8217;})<br>\n&#8216;\/nl\/nieuws\/categorie\/recent\/&#8217;<\/p>\n<p>In most cases, it\u2019s best to use translated URLs only within a language-code-prefixed block of patterns (using i18n_patterns()), to avoid the possibility that a carelessly translated URL causes a collision with a non-translated URL pattern.<\/p>\n<p><strong>Reversing in Templates<\/strong> &#8211; If localized URLs get reversed in templates, they always use the current language. To link to a URL in another language use the language template tag. It enables the given language in the enclosed template section:<\/p>\n<p>{% load i18n %}<\/p>\n<p>{% get_available_languages as languages %}<\/p>\n<p>{% trans &#8220;View this category in:&#8221; %}<br>\n{% for lang_code, lang_name in languages %}<br>\n{% language lang_code %}<br>\n&lt;a href=&#8221;{% url &#8216;category&#8217; slug=category.slug %}&#8221;&gt;{{<br>\nlang_name }}&lt;\/a&gt;<br>\n{% endlanguage %}<br>\n{% endfor %}<br>\nThe `language` tag expects the language code as the only argument.<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/certified-django-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Translations in Django templates uses two template tags and a slightly different syntax than in Python code. To give your template access to these tags, put {% load i18n %} toward the top of your template. As with all template tags, this tag needs to be loaded in all templates which use translations, even those&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8655],"tags":[8866],"class_list":["post-75936","page","type-page","status-publish","hentry","category-django-web-development","tag-specifying-translation-strings-in-template-code"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Specifying Translation Strings in Template Code - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Specifying Translation Strings in Template Code - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Translations in Django templates uses two template tags and a slightly different syntax than in Python code. To give your template access to these tags, put {% load i18n %} toward the top of your template. As with all template tags, this tag needs to be loaded in all templates which use translations, even those...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:42+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/\",\"name\":\"Specifying Translation Strings in Template Code - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2020-01-20T07:05:43+00:00\",\"dateModified\":\"2024-04-12T08:47:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Specifying Translation Strings in Template Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Specifying Translation Strings in Template Code - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/","og_locale":"en_US","og_type":"article","og_title":"Specifying Translation Strings in Template Code - Tutorial","og_description":"Translations in Django templates uses two template tags and a slightly different syntax than in Python code. To give your template access to these tags, put {% load i18n %} toward the top of your template. As with all template tags, this tag needs to be loaded in all templates which use translations, even those...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:42+00:00","twitter_misc":{"Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/","name":"Specifying Translation Strings in Template Code - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2020-01-20T07:05:43+00:00","dateModified":"2024-04-12T08:47:42+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/specifying-translation-strings-in-template-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Specifying Translation Strings in Template Code"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=75936"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75936\/revisions"}],"predecessor-version":[{"id":83447,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75936\/revisions\/83447"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=75936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=75936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=75936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}