简体   繁体   中英

Kotlin : Translate UI from English to French android

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 ?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM