Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to append a translated string to himself with gettext

The following code is not working

from django.utils.translation import gettext_lazy as _ 

stringtest=_("First string")
stringtest= stringtest + _(" Second string")
print stringtest

I get the following exception:

cannot concatenate 'str' and '__proxy__' objects

Is it really impossible to append a "translated" string to himself ?

like image 415
Erwan Avatar asked May 17 '14 09:05

Erwan


1 Answers

We can use format_lazy.

from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _ 

msgs_to_concat = [_("First string"), _(" Second string")]

stringtest = format_lazy('{}'*len(msgs_to_concat), *msgs_to_concat)
like image 131
Valery Ramusik Avatar answered Oct 20 '22 02:10

Valery Ramusik