I like your thinking Stefano! Taking it one step further I imagine we could over-ride the print
function to do the lang[string]
lookup and save ourselves some editing.
from lang-it.py import lang
original_print = print
def local_print(expression):
if type(expression) == str and expression in lang:
original_print(lang[expression])
else:
original_print(expression)
print = local_print
Then:
>>> print("Hello world")
Ciao Mondo
>>> print(40+2)
42
However print isn’t the only place local language will appear, especially in Anvil where most output is set by calculation then changing .text
attribute etc. . For example the status
of an Offer or Request in WGACA might be something like this:
count = len(offers)
label_1.text = f"You have made {count} offers. Very generous of you!")
Hence my suggestion of search and replace e.g.
lang = {'label_1.text=f"You have made {count} offers.Very generous of you!")' : ' label_1.text=f"Hai fatto {count} offerte. Sei molto generoso!")'}
I’m not sure if this sort of case is already covered in https://anvil.works/library/localisation but I need to step back now and focus on priority fixes and enhancements for WGACA. Thanks for contributing and I hope @aldo.ercolani and @tommy.hagvall will be able to move this forward from here…
All the best,
Peter