1from kivy.app import App
2from kivy.lang.builder import Builder
3from kivy.properties import StringProperty
4from kivy.uix.boxlayout import BoxLayout
5
6
7class Container(BoxLayout):
8 message = StringProperty()
9
10 def retranslate(self, language):
11 texts = {"en": "Hello World", "fr": "Salut monde"}
12 self.message = texts.get(language, "")
13
14
15Builder.load_string(
16 """
17<Container>:
18 orientation: 'vertical'
19 Button:
20 text: root.message
21 Button:
22 text: "Eng"
23 on_press: root.retranslate("en")
24 Button:
25 text: "Fra"
26 on_press: root.retranslate("fr")
27"""
28)
29
30
31class MyApp(App):
32 def build(self):
33 w = Container()
34 w.retranslate("en")
35 return w
36
37
38if __name__ == "__main__":
39 MyApp().run()
40
41