When developing an application that supports multiple language localizations, I use a file in which I store all the string data of the program. I used to get by with simple -
exec(open("файл/языковой/локолизации").read()) thus initializing all variables with string values in the main application code.
Now exec somehow do not want to use. I have adapted the ConfigParser module for this purpose. Now it looks like this:
from ConfigParser import ConfigParser config = ConfigParser() config.read("locale.ini") language = config.get("LOCALE", "language") # устанавливаем локаль section = language.upper() config.read("{}.ini".format(language)) # читаем файл строковых данных # Таким образом я получаю строковые значения для приложеничя. program_title = config.get(section, "program_title") locale.ini
(file of current application localization):
[LOCALE] language = english english.ini
(file with string data):
[ENGLISH] program_title = Clean Master Now, let's say, if I need to change the language to Russian, I add the file russian.ini with the lines of Russian localization, and in the file locale.ini I set the value "language" to "russian".
It turns out the following:
locale.ini (file of the current localization of the application):
[LOCALE] language = russian english.ini (file with string data):
[RUSSIAN] program_title = Мастер Очистки Maybe in Python there are other options for the above bike?