title: Django - Special characters in translations
body: <p>I need to translate a string that contains a non-breaking space (<code>&quot;\xa0&quot;</code>), but I can't find a way to translate this string properly. The translation ignores the special character or doesn't translate the string at all. Eventually I came up with this solution:</p>
  <pre class="lang-py prettyprint-override"><code>from django.utils.translation import gettext_lazy as _, pgettext_lazy
  
  return _(&quot;On {date} ({timesince} ago)&quot;)\
      .replace(&quot; ago)&quot;, &quot;\xa0ago)&quot;)\
      .replace(&quot;(לפני &quot;, &quot;(לפני\xa0&quot;)\
      .format(
          date=formats.date_format(value=last_visit_date),
          timesince=timesince(d=last_visit_date, now=today),
      )
  </code></pre>
  <p>Which works, but I would prefer to translate the string properly and not replace the translated string after its translation.</p>
  <p>Notice that English returns the original string without any translation.</p>
  <p>(I tried to translate the string <code>&quot;On {date} ({timesince}\xa0ago)&quot;</code> but it didn't work)</p>
  <p>Any ideas?</p>
  <p>I think maybe I can use <code>&quot;{timesince} ago&quot;</code> as a separate string and then translate it, and then convert only spaces to <code>&quot;\xa0&quot;</code>, and only then format <code>{timesince}</code> (which might contain spaces too). What do you think?</p>
  <p><strong>Update:</strong> I changed the code to the following function. Is it a good and correct way to translate?</p>
  <pre class="lang-py prettyprint-override"><code>from django.utils.html import avoid_wrapping
  from django.utils.translation import gettext_lazy as _, pgettext_lazy
  
  return _(&quot;On {date} ({timesince_ago})&quot;).format(
      date=formats.date_format(value=last_visit_date),
      timesince_ago=avoid_wrapping(value=_(&quot;{timesince} ago&quot;)).format(
          timesince=timesince(d=last_visit_date, now=today),
      ),
  )
  </code></pre>