Replace string_concat() with equivalent

Asked

Viewed 85 times

3

I am a beginner in Python and accepted to participate in a more or less old project, which was using Python 2.7 so far. At the beginning of the year, this version was deprecated and now I can’t install anything with Pip, so I need to update the whole project to Python 3.x. The first obstacle to this is the functions string_concat(), that used to belong to the module django.utils.translation up to Django 1.9, then discontinued. Next, an example of code in which it appears:

'ESPESSURAF' : {
    u'NOME':u'ESPESSURAF',
    u'NOME_HTML': string_concat(NOMES_HTML['ESPESSURAF'], u' <em>t&nbsp;<sub> f</sub> </em> [m]'),
    u'UNIDADE':u' <em>t&nbsp;<sub> f</sub>[m] </em>',
    u'COMENTARIO':u'',
    u'TOOLTIP' : u''
},

All other occurrences are very similar to this one, so the solution of one must be valid to all. I read somewhere that format_lazy() may be a good replacement, but I don’t have enough experience to know how to do this adaptation. I need to fix this as soon as possible, I would be enormously grateful for any help.

  • You can use Fstring to concatenate the strings, no?

  • Yes, but these are Lazy strings; I’m not sure how this works, but from what I understand, they are used to make translation into other languages possible. So concatenating with f-strings in this situation can break the translations, I believe.

  • Dude, check your lib ugettext_lazy, maybe that’s what you need. When I worked with a Django project this is how we kept the translations.

  • Yes, I had found something that seemed to be the function code itself, but I didn’t get a chance to test it, now it’s too late.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.