Xamarin.Forms.Localization 1.0.0

dotnet add package Xamarin.Forms.Localization --version 1.0.0                
NuGet\Install-Package Xamarin.Forms.Localization -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xamarin.Forms.Localization" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xamarin.Forms.Localization --version 1.0.0                
#r "nuget: Xamarin.Forms.Localization, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xamarin.Forms.Localization as a Cake Addin
#addin nuget:?package=Xamarin.Forms.Localization&version=1.0.0

// Install Xamarin.Forms.Localization as a Cake Tool
#tool nuget:?package=Xamarin.Forms.Localization&version=1.0.0                

Localization for Xamarin.Forms, Xamarin.iOS , Xamarin.Android, Xamarin.Mac and Xamarin.WPF

Powerfull netstandard plugin for handling language localization in Xamarin.Forms.

alternate text is missing from this package README image

NuGet

Features

  • Get and set current culture
  • Get device culture
  • Ensure device culture match available cultures or set a default culture even when culture are neutral and device culture is not.
  • Get culture list
  • Get specific culture by name
  • Raise event when current culture change to update Resources Culture
  • Detect FlowDirection based on current culture 🎁
  • No markup extension needed to bind resource messages
  • Intellisense available for Resources ❤️

Platform Support

Platform Version
Mono 5.4+
Xamarin.Forms 3.0+
Xamarin.iOS iOS 10.14+
Xamarin.Android API 14+
Windows 10 UWP 10+
Xamarin.Mac +3.8
watchOS All
tvOS All

Setup

  • Install into your Net Standard project (clients are not needed).

  • If you want to use in Android, iOS with no Xamarin.Forms dependency use the Sources package.

Getting Started

  1. Add your Resx files

alternate text is missing from this package README image

  1. Add one .resx file per language you want to support. As you can imagine it must follow a specific naming convention: use the same filename as the base resources file (eg. Messages) followed by a period (.) and then the language code.

alternate text is missing from this package README image

  1. In order to recognize the device language, you can use EnsureDeviceOrDefaultCulture, if device's language match available cultures, that culture will be set, otherwise, defaultCultureName will be used.

    Localization.Current.EnsureDeviceOrDefaultCulture(defaultCultureName:"en",
                                 availableCultures:new []{"en","ar","fr"});
    
  2. Set the culture of your resource class file when initializing your application.

    Messages.Culture = Localization.Current.CurrentCultureInfo;
    
  3. Ensure that you handle the language change event to ensure resource class Culture matchs.

    Localization.Current.OnCultureChanged += (culture)=>
    {
        Messages.Culture = culture;
    };
    

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

Xamarin Forms Specifics

This pacakage depends on new Xamarin.Forms 3.0 package with support to RTL content.

To use the resources in XAML, you need to import your resource class namespace and set any property value using the Static expression. You don't need any custom markup extension and it brings Intellisense support 😉

alternate text is missing from this package README image

iOS Considerations

In the Info.plist file add the keys Localizations & Localization native development region to change the user interface OS elements. It will take the device language.

alternate text is missing from this package README image

API Details

Call Localization.Current from any project or .net standard library project to gain access to APIs.

CurrentCultureInfo

Gets and set the current culture. By default will be set to the device culture.

Usage sample:

Localization.Current.CurrentCultureInfo = new CultureInfo("en");

CurrentNeutralCultureInfo

Gets the neutral culture version of the current culture.

Usage sample:

Localization.Current.CurrentNeutralCultureInfo;

DeviceCultureInfo

Gets the device culture

Usage sample:

Localization.Current.DeviceCultureInfo;

CultureInfoList

Gets all cultures supported in .NET Framework (neutral & specific cultures)

Usage sample:

Localization.Current.CultureInfoList;

NeutralCultureInfoList

Gets all cultures associated with a language (not specific to a country/region).

Usage sample:

Localization.Current.NeutralCultureInfoList;

GetCultureInfo

Gets a specific culture by language code.

Usage sample:

Localization.Current.GetCultureInfo("es");

IsRightToLeft

Gets true if the current culture is RTL language.

Usage sample:

Localization.Current.IsRightToLeft

FlowDirection

Gets a FlowDirection enum value used for Xamarin.Forms to add RTL support. For more information, review https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/right-to-left.

Usage sample:

  public partial class MainPage : ContentPage
  {
      public MainPage()
      {
          InitializeComponent();
          FlowDirection = Localization.Current.FlowDirection;
      }
  }
 

EnsureDeviceOrDefaultCulture(string defaultCultureName, params string[] availableCultures) Try to set the CurrentCultureInfo value based on device culture only if it matches available cultures.

Usage sample:

   Localization.Current.EnsureDeviceOrDefaultCulture(defaultCultureName:"en",
                                availableCultures:new []{"en","ar","fr"});

OnCultureChanged An event that arises when you change the CurrentCultureInfo.

Usage sample:

   Localization.Current.OnCultureChanged += (culture)=>
   {
       Messages.Culture = culture;
   };

Contributors

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 16,731 5/18/2018