M
M
Max Payne2018-07-25 03:04:42
Python
Max Payne, 2018-07-25 03:04:42

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

1 answer(s)
F
FeNUMe, 2018-07-25
@FeNUMe

What exactly did you not like about gettext ? This is the de facto standard for translations, strings are stored in human-readable .po files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question