- How to change the system language on your Android phone
- How to change the system language on your Android phone
- Samsung needs to bring back its iPod competitor
- VoLTE: How to use it and why you should care
- PlayStation reportedly planning service to compete with Xbox Game Pass
- These are the best USB-C cables you can find for Android Auto
- Conversion By Translation: Changing Your Android App Language At Runtime
- The Problem
- Prerequisite
- Configuration Class
- Locale.setDefault() Method
- The Solution
- A Game of Cat & माउस्
- #1: System Language Change
- #2: WebView
- Conclusion
- How to Change the Whole App Language in Android Programmatically?
- Example
- Step by Step Implementation
- Changing App language in Android
- Points to keep in mind:
How to change the system language on your Android phone
Source: Harish Jonnalagadda / Android Central
Bought a phone from China or selected the wrong language when setting up your phone? No need to worry. You can easily change the system language on your Android phone by heading into the settings. You can also add as many languages as you want, which is helpful for bilingual users. We’ll show you how to do it in this easy guide.
How to change the system language on your Android phone
To make things easier for you, I switched the language on my phone to Simplified Chinese (the language that’s installed by default on phones in China), and in the guide below I’ll show you how to change it to English.
For the purposes of this guide we used a OnePlus 7 Pro, but you can use just about any Android phone and the steps will be the same.
- Open Settings from the app drawer or home screen.
- Scroll down to the bottom of the page.
Tap System (gear icon).
Source: Harish Jonnalagadda / Android Central
Choose Add a language (plus button).
Source: Harish Jonnalagadda / Android Central
Once the language is added, press and hold the two horizontal lines and move your preferred language to the top.
Source: Harish Jonnalagadda / Android Central
That’s it! You can add as many languages as you want, and just change the order to switch your phone’s system language. If you don’t immediately see the language changing, you may need to restart your device for the changes to take effect.
Android natively supports dozens of languages, including both U.K. and U.S. English, multiple types of Chinese, French, Spanish, and more.
We may earn a commission for purchases using our links. Learn more.
Samsung needs to bring back its iPod competitor
I don’t want to buy an iPod Touch. Since I want a reasonably priced PMP with acceptable audio hardware that can install a few crucial apps, I might have to.
VoLTE: How to use it and why you should care
VoLTE — or Voice over LTE — is the new standard for calling throughout the U.S., Canada, and parts of Europe. Not only does it facilitate much higher call quality between cell phones, but it allows devices to stay connected to LTE while on a call, improving data speeds for everyone.
PlayStation reportedly planning service to compete with Xbox Game Pass
Sony is planning to create a service similar to Xbox Game Pass, according to a new report. The service could launch as early as sometime in the spring of 2022, with multiple tiers.
These are the best USB-C cables you can find for Android Auto
Android Auto is an absolute necessity when driving, regardless of whether you’re headed out to the grocery store or for a long road trip. These cables will ensure your phone stays protected and charged, no matter what.
Источник
Conversion By Translation: Changing Your Android App Language At Runtime
You have an awesome app with lots of cool features, one of which is multi-language support for your users. Everything works great but your Product Manager wants to improve conversion by prompting users to choose the app’s language on the first launch as part of the onboarding process.
With a couple of years of Android experience under your belt, you’re thinking,
“How hard can it be?”
The Problem
On Android, there is no official support, documentation or API to change an entire app’s language at runtime. When a user opens an app, the resource framework automatically selects the resources that best match the device language settings. In Google Maps, for example, you can not change the street names on the map without changing the entire device language.
Prerequisite
In order to change an app’s language (or Locale in Android terms), we need to be familiar with 2 different mechanisms that will help us achieve our goal:
Configuration Class
This class describes all device configuration information that can impact the resources the application retrieves. This includes user-specified configuration options (locale list and scaling)
Basically, this is the class that Android is gettings its Locale information from.
Overriding this class with the Locale that represents the user’s selected language will change the folder Android is looking for its resources (e.g strings.xml).
Locale.setDefault() Method
Gets the current value of the default locale for this instance of the Java Virtual Machine.
The Default Locale is usually used when using operations like formatting text, parsing numbers or handling dates. So it is important to override it, otherwise, an app may be displayed in the correct language but things like dates and currency will be broken.
The Solution
From API 17 and above, the preferred way to override a Configuration is by wrapping the currently used Context in a new Context using the method below:
We can combine all the actions we need to take into a single function:
This method should be called inside the attachBaseContext() method in the Application class and in each Activity.
As far as the Android system implementation goes, we are done!
(or so I thought? more on that later)
A few things you should do in order to achieve this:
- The selected language should be persisted in Room/SharedPreferences/etc in order to retrieve it later ( CreateLocaleFromSavedLanguage() method in the snippet above)
- Reflect the language change by re-creating your Activity or Fragment (this will result in calling attachBaseContext() and modifying the current Context )
- Optional: Load fresh data from the server based on the selected language, like translated strings or specific business logic directed to the selected language users
A Game of Cat & माउस्
The feature is done and you confidently mark it as ready for QA testing. 💪
As the days pass, bug tickets pile up, each with a different scenario that made the app look like it is partially translated to the selected language and partially using the device language.
Below are 2 example scenarios, there are probably more weird cases, so keep that in mind if you decide to go on this road.
#1: System Language Change
If the user changes the device’s main language while your app is in the background, your app Locale will be overridden by the Android system to reflect the new system language.
The fix, in this case, is to override the onConfigurationChanged() method in the Application class and override the Locale using the updateConfiguration() method found in Resource class.
#2: WebView
If your app is using WebView in order to display web pages (yeah I hate it too) then you will notice strange behavior every time a WebView is used.
After each WebView creation, the Application Locale gets overridden with the system Locale which messed up the translations. 🤔
The reason behind this is starting with Android N, the Chrome app will be used to render any/all Webviews in third-party Android apps. Because Chrome is an Android app in itself, running in its own sandboxed process, it will not be bound to the Locale set by your app. Instead, Chrome will revert to the primary device Locale .
Source: https://stackoverflow.com/a/40675539/5516215
The fix, in this case, is again to override the Locale after a WebView is created using the technique we wrote above. One way of doing this is by using a custom WebView :
Hopefully, this issue should be resolved in Android 10, where the Chrome app will no longer be the WebView provider.
Source: https://www.xda-developers.com/google-chrome-no-longer-webview-provider-android-10/
Conclusion
After a few iterations, everything looks good. The Product Manager is happy, your users are happy and even you feel quite pleased with implementing a feature that is not officially supported. 👏
With that said, future Android versions can change how this solution affects your app and even introduce new edge cases that require special care, it is up to you to decide if the investment is worthwhile.
Источник
How to Change the Whole App Language in Android Programmatically?
Android 7.0(API level 24) provides support for multilingual users, allowing the users to select multiple locales in the setting. A Locale object represents a specific geographical, political, or cultural region. Operations that required these Locale to perform a task are called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation so, the number should be formatted according to the conventions of the user’s native region, culture, or country.
Example
In this example, we are going to create a simple application in which the user has the option to select his desired language-English or Hindi. This will change the language of the whole application. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Step by Step Implementation
Step 1: Create A New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Create Resource Files
In this step, we are required to create a string resource file for the Hindi language. Go to app > res > values > right-click > New > Value Resource File and name it as strings. Now, we have to choose qualifiers as Locale from the available list and select the language as Hindi from the drop-down list. Below is the picture of the steps to be performed.
Источник
Changing App language in Android
In your app, you can add as many languages as you want. By languages, I mean the language of the text that we see in any mobile application. For example, if you have English, French, and Hindi users, then you can have language support for all these languages. Like «Hello» in English will become «Bonjour» in French and «नमस्ते» in Hindi.
But how can we change the language? That’s the topic for this blog. In this blog, we will learn how to change the App locale in Android with ease.
By default, you have English as your default language for the whole app and the text corresponding to the English language will be there in our strings.xml file. So, similarly, for other languages, you need to add their strings.xml file.
So, basically Android loads the resources related to language based on the system locale setting. For example, if the language of your Android phone is English, then strings.xml of English will be loaded by Android. We do not have to do anything extra here.
But, many times, we want our users to change the language of our App only by selecting the preferred language and not by changing the language of our Android phone. So, let’s see how to add this.
First of all, create a project in Android Studio. Here, we will be having 2 activities:
- MainActivity: This will contain one welcome TextView and two Buttons, one for opening the next activity in the English language and the other for opening the next activity in the Hindi language.
- LanguageActivity: This will simply contain a TextView displaying some message. The message will be shown in English if the language of the app is English and the message will be shown in Hindi if the language of the app is Hindi.
So, let’s start with the MainActivity. The following is the code for the activity_main.xml file:
Here, we have 1 TextView and 2 Buttons.
Similarly, you can add one TextView in your LanguageActivity. The following is the XML code for the same:
And finally, here is the strings.xml file:
So, we are done with our prerequisite part. Now, we are ready to add a new language to our app. Follow the below steps to do so:
- Right Click on res > New > Android Resource File
- Put the file name as strings.xml
- Select the option of Locale
- Select the locale for Hindi with code «hi»
- Click on Ok and now, you will be having two values directory i.e. the default one with the name values and the other with name values-hi . The default one will contain the strings.xml file for the default language(in our case, English) and the values-hi will contain the strings.xml file for the Hindi language.
Now, you need to put all the values of all the strings that we defined in our default strings.xml file for our new Hindi strings.xml file.
But there are certain cases where we want to keep the text of the default language. For example, the name of the App should be the same for all languages. In our case, we just need to translate the message that is shown on the LanguageActivity and not all texts like AppName, WelcomeMessage, etc.
So, for that, we need to set translatable to false in our default strings.xml file(the English one). For example:
Similarly, you can set translatable = «false» for other string values as well. Now, for the other strings that you want to translate, you can simply add their values in the strings.xml file of the Hindi language. For example, the code of strings.xml (hi) will be:
In this way, you are telling the Android app to use the string value according to the locale of the App.
Now, our final task is to change the locale or simply the language of the app when we click on the button. For this, add the below function in your MainActivity.kt file:
In the above code, pass the context and the language code and then start the LanguageActivity . For example:
Now, when you open the LangaugeActivity, then you can see the changes in the language.
Points to keep in mind:
- Whenever an activity is loaded then the corresponding string.xml file is loaded at that time only. For example, if the current locale of your app is English and on button click, you changed it to Hindi. Then no change on that particular activity will be observed because the string file of that activity is already loaded. But if you move to some other activity and then come back to the first activity, then you will see the language changes. If you want to see instant changes, then you need to refresh the activity after the change of the locale.
- In some Android Versions, you might not see the locale change if you are opening some WebView in your app. Always take care of the case when you load the WebView for the very first time. One possible option is to set again the locale after loading the WebView.
- You need to handle the case of orientation change of your activity. The locale will be reset in this case as well, so handle this as well.
- It is recommended by Android to not change the locale at runtime. So, you can avoid this if the use-case of language is not that much important in your app.
This is how you can change the locale of your App. That’s it for this blog. Hope you enjoyed this blog.
Источник