When a user uploads an application to the application storage, they can manually set the language for their application. This feature is great, but what if it's important for a user to overwrite that setting?
For example, the application needs to respond differently and present a user with a screen or a pop-up based on the location or the language of the device. If the application is opened in the UK, which falls under the GDPR guidelines, then users should be presented with a page that informs them of their rights. This sort of behavior, however, is not applicable for users in the US, and the screen should not be visible.
We can manually switch the Device Language setting to reflect the language: English (United Kingdom) or English(US) which would yield the desired outcome.
This solution, however, is not ideal. It requires too much manual intervention, which requires too much time, which is too much effort.
A better solution would be to make use of Appium capabilities for location or language, but that comes with a small caveat.
In order to overwrite the setting that is set in the application uploaded to storage or the application that has a preset language, you must provide only one capability: language or locale. Providing both will default to language and might not produce the desired outcome.
Setting only the locale, will allow the user to override the language that is applicable to the location without having to provide additional capabilities:
caps.setCapability("locale", "en_UK");
It is important to only provide one capability, if both are presented, only the language capability will be picked up and the locale will be ignored. So, if your desired outcome is to set the language based on the locale, just set the locale as it is recommended in the Appium documentation.
Happy Testing!