
Posted by Neelansh Sahai Android Developer Relationship Engineer (dated Twitter And the linkedin)
ranging from Android 13We’ve included one of the crucial requested options from the customers, Language preferences for every app. Permits customers to change software languages from the system settings, offering customers with higher management over their language selections for various functions, whatever the system language.
![]() ![]() ![]() |
Construct for multilingual customers
This weblog focuses on how one can combine the Per-App Language Choice API into your app to offer your customers with flexibility to decide on completely different languages for various apps.
1. Customers can change the language settings from the system settings by choosing:
Settings → System → Languages and enter → Software languages → [Select the desired App] → [Select the desired Language]
2. In case your app already has an in-app language picker, you’ll be able to combine the language desire API for every app to make the most of full platform help. For customers of the model previous to Android 13, the system settings won’t be seen, however builders can nonetheless present a file In-app language picker.
How do you combine this function into your app?
There are 5 steps to observe whereas engaged on the Per App Language Preferences function, listed right here →
1. Create locale_config. xml a file
Create a brand new file within the /xml/values listing and identify it as locale_config. xml. This file ought to include a listing of all languages supported by the appliance. The menu merchandise have to be a string containing a language tag.
locale_config. xml
2. Add locale_config in AndroidManifest.xml
Choose this locale_config. xml file within the software AndroidManifest. xml
AndroidManifest. xml
After steps 1 and a couple of, customers will have the ability to uncover and set their very own language desire in your app from the system settings on gadgets operating Android 13 or greater. In case your customers are utilizing gadgets with variations sooner than Android 13, you’ll be able to present an in-app language picker. Optionally, you can even embody the identical language picker in your app for gadgets with Android 13 or greater. When your software contains an in-app language picker, it is crucial that the consumer’s preferences are in sync between the system and the appliance. That is the place the AndroidX APIs come into the image. Learn on to discover ways to create an in-app language picker.
Use the most recent model of the AppCompat library
4. Use the AndroidX APIs
Use APIs in your code to set and get software languages.
MainActivity.kt
5. Delegate storage to AndroidX
Let AndroidX deal with storing the locale so the consumer desire persists.
AndroidManifest. xml
Steps 3, 4, and 5 above present the minimal elements wanted to create an in-app language picker.
With this, your software can now help locale switching.
Extra issues to care for whereas migrating to the API
Earlier, builders needed to deal with consumer preferences themselves, both through the use of frequent preferences, Retailer information on the server or different software logic. With the brand new APIs, there is no such thing as a must take care of this individually. So if you use these APIs, AndroidX already takes care of the storage half, however what occurs when the app is opened for the primary time after the consumer updates their system to Android 13 or greater?
On this case, the system won’t pay attention to the consumer’s desire for the language of the appliance, and can subsequently set the appliance to the default system language. To keep away from this, builders want so as to add one-time paging logic in order that customers do not need to set the language once more when updating the app.
What flexibility does the function present to customers and builders?
Listed here are some issues that could be helpful to customers.
- All gadgets operating Android 13 or greater may have a standard place for customers to find and alter the language of their apps.
- Though the system settings are restricted to gadgets with Android 13 or greater, AndroidX APIs are backward suitable. Thus, there is no such thing as a requirement so as to add OS model checks in your code whereas constructing for multilingual customers.
- Builders need not deal with configuration modifications individually or fear about storing the consumer’s particular language every time. The API handles configuration modifications and shops language preferences for you.
- Works with different Android options like backup and restore. If the consumer switches to a brand new system and restores beforehand backed up information, your app will maintain the consumer’s final most well-liked language, offering customers with a greater and smoother expertise.
a abstract
With that stated, most components of the function are coated. So let’s take a fast have a look at what we mentioned in in the present day’s studying.
- A fast learn on what every app’s language preferences supply multilingual customers and app builders.
- What finish customers will see on their gadgets.
- Easy methods to migrate your app to every app’s language desire APIs.
- There are some things that should be taken care of whereas migrating to APIs to make sure a greater consumer expertise.
- Lastly, the advantages that customers and builders can get from this function.
References
The Information Weblog The place You Get The Information First
Android Builders Weblog
#Android #Developer #Weblog #Language #preferences #app