In this blog, we will learn how to use multilingual in Xamarin forms. And here we will be going to create an application that can support multiple languages like, Tamil, French, Japanese, Spanish, English, Hindi, Gujarati, etc. in our Xamarin forms application. For any mobile app, multilingual is one of the most common requirements. In Xamarin forms,creating multiple languages andhandling multiple languages is very simple.
Table of Content
How to use Multilingual using Xamarin forms?
Using the resource file, we can use multilingual in Xamarin forms. Here, we need to create a separate resource file for each of the languages. This resource file has a key-value pair.
Let’s see some information about getting and setting the language.
For getting device Language
Get or Set the actual language
- Thread.CurrentThread.CurrentUICulture = new CultureInfo(“es”);
- AppResource.Culture = new CultureInfo(“es”);
For getting all Culture language supported
What is Culture?
Culture is a combination of languages. Culture can also include dates, times, and currencies.Here we can see the syntax for getting device language, get or set the actual language, and getting all culture language supported. Now, we can see the simple example of how to use multiple languages in Xamarin forms.
Open Visual Studio and select Xamarin project.
After selecting Xamarin forms, give it the appropriate name and select Blank App for Android and iOS platforms.
After creating the project, make a folder and give it the name Resource. Here, we can create a folder for adding a number of resource files for different languages. For adding a resource file Right-click on the Resource folder -> Add -> New Item -> Select Resources File and give it to the name language-wise.
For French language translation ->AppResources.fr.resx
For Japanese language translation ->AppResources.ja.resx
For Spanish language translation ->AppResources.es.resx
For Brazilian Portuguese language translation -> AppResources.pt-BR.resx
For Portuguese language translation ->AppResources.pt.resx
For Chinese (Simplified) language translation ->AppResources.zh-Hans.resx
For Chinese (Traditional) language translation ->AppResources.zh-Hant.resx
For German language translation ->AppResources.de.resx
These all are resource file names for different languages.
When the resource file adds for any language you need to translate the content of your required language.
After adding a resource file, we have to add one more Content Page to select a language in the list of languages and the save button for using the selected language in the whole application. First, we have to set actual language using
Thread.CurrentThread.CurrentUICulture = new CultureInfo(“es”);
AppResource.Culture = new CultureInfo(“es”);
For add one more content page open Solution Explorer -> Right-click on the project name -> Add -> New Item -> Select Content Page.
Here ListLanguagePage is our new content page name. Just open the ListLanguagePage file and add the below code.
On this XAML page, we can add a label control to display languages and picker control for selecting one language in the list of languages. And one button to apply the selected language in the application.ListLanguagePage.xaml
Searching for the Best Xamarin App Development Company ?
Your Search ends here.