Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To use internationalization:</p> <ol> <li><strike>Define the languages your site supports.</strike></li> <li><strike>Mark strings for translation.</strike></li> <li><strike>Create the language files.</strike> </li> <li><strike>Set up the middleware in <code>settings.py</code>.</strike></li> <li>Set the default language of the request.</li> </ol> <p>You need to <a href="https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-language-preference" rel="nofollow">set the language for the request</a>, otherwise django will default to the language request coming from the browser which in your case is English.</p> <p>You also need to fix your template, it should be:</p> <pre><code>{% load i18n %} {% trans alert %} </code></pre> <p>In your view the <code>_</code> function only marks your string for translation; it doesn't actually translate it. Marking the string for translation makes django export it in the language files, and makes django look it up when a different language is requested by the user.</p> <p>There are <a href="https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-language-preference" rel="nofollow">a few ways that django detects the preferred language</a> (it will stop at the first place it finds a language preference). These ways in the order they are checked are:</p> <ol> <li>Language prefix in the URL, for example <code>/en/foo/bar/</code></li> <li>A <code>django_language</code> key in the session.</li> <li>A <code>django_language</code> cookie.</li> <li><code>Accept-Language</code> header.</li> <li><code>LANGUAGE_CODE</code> setting.</li> </ol> <p>In your case, it catching #4, because your browser is sending a list of languages it will accept, and the first one is English.</p> <p>There are a few ways you can resolve this:</p> <ol> <li>You can activate the language in your view: <a href="https://docs.djangoproject.com/en/1.5/ref/utils/#django.utils.translation.activate" rel="nofollow"><code>activate('fa')</code></a></li> <li><p>You can force a language in your template, with the <a href="https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#switching-language-in-templates" rel="nofollow"><code>language</code></a> template tag:</p> <pre><code>{% load i18n %} {% language 'fa' %} {% trans alert %} </code></pre></li> <li>You can use the <a href="https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#url-internationalization" rel="nofollow">url internationalization</a> feature, and pair that with the <a href="https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#the-set-language-redirect-view" rel="nofollow"><code>set_language</code></a> redirect view, to properly set the language and internationalize your URLs.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload