Answer the question
In order to leave comments, you need to log in
How to correctly render strings in templates?
How to correctly implement the removal of lines in templates? Let's say for multilingualism. I have a tools module with goodies used in the project. Nearby are files for languages with constants, such as HELLO = "Привет"
. Tools has a get_message function that accepts a string constant name, scope, and language.
While I see the following option - class methods return, for example tools.get_message("HELLO", {}, "ru")
. Next, the get_message function tries to get this constant from the file via getattr and formats it via format_map() with the scope passed to the function.
But this looks like a perversion, are there any other alternative and logical options? And if I need to execute a function in this line?
It is desirable that this works quickly, and not like a Template.
At the same time, I am not interested in the translation itself, which gettext does, but in the approach to storing and processing such string data.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question