How would you recommend I go about making my Anvil application multilingual?
There are things like this : https://github.com/tuvistavie/python-i18n
but I’d be curious if anyone has actual experience of doing something like this and could recommend something.
I have done it before in PHP, but I just created translation files that overwrote array elements (eg I would include default language file of English and override the arrays with the required language :
# In English.php -
translate['welcome']="Welcome"
# In French.php -
translate['welcome']="Bonjour"
That’s as good a way as any to start off! I would recommend using data bindings for this. Eg if you did:
# ... in some module somewhere:
TRANSLATIONS_FR = {'welcome': 'Bonjour'}
TRANSLATIONS_DE = {'welcome': 'Wilkommen'}
TRANSLATIONS_EN = {'welcome', 'Hi there'}
# ... and in the __init__ method for your form:
self.translations = TranslationModule.TRANSLATIONS_EN
And then you could data-bind the text property of your label to self.translations['welcome'].
(Extra suggestion, slightly dirty: Anvil silently swallows KeyErrors in data binding assignments, so that it can initialise forms when, eg, self.item is an empty dictionary. This means that you could actually do: TRANSLATIONS_EN = {}, and then set all your default text properties in the designer to the English versions. That way, you can use the English in the designer, and get the translations at run-time.)
Is your Anvil app multi-lingual? Would you like to commission development of a powerful built-in internationalisation mechanism for Anvil apps? Contact support@anvil.works and ask about support and commissioning agreements! The ability to prioritise feature development is a valuable one, and it’s available exclusively to our support customers.
Anvil has the anvil.users.login_with_form() method, but it also has lower-level functions such as anvil.users.login_with_email(). You can use these to build your own login flow.
In the cookbook example I’ve linked to above, we’ve already done it for you. You just need to add the Custom Signup Flow app as a dependency:
then create Signup and Login buttons somewhere:
then import the Custom Signup Flow app and call the login and signup methods (remember to bind the click methods to the Buttons and the show method to the Form):
If you want to modify the login and signup forms, for example to translate them, you can modify them in your copy of the Custom Signup Flow app. Remember to publish your changes if you are depending on the published version!
Bringing back an old conversation with one little question.
I need all of my UI to be fully Hebrew (RTL language).
Should the same solution work here too? Just using a big language dict that translate English for example to Hebrew (with this too of course)?
As in: TRANSLATIONS_IL = {'welcome', 'ברוך הבא'}