Mastering Multilingual in Xamarin Forms


Isn't it fun,

to instantly listen to a blog on the go? PLAY !

 
 

Xamarin_Forms_Mastering_Multilingual

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.

Language Management

For getting device Language

  1. CultureInfo.InstalledUICulture

Get or Set the actual language

  1. Thread.CurrentThread.CurrentUICulture = new CultureInfo(“es”);
  2. AppResource.Culture = new CultureInfo(“es”);

For getting all Culture language supported

  1. CultureInfo.GetCultures(CultureTypes.NeutralCultures);

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.


Step: 1

Open Visual Studio and select Xamarin project.

Image: Create a Xamarin project.

After selecting Xamarin forms, give it the appropriate name and select Blank App for Android and iOS platforms.

Image: Select the template and platform.


Step: 2

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.



Image: Resources files


Step: 3

When the resource file adds for any language you need to translate the content of your required language.

Image: Spanish language translation.

Image: French language translation.

Image: Japanese language translation.

Image: English language translation.


Step: 4

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
 

<?xml encoding="utf-8" version="1.0">

<contentpage.content>
<stacklayout padding="20">

<stacklayout>
<label text="{x:Staticresource:AppResource.SelectLanguage}">

<picker.items>
<x:string>English</x:string>
<x:string>Tamil</x:string>
<x:string>Spanish</x:string>
<x:string>Japanese</x:string>
<x:string>French</x:string>
</picker.items><button backgroundcolor="Black" clicked="OnClickedEvent" text="{x:Staticresource:AppResource.Save}" textcolor="White"></button></label></stacklayout><label text="{x:Staticresource:AppResource.SelectLanguage}">

</label></stacklayout><label text="{x:Staticresource:AppResource.SelectLanguage}">
</label></contentpage.content><label text="{x:Staticresource:AppResource.SelectLanguage}">


</label></?xml>






Searching for the Best Xamarin App Development Company ?

Your Search ends here.



Xamarin_Forms_Mastering_Multilingual

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.

Language Management

For getting device Language

  1. CultureInfo.InstalledUICulture

Get or Set the actual language

  1. Thread.CurrentThread.CurrentUICulture = new CultureInfo(“es”);
  2. AppResource.Culture = new CultureInfo(“es”);

For getting all Culture language supported

  1. CultureInfo.GetCultures(CultureTypes.NeutralCultures);

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.


Step: 1

Open Visual Studio and select Xamarin project.

Image: Create a Xamarin project.

After selecting Xamarin forms, give it the appropriate name and select Blank App for Android and iOS platforms.

Image: Select the template and platform.


Step: 2

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.



Image: Resources files


Step: 3

When the resource file adds for any language you need to translate the content of your required language.

Image: Spanish language translation.

Image: French language translation.

Image: Japanese language translation.

Image: English language translation.


Step: 4

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
 

<?xml encoding="utf-8" version="1.0">

<contentpage.content>
<stacklayout padding="20">

<stacklayout>
<label text="{x:Staticresource:AppResource.SelectLanguage}">

<picker.items>
<x:string>English</x:string>
<x:string>Tamil</x:string>
<x:string>Spanish</x:string>
<x:string>Japanese</x:string>
<x:string>French</x:string>
</picker.items><button backgroundcolor="Black" clicked="OnClickedEvent" text="{x:Staticresource:AppResource.Save}" textcolor="White"></button></label></stacklayout><label text="{x:Staticresource:AppResource.SelectLanguage}">

</label></stacklayout><label text="{x:Staticresource:AppResource.SelectLanguage}">
</label></contentpage.content><label text="{x:Staticresource:AppResource.SelectLanguage}">


</label></?xml>






Searching for the Best Xamarin App Development Company ?

Your Search ends here.