RedCorners.Forms.Localization 5.30.2

Easy and intuitive localization tools for Xamarin.Forms.

Install-Package RedCorners.Forms.Localization -Version 5.30.2
dotnet add package RedCorners.Forms.Localization --version 5.30.2
<PackageReference Include="RedCorners.Forms.Localization" Version="5.30.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RedCorners.Forms.Localization --version 5.30.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NuGet: https://www.nuget.org/packages/RedCorners.Forms.Localization

RedCorners.Forms.Localization is a lightweight and easy to use library for facilitating translations and localizations in Xamarin.Forms. It is available as a .NET Standard library and works on all of the platforms you can install Xamarin.Forms on.

It stores translations as a Dictionary of Dictionarys, where the parent Dictionary holds the mappings between language keys and their translations, and the child Dictionarys hold the mappings between translation keys and their values in each language.

This concept allows the translation engine to work perfectly with JSON data structures:

{
    "En": {
        "Hello": "Hello!",
        "HelloX": "Hello, {0}!",
        "Bye": "Bye!"
    },
    "Fr": {
        "Hello": "Salut!",
        "HelloX": "Salut, {0}!",
        "Bye": "Au revoir!"
    },
    "De": {
        "Hello": "Hallo!",
        "HelloX": "Hallo, {0}!",
        "Bye": "Tschüss!"
    }
}

Getting Started

Everything is located under the RedCorners.Forms.Localization namespace inside the RL static class:

using RedCorners.Forms.Localization;

Full Documentation: http://redcorners.com/localization/

After installing the RedCorners.Forms.Localization package and its dependencies, you have a few different ways to load the translations. The most straightforward way is to call the Load method with a Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;, containing a structure similar to the one above:

RL.Load(map);

If you have a dictionary for each language, you can load them individually like this:

Dictionary<string, string> english, french, german;

RL.Load("En", english);
RL.Load("Fr", french);
RL.Load("De", german);

The RL class provides an additional overload of the Load method for automatically loading translations from embedded resources. Assume the scenario where three JSON files are set as embedded resources inside a project with the default namespace LocalizationDemo and the .trans.json file extensions:

<img src="https://redcorners.com/images/localization_000.PNG" class="free-width" />

You can automatically load all the files by calling this special overload of RL:

<img src="https://redcorners.com/images/localization_001.PNG" class="free-width" />

namespace LocalizationDemo
{
    public class App : Application2
    {
        public override void InitializeSystems()
        {
            base.InitializeSystems();
            RL.Load(typeof(App), "LocalizationDemo.", ".trans.json");
        }
    }
}

Changing the Language

You can change the current language by calling the SetLanguage method. RL provides an OnLanguageChange event, which is triggered whenever the language is changed. You can use this event to restart or update your UI layer to reflect the new language:

RL.SetLanguage("En");
RL.OnLanguageChange += (o, e) => ShowFirstPage();

The GetLanguageKeys() method returns a list of all loaded language keys (e.g. En, Fr or De). This is derived from the file names, based on the parameters of the Load method.

Performing Localizations

The L method provides the values of the specified key in the selected language:

Console.WriteLine(RL.L("Hello"));

In case the translation value requires a parameter, you can provide them to the L method:

Console.WriteLine(RL.L("HelloX", "Alice"));
//Prints "Hello, Alice!"

XAML Syntax

You can use the RL tools in Xamarin.Forms XAML. To do this, first include the namespace:

xmlns:rl="clr-namespace:RedCorners.Forms.Localization;assembly=RedCorners.Forms.Localization"

Once you have this, you can use the RL XAML extension to quickly provide localized strings:

<Label Text="{rl:RL Hello}" />

NuGet: https://www.nuget.org/packages/RedCorners.Forms.Localization

RedCorners.Forms.Localization is a lightweight and easy to use library for facilitating translations and localizations in Xamarin.Forms. It is available as a .NET Standard library and works on all of the platforms you can install Xamarin.Forms on.

It stores translations as a Dictionary of Dictionarys, where the parent Dictionary holds the mappings between language keys and their translations, and the child Dictionarys hold the mappings between translation keys and their values in each language.

This concept allows the translation engine to work perfectly with JSON data structures:

{
    "En": {
        "Hello": "Hello!",
        "HelloX": "Hello, {0}!",
        "Bye": "Bye!"
    },
    "Fr": {
        "Hello": "Salut!",
        "HelloX": "Salut, {0}!",
        "Bye": "Au revoir!"
    },
    "De": {
        "Hello": "Hallo!",
        "HelloX": "Hallo, {0}!",
        "Bye": "Tschüss!"
    }
}

Getting Started

Everything is located under the RedCorners.Forms.Localization namespace inside the RL static class:

using RedCorners.Forms.Localization;

Full Documentation: http://redcorners.com/localization/

After installing the RedCorners.Forms.Localization package and its dependencies, you have a few different ways to load the translations. The most straightforward way is to call the Load method with a Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;, containing a structure similar to the one above:

RL.Load(map);

If you have a dictionary for each language, you can load them individually like this:

Dictionary<string, string> english, french, german;

RL.Load("En", english);
RL.Load("Fr", french);
RL.Load("De", german);

The RL class provides an additional overload of the Load method for automatically loading translations from embedded resources. Assume the scenario where three JSON files are set as embedded resources inside a project with the default namespace LocalizationDemo and the .trans.json file extensions:

<img src="https://redcorners.com/images/localization_000.PNG" class="free-width" />

You can automatically load all the files by calling this special overload of RL:

<img src="https://redcorners.com/images/localization_001.PNG" class="free-width" />

namespace LocalizationDemo
{
    public class App : Application2
    {
        public override void InitializeSystems()
        {
            base.InitializeSystems();
            RL.Load(typeof(App), "LocalizationDemo.", ".trans.json");
        }
    }
}

Changing the Language

You can change the current language by calling the SetLanguage method. RL provides an OnLanguageChange event, which is triggered whenever the language is changed. You can use this event to restart or update your UI layer to reflect the new language:

RL.SetLanguage("En");
RL.OnLanguageChange += (o, e) => ShowFirstPage();

The GetLanguageKeys() method returns a list of all loaded language keys (e.g. En, Fr or De). This is derived from the file names, based on the parameters of the Load method.

Performing Localizations

The L method provides the values of the specified key in the selected language:

Console.WriteLine(RL.L("Hello"));

In case the translation value requires a parameter, you can provide them to the L method:

Console.WriteLine(RL.L("HelloX", "Alice"));
//Prints "Hello, Alice!"

XAML Syntax

You can use the RL tools in Xamarin.Forms XAML. To do this, first include the namespace:

xmlns:rl="clr-namespace:RedCorners.Forms.Localization;assembly=RedCorners.Forms.Localization"

Once you have this, you can use the RL XAML extension to quickly provide localized strings:

<Label Text="{rl:RL Hello}" />

Release Notes

Easy and intuitive localization tools for Xamarin.Forms.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.30.2 49 9/16/2019
5.30.1 52 9/9/2019
4.11.0-alpha 56 6/26/2019