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

20 Comments

  1. Hi, I’m trying to follow your guide, I did everything like you said (I think) but when I try to runing the app (android) i recieve the following error :

    android.runtime.JavaProxyThrowable: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure “ProjectName.UserInterface.Localization.resources” was correctly embedded or linked into assembly “ProjectApp.Shared” at compile time, or that all the satellite assemblies required are loadable and fully signed.

    Any ideia what may have caused this ? Thanks.

  2. Nice post Charlin! It comes to the part of using this features in order to completely understand them and I can tell that your tutorial is pretty straight forward! Thanks!

  3. This works really well for me, thanks! I saw on your repo that James Montemagno wants to include it in Xamarin Essentials. You should definitely do that!

    I do have a question, though. I’m using this with Prism and I’m wondering what the best way is to update all the pages when someone changes their language selection using my code (not necessarily the OS event).

    Should I just navigate back to the top of the stack or something so that all the pages are newly created? I don’t want to do something like DynamicResources, do I? Or should I just store their preference and tell them I’m restarting the app? Then pick it up.

    I suppose I could also monitor the system language changed event. I noticed that iOS handled it automatically, but Android did not.

    Seems like a bit more work than I had planned.

    Anyway, the basic stuff of matching their phone preference is really cool, thanks again.

    1. Hi Bill, so glad to hear that :),
      After change the language in Prism you can do an absolute navigation, it will reload the navigation stack.

  4. Hi, I tryed the follow your guide to vertion 1.0.2,and tryed de 1.1.16-beta version too, but the folder Helpers isn’t criated. I tryed copy it from a sample of aplication, but i get some errors when i do this. Any idea about why the install have problems? I’m using win 10 and Visual Studio 2018. Thanks and congrats for great job.

  5. I am using Plugin.Multilingual in xamarin forms, so in the xaml page I am able to get transalted text like “{i18n:Translate Password}”. How to do the same from c# code?

  6. Hi,
    I’ been in circles for a while trying to get around the
    Error CS0103 The name ‘AppResources’ does not exist in the current context’
    Any idea why is this happening?

  7. Yes. I’ve followed all the steps on your guide, although I had to add the Helpers folder manually. I’ve reviewed everything but cannot find any wrong doing from my end. The error shows on the App.xaml.cs on the AppResources.culture = CrossMultilingual.Current.DeviceCultureInfo; line code.
    Thank you.

    1. mmmm, is your project a shared project? If is you should add the files AppResources.resx and AppResources.Designer.cs manually, and each time you add a value in the AppResources.resx that you will use in codebehind you should add it in the designer file manually.

      If is not a shared project:
      Are you sure your file is called AppResources? Can you send me a screenshot of your project structure and also the AppResources.designer file.

      1. Ok, I don’t think its a shared project. Also I don’t have an AppResources.designer (as far as I’m aware) file.

        Could you please confirm how to I send the screenshots and files to you?
        Thanks again.