-1

In my android app with kotlin, I add a button in a slide menu that when I clickOn the language change from English to French. I have two idea, The First One create two layout one mainactivity_en.xml and the second layout mainactivity.xml. The Second idea, is to keep one layout mainactivity.xml, and doing test if language "Fr" I change all fields with french language else "En" with english. I would like to know what's the more efficient and optimised solution to translate UI from English to Frensh ?

Lina
  • 553
  • 10
  • 34

2 Answers2

0

Just set the locale and update resources programmatically. A quick google comes up with a walkthrough.

Submersed
  • 8,810
  • 2
  • 30
  • 38
0

You don't need to maintain two separate activities. The strings.xml is appropriate for this. Then you would have two values folders in your res directory. One for values and the other for values_en or values_fr depending on what language is the primary language. The Localization Documentation has more details. To update the language at runtime see this.

Benjamin Cassidy
  • 827
  • 1
  • 8
  • 23