Special characters in translations

8 views
Skip to first unread message

אורי

unread,
Jul 31, 2022, 11:27:35 PMJul 31
to django...@googlegroups.com
Hi,

I need to translate a string that contains a non-breaking space ("\xa0"), 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:

from django.utils.translation import gettext_lazy as _, pgettext_lazy

            return _("On {date} ({timesince} ago)")\
                .replace(" ago)", "\xa0ago)")\
                .replace("(לפני ", "(לפני\xa0")\
                .format(
                    date=formats.date_format(value=last_visit_date),
                    timesince=timesince(d=last_visit_date, now=today),
                )
Which works, but I would prefer to translate the string properly and not replace the translated string after its translation.

Notice that English returns the original string without any translation.

(I tried to translate the string "On {date} ({timesince}\xa0ago)" but it didn't work)

Any ideas?

Thanks,

Reply all
Reply to author
Forward
0 new messages