mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-01-18 16:58:48 +00:00
Оптимизация функции локализации
This commit is contained in:
parent
3d6074260a
commit
63af9c4eaa
@ -30,29 +30,44 @@ def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space
|
|||||||
recipes[product] = reag__(category=category, comps=comps, out=out)
|
recipes[product] = reag__(category=category, comps=comps, out=out)
|
||||||
return recipes
|
return recipes
|
||||||
|
|
||||||
def localize(ftl = parse_ftl()):
|
|
||||||
recipes = load_recipes()
|
def localize(recipes, locale):
|
||||||
for k, v in list(recipes.items()):
|
loc_recipes = {}
|
||||||
for word in ftl:
|
# Итерируем элементы
|
||||||
if k.lower() == word:
|
for element in recipes:
|
||||||
new_key = ftl[word].capitalize()
|
# Итерируем составные
|
||||||
recipes[new_key] = recipes.pop(k)
|
el = recipes[element]
|
||||||
for k1, v1 in list(recipes[new_key].comps.items()):
|
# Локализованные составные
|
||||||
for word1 in ftl:
|
loc_comps = {}
|
||||||
if k1.lower() == word1:
|
for comp in el.comps:
|
||||||
new_key1 = ftl[word1]
|
# Ищем перевод
|
||||||
recipes[new_key].comps[new_key1] = recipes[new_key].comps.pop(k1)
|
if comp.lower() in locale:
|
||||||
else:
|
loc = locale[comp.lower()].capitalize()
|
||||||
try:
|
loc_comps[loc] = el.comps[comp]
|
||||||
for k1, v1 in list(recipes[k].comps.items()):
|
else:
|
||||||
for word1 in ftl:
|
loc_comps[comp] = el.comps[comp]
|
||||||
if k1.lower() == word1:
|
# Заменяем на локализованное
|
||||||
new_key1 = ftl[word1].capitalize()
|
el.comps = loc_comps
|
||||||
recipes[k].comps[new_key1] = recipes[k].comps.pop(k1)
|
|
||||||
except:
|
# Локализуем ключ
|
||||||
for k1, v1 in list(recipes[new_key].comps.items()):
|
if element.lower() in locale:
|
||||||
for word1 in ftl:
|
loc = locale[element.lower()].capitalize()
|
||||||
if k1.lower() == word1:
|
loc_recipes[loc] = recipes[element]
|
||||||
new_key1 = ftl[word1].capitalize()
|
else:
|
||||||
recipes[new_key].comps[new_key1] = recipes[new_key].comps.pop(k1)
|
loc_recipes[element] = recipes[element]
|
||||||
return recipes
|
|
||||||
|
return loc_recipes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
recipes = load_recipes()
|
||||||
|
locales = parse_ftl()
|
||||||
|
|
||||||
|
recipes = localize(recipes, locales)
|
||||||
|
|
||||||
|
from icecream import ic
|
||||||
|
ic.configureOutput(prefix='')
|
||||||
|
for i in recipes:
|
||||||
|
el = [i, recipes[i].comps]
|
||||||
|
ic(el)
|
||||||
|
Loading…
Reference in New Issue
Block a user