×

iFour Logo

How to handle multilingual in Xamarin forms?

Kapil Panchal - November 09, 2020

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

  • play
  • pause
  • pause
How to handle multilingual in Xamarin forms?

In this blog, we will be going to talk about how to implement multilingual in xamarin forms. Multilingual means user requires the multiple languages in their application because there are many people from everywhere to utilizethe application, at that time multilingual feature is the most useful one.

Localization is the process of adapting an application to satisfy the precise language or cultural requirements of a target market. To accomplish localization, text and pictures in an application may need to be translated into multiple languages.

How to implement multilingual using xamarin forms?


You can implement multilingual by creating resources for each language and bundling them with the internationalize app. All you've got to try to do is to make a resource file for every language. These resources have an inventory of key-value pairs of words, phrases, or sentences.

For example, you've got a resource file for English language and you've got the key of SubmitText with a worth of “Welcome”. And furthermore,you may have a resource file for Filipino which also features a SubmitText key but with a worth of “Maligayangpagdating”. After creating these resources, you’ll now use it on your app. The app will select its corresponding resource counting on the phone’s language. If there's no corresponding resource, it'll use by default language, which will be English.

 

Step 1: First Create the xamarin project

Step1: Create a new project by selecting the xamarin forms project.

xamarin_first

Fig 1: Create a xamarin project.

Step 2: Next, select the blank template and platform depending on your requirements.

template

Fig 2: Select the template and platform

Step 2: After creating the project, create a new folder and assign the name as Resource.Then, create a resource file.

Step 1: Right-click on the solution explorer then select

Add ->New Item-> select General -> select the resource dictionary file -> assign the suitable name (Example:AppResources.resx) ->Then click Ohk.
xamarinResource

Fig 3: Resource file.


Example of Assign the name:
Language Code of Language File Name
France Fr AppResources.fr.resx
Spanish Sp AppResourcec.sp.resx

Table 1: Resource file name

 

Step 3:Create the resource file if you need to translate the content of your required language.

The Access Modifier sink setting determines how Visual Studio generates the category want to access resources. Setting the Access Modifier to Public or Internal leads to a generated class with the required accessibility level. Setting the Access Modifier to No code generation doesn't generate a category file. The default resource file should be configured to get a category file, which ends up during a file with the designer.cs extension being added to the project.

Once through with our default resource file, we will now create resource files for other languages that we would like to support. For each language you’re supporting, you'll get to add a resource file with the name: “Resource. {culture name}.resx”. You can find an inventory of culture names here. You will able to add equivalent keys that will be added in our default resource to give surety for app that will have translations for every text.

The translation file uses equivalent Name values laid out in the default file but contains Spanish language strings within the Value column. Additionally, the Access Modifier is about No code generation.

 

Example

1) File Name: AppResources.resx

 
Name Value
WelcomeToXamarinForms Welcome to xamarin forms

Table 2: AppResources.resx

2) File Name: AppResource.fr.resx(For the French Language)

 
Name Value
WelcomeToXamarinForms Bienvenue dans les formulaires Xamarin

Table 3: AppResources.fr.resx

 

Step 4: Handel the Multilingual Implementation.

First, you have to set the actual language.

Code:

CultureInfo info = new CultureInfo("fr");
Thread.CurrentThread.CurrentUICulture = info;
AppResource.Culture = info;
Application.Current.MainPage = new NavigationPage(new MainPage());

Step 5: Implement the Multilingual in the XAML file.

If you have used this file before, you need to add the namespace.

xmlns:resource=” clr-namespace:DemoOfMultilingual”;

Then use the file to be shown below:

Code:

roadmap-scrum

Step 6: Run the project multilingual.

Example of the Multilingual Implementation.

using DemoOfMultilingual.Resx;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace DemoOfMultilingual
{
public partial class MainPage :ContentPage
{
public MainPage()
{
InitializeComponent();
CultureInfo.InstalledUICulture;
CultureInfo info = new CultureInfo("fr");
Thread.CurrentThread.CurrentUICulture = info;
AppResource.Culture = info;
Application.Current.MainPage = new NavigationPage(new MainPage());
}

Step 1: Create the xamarin project.

Step 2: After creating the project to create the resource file and assign them a suitable name.


Example: AppResources.resx
Name Value Comment
ClickMe Click Me  
Welcome_to_xamarin_forms Welcome to xamarin forms  

Table 4: AppResources.resx


Second file: AppResources.fr.resx. (French)
Name Value Comment
ClickMe Cliquez sur moi  
Welcome_to_xamarin_forms Bienvenue dans les formulaires Xamarin  

Table 5: AppResources.fr.resx


Third File: AppResources.gr.resx(German)
Name Value Comment
ClickMe Klick mich  
Welcome_to_xamarin_forms Willkommen bei Xamarin-Formularen  

Table 6: AppResources.gr.resx


Step 3: You can assign the name in the XAML page as shown below File name:Mainpage.xaml
mainpage

Class file:Mainpage.cs Another way to perform the control using the file below:

Searching for Reliable Xamarin Mobile App Development Company? Contact Now.


File Name: App.xaml.cs
using DemoOfMultilingual.Resx;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace DemoOfMultilingual
{
public partial class App: Application
{
public App ()
{
InitializeComponent();
MainPage = new ContentPage()
{
Content = new Label()
{
Text = AppResources.Welcome_to_xamarin_forms,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Color.Red,
FontSize = 22
}
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}

Output of the project


English Language

EnglishLangauge

French Language

FrenchLanguager

Conclusion


As you can see, handling Multilingual in Xamarin.Forms are sort of easy even within the most complex scenarios, there are easy ways to urge it to work for your needs. As a further recommendation, we encourage you to ascertain these great tips within the Xamarin documentation about Localization best practices which can assist you to possess more consistent code. Both are really useful tools when it involves localization-related tasks.

How to handle multilingual in Xamarin forms? In this blog, we will be going to talk about how to implement multilingual in xamarin forms. Multilingual means user requires the multiple languages in their application because there are many people from everywhere to utilizethe application, at that time multilingual feature is the most useful one. Localization is the process of adapting an application to satisfy the precise language or cultural requirements of a target market. To accomplish localization, text and pictures in an application may need to be translated into multiple languages. Table of Content 1. How to implement multilingual using xamarin forms 1.1 Step 1: First Create the xamarin project 1.2 Step 2: After creating the project, create a new folder and assign the name as Resource.Then, create a resource file. 1.3 Step 3:Create the resource file if you need to translate the content of your required language. 1.4 Step 4: Handel the Multilingual Implementation. 1.5 Step 5: Implement the Multilingual in the XAML file. 1.6 Step 6: Run the project multilingual. 2. Conclusion   How to implement multilingual using xamarin forms? You can implement multilingual by creating resources for each language and bundling them with the internationalize app. All you've got to try to do is to make a resource file for every language. These resources have an inventory of key-value pairs of words, phrases, or sentences. For example, you've got a resource file for English language and you've got the key of SubmitText with a worth of “Welcome”. And furthermore,you may have a resource file for Filipino which also features a SubmitText key but with a worth of “Maligayangpagdating”. After creating these resources, you’ll now use it on your app. The app will select its corresponding resource counting on the phone’s language. If there's no corresponding resource, it'll use by default language, which will be English.   Step 1: First Create the xamarin project Step1: Create a new project by selecting the xamarin forms project. Fig 1: Create a xamarin project. Step 2: Next, select the blank template and platform depending on your requirements. Fig 2: Select the template and platform Step 2: After creating the project, create a new folder and assign the name as Resource.Then, create a resource file. Step 1: Right-click on the solution explorer then select Add ->New Item-> select General -> select the resource dictionary file -> assign the suitable name (Example:AppResources.resx) ->Then click Ohk. Fig 3: Resource file. Read More: Why To Choose Syncfusion Xamarin Ui Control? Example of Assign the name: Language Code of Language File Name France Fr AppResources.fr.resx Spanish Sp AppResourcec.sp.resx Table 1: Resource file name   Step 3:Create the resource file if you need to translate the content of your required language. The Access Modifier sink setting determines how Visual Studio generates the category want to access resources. Setting the Access Modifier to Public or Internal leads to a generated class with the required accessibility level. Setting the Access Modifier to No code generation doesn't generate a category file. The default resource file should be configured to get a category file, which ends up during a file with the designer.cs extension being added to the project. Once through with our default resource file, we will now create resource files for other languages that we would like to support. For each language you’re supporting, you'll get to add a resource file with the name: “Resource. {culture name}.resx”. You can find an inventory of culture names here. You will able to add equivalent keys that will be added in our default resource to give surety for app that will have translations for every text. The translation file uses equivalent Name values laid out in the default file but contains Spanish language strings within the Value column. Additionally, the Access Modifier is about No code generation.   Example 1) File Name: AppResources.resx   Name Value WelcomeToXamarinForms Welcome to xamarin forms Table 2: AppResources.resx 2) File Name: AppResource.fr.resx(For the French Language)   Name Value WelcomeToXamarinForms Bienvenue dans les formulaires Xamarin Table 3: AppResources.fr.resx   Step 4: Handel the Multilingual Implementation. First, you have to set the actual language. Code: CultureInfo info = new CultureInfo("fr"); Thread.CurrentThread.CurrentUICulture = info; AppResource.Culture = info; Application.Current.MainPage = new NavigationPage(new MainPage()); Step 5: Implement the Multilingual in the XAML file. If you have used this file before, you need to add the namespace. xmlns:resource=” clr-namespace:DemoOfMultilingual”; Then use the file to be shown below: Code: Step 6: Run the project multilingual. Example of the Multilingual Implementation. using DemoOfMultilingual.Resx; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Xamarin.Forms; namespace DemoOfMultilingual { public partial class MainPage :ContentPage { public MainPage() { InitializeComponent(); CultureInfo.InstalledUICulture; CultureInfo info = new CultureInfo("fr"); Thread.CurrentThread.CurrentUICulture = info; AppResource.Culture = info; Application.Current.MainPage = new NavigationPage(new MainPage()); } Step 1: Create the xamarin project. Step 2: After creating the project to create the resource file and assign them a suitable name. Example: AppResources.resx Name Value Comment ClickMe Click Me   Welcome_to_xamarin_forms Welcome to xamarin forms   Table 4: AppResources.resx Second file: AppResources.fr.resx. (French) Name Value Comment ClickMe Cliquez sur moi   Welcome_to_xamarin_forms Bienvenue dans les formulaires Xamarin   Table 5: AppResources.fr.resx Third File: AppResources.gr.resx(German) Name Value Comment ClickMe Klick mich   Welcome_to_xamarin_forms Willkommen bei Xamarin-Formularen   Table 6: AppResources.gr.resx Step 3: You can assign the name in the XAML page as shown below File name:Mainpage.xaml Class file:Mainpage.cs Another way to perform the control using the file below: Searching for Reliable Xamarin Mobile App Development Company? Contact Now. See here File Name: App.xaml.cs using DemoOfMultilingual.Resx; using System; using Xamarin.Forms; using Xamarin.Forms.Xaml; [assembly: XamlCompilation(XamlCompilationOptions.Compile)] namespace DemoOfMultilingual { public partial class App: Application { public App () { InitializeComponent(); MainPage = new ContentPage() { Content = new Label() { Text = AppResources.Welcome_to_xamarin_forms, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, TextColor = Color.Red, FontSize = 22 } }; } protected override void OnStart() { // Handle when your app starts } protected override void OnSleep() { // Handle when your app sleeps } protected override void OnResume() { // Handle when your app resumes } } } Output of the project English Language French Language Conclusion As you can see, handling Multilingual in Xamarin.Forms are sort of easy even within the most complex scenarios, there are easy ways to urge it to work for your needs. As a further recommendation, we encourage you to ascertain these great tips within the Xamarin documentation about Localization best practices which can assist you to possess more consistent code. Both are really useful tools when it involves localization-related tasks.

Build Your Agile Team

Enter your e-mail address Please enter valid e-mail

Categories

Ensure your sustainable growth with our team

Talk to our experts
Sustainable
Sustainable
 

Blog Our insights

Next-Gen Programming Languages: Shaping the Future of Software Development in 2024
Next-Gen Programming Languages: Shaping the Future of Software Development in 2024

Introduction Imagine standing in line at the grocery store, waiting to pay for groceries. You pull out your phone and scan each item’s barcode with a single tap. This seemingly...

MySQL vs Azure SQL Database: Understanding Needs, Factors, and Performance Metrics
MySQL vs Azure SQL Database: Understanding Needs, Factors, and Performance Metrics

The world of technology is constantly changing, and databases are at the forefront of this evolution. We have explored different types of databases, both physical and cloud-based, and realized how each of them provides unique features to improve data accessibility and inclusive performance. Leading the pack are MySQL and Azure SQL database services , helping business elevate their processes to new heights.

Streamlining E-commerce Operations with Microsoft PowerApps
Streamlining E-commerce Operations with Microsoft PowerApps

In today's rapidly changing digital world, eCommerce is a dynamic industry. Every day, millions of transactions take place online, so companies are always looking for new and creative methods to improve consumer satisfaction and optimize operations.