Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what worked for me:</p> <ul> <li><p>create a file in your app folder which will hold django messages for which translations need to be overridden, e.g. <code>django_standard_messages.py</code></p></li> <li><p>in django lib folder or in <code>django.po</code> files find the message (string) that needs to be overridden, e.g. <code>django.forms/fields.py</code> has message <code>_(u"This field is required.")</code> which we want to translate to german differently</p></li> <li><p>in <code>django_standard_messages.py</code> add all such messages like this:</p></li> </ul> <blockquote> <pre><code># coding: utf-8 _ = lambda s: s django_standard_messages_to_override = [ _("This field is required."), ... ] </code></pre> </blockquote> <ul> <li>Translate the file (<code>makemessages</code>, <code>compilemessages</code>) - makemessages will add added django standard messages in your application .po file, find them and translate, run compilemessages to update .mo file</li> <li>tryout</li> </ul> <p><strong>The logic behind:</strong> (I think ;) ) - when <strong><code>ugettext</code></strong> function searches translation for one message (string), there are several <code>.po</code>/<code>.mo</code> files that needs to be searched through. <strong>The first match is used</strong>. So, if our local app <code>.po</code>/<code>.mo</code> is first in that order, our translations will override all other (e.g. django default). </p> <h2>Alternative</h2> <p>When you need <strong>to translate all or most of django default messages</strong>, the other possibility (<strong>which I didn't tried</strong>) is to <strong>copy</strong> default django <code>.po</code> file in our locale or some other special folder, and fix translations and register the folder (if new) in <code>LOCALE_PATHS</code> django <code>settings</code> file as first entry in the list. </p> <p><strong>The logic behind:</strong> is the very similar as noted in previous section.</p>
 

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