I am looking to do language translations for my app. Accessing the translations from dictionaries in another py file makes the most sense to me.
I can technically access the dictionary values, but I cannot make the values change in the KV file when a button is pressed. Any guidance would be sincerely appreciated!
main.py
from kivy.app import App
from kivy.lang import Builder
kv_file = Builder.load_string("""
#:import pyfile pyfile
ScreenManager:
id: manager
Screen:
GridLayout:
cols:1
rows:5
Button:
text: 'To English'
on_release:
pyfile.rando().chosen_language = pyfile.rando().English
Button:
text: 'To Croatian'
on_release:
pyfile.rando().chosen_language = pyfile.rando().Croatian
Label:
text:
pyfile.rando().chosen_language['MS First Button']
""")
class MyApp(App):
def build(self):
return kv_file
if __name__ == '__main__':
MyApp().run()
pyfile.py
# -*- coding: utf-8 -*-
from kivy.properties import DictProperty
class rando(DictProperty):
English = {'MS First Button': 'Take the Quiz'
}
Croatian = {'MS First Button': 'Učinite Kviz'
}
chosen_language = English