Multilingual (Localization) Plugin for Xamarin and Windows

Just released the Multilingual Plugin , it makes easier the process of adding and handling multi language support across Xamarin Forms, iOS, Android, UWP, Mac, tvOS and watchOS.

Set up

Using it is really simple and you can set up all in just 3 steps:

1-Install the plugin in all your projects

2-Add your Resx resource files in your PCL project

Add one resx file per each language you want to support. “It must follow a specific naming convention: use the same filename as the base resources file (eg. AppResources) followed by a period (.) and then the language code”.

3-Set the culture of your resource class file when initializing your application.

If you are using Xamarin Forms it would be in your App.cs

AppResources.Culture = CrossMultilingual.Current.DeviceCultureInfo;

Xamarin Forms Only

If you are using Xamarin Forms and you want to handle multi language in your XAML:

1-When installing the plugin it will create a TranslateExtension.txt file in folder Helpers, rename the extension for this file to TranslateExtension.cs.

In TranslateExtension.cs file in the constant ResourceId by default it will assume your resource file is added in the root of the project and the resx file is named as AppResources. If you added it to a folder or named the resx file differently you can change it there.

2-Add the reference of your translate extension in your XAML and use it.

Use it

You just have to use CrossMultilingual.Current. 

Get or Set the actual language

CrossMultilingual.Current.CurrentCultureInfo = new CultureInfo("en")

Note: After changing the current culture is important to update your resx class culture too. As follows:

AppResources.Culture = CrossMultilingual.Current.CurrentCultureInfo

Get the actual device language

CrossMultilingual.Current.DeviceCultureInfo

Get all culture languages supported

In case you don’t know the code for a specific culture the following property returns an array of the cultures for all the countries:

CrossMultilingual.Current.CultureInfoList

In case you want to know more about localization:

https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/

Full documentation of the plugin:

https://github.com/CrossGeeks/MultilingualPlugin

Xamarin Forms Sample project:

https://github.com/CrossGeeks/MultilingualPlugin/tree/master/samples/MultilingualSample

Happy coding! 🙂

You may also like