Sunday, July 31, 2022

Special characters in translations

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,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeHApgN7yWJKWEcVLeUUTzs94z5-kWRy%3D_pMAMm2Tkonng%40mail.gmail.com.

No comments:

Post a Comment