Xamarin Forms Multilingual App
Is your app’s audience comes from different kinds of regions/countries whose primary language is not just English? You must provide multilingual support to your app which can help your app/business grow.
In this article, I am going to demonstrate how to change the language of our app from English to Arabic. I am choosing the Arabic language because in the Arabic language the phrase is written & read from Right to Left.
Before we begin let’s divide our implementation into the following steps
- Create English/Default & Arabic Language Resource Files
- Implement the language change code on our page.
Create English/Default & Arabic Language Resource Files
Let’s note down the language code of the languages that we are using, you can use this link.
Now add the resource file with extension .resx in a separate folder. Follow the below steps on the newly created folder Resx.
Right Click → Add → New Item → Resource File
Name it as AppResource.resx , this file will hold the default text/language of the app.
Add another resource file Arabic language named AppResource.ar.resx here ar is the language code of the Arabic Language.
It will look like this after adding both Default & Arabic language resource files.
Add texts for resource files Arabic & Default languages & make sure its access modifier is Public.
Create a ContentPage & Add Label to display welcome text & Button to change the language.
in this code instead of setting direct hardcoded text to label & button we will use the namespace of resource file we added & use the keys to get the text.
Code-behind has the code of setting App Flow Direction, Applying new language selection & Reloading the app to see the result of language change.