Plugin._121ResxLocalization 1.0.7

dotnet add package Plugin._121ResxLocalization --version 1.0.7
NuGet\Install-Package Plugin._121ResxLocalization -Version 1.0.7
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="Plugin._121ResxLocalization" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin._121ResxLocalization --version 1.0.7
#r "nuget: Plugin._121ResxLocalization, 1.0.7"
#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 Plugin._121ResxLocalization as a Cake Addin
#addin nuget:?package=Plugin._121ResxLocalization&version=1.0.7

// Install Plugin._121ResxLocalization as a Cake Tool
#tool nuget:?package=Plugin._121ResxLocalization&version=1.0.7

121ResxLocalization

Xamarin Resx Localization

This plugin is to ease developer to implement resx localization in xamarin

Note: All of your projects under a solution must be using Xamarin Forms 3.3.0.912540 or later All projects must be using the same version of Xamarin Forms if not, there will be token error

After installing the plugin into your project from nuget: https://www.nuget.org/packages/Plugin._121ResxLocalization/1.0.0#

  1. Create a Resx folder inside your main project

  2. Create new resource file inside Resx folder, for English → AppResources.resx, for Spanish → AppResources.es.resx, and for others you can refer to this page: https://msdn.microsoft.com/en-us/library/cc233982.aspx

  3. Open your App.cs and insert lines below, please note that you need to change resourceBaseName and resourceAssembly to refer to your project:

         if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android)
         {
             Boolean checkLocal = Cross_121ResxLocalization.IsSupported;
             I_121ResxLocalization iService = Cross_121ResxLocalization.Current;
    
             // determine the correct, supported .NET culture
             var ci = iService.GetCurrentCultureInfo();
             Plugin._121ResxLocalization.TranslateExtension trE = new Plugin._121ResxLocalization.TranslateExtension(ci);
             Plugin._121ResxLocalization.TranslateExtension.resourceBasename = "<project name>.Resx.AppResources";
             Plugin._121ResxLocalization.TranslateExtension.resourceAssembly = IntrospectionExtensions.GetTypeInfo(typeof(< project name>.<any class>)).Assembly;
             Resx.AppResources.Culture = ci; // set the RESX for resource localization
             iService.SetLocale(ci); // set the Thread for locale-aware methods
         }
    

For example:

public App () { InitializeComponent();

        if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android)
        {
            Boolean checkLocal = Cross_121ResxLocalization.IsSupported;
            I_121ResxLocalization iService = Cross_121ResxLocalization.Current;
            
            // determine the correct, supported .NET culture
            var ci = iService.GetCurrentCultureInfo();
            Plugin._121ResxLocalization.TranslateExtension trE = new Plugin._121ResxLocalization.TranslateExtension(ci);
             Plugin._121ResxLocalization.TranslateExtension.resourceBasename = "<project name>.Resx.AppResources";
            Plugin._121ResxLocalization.TranslateExtension.resourceAssembly = IntrospectionExtensions.GetTypeInfo(typeof(< project name>.<any class>)).Assembly;
            Resx.AppResources.Culture = ci; // set the RESX for resource localization
            iService.SetLocale(ci); // set the Thread for locale-aware methods
        }

        MainPage = new TestLocalizationNuget.MainPage();
	}
	
  1. To apply localization in a page:

Please take a look at the sample: https://github.com/magiciangambit/121ResxLocalization/blob/121ResxLocalization/TestLocalizationNuget/TestLocalizationNuget/MainPage.xaml

  1. From the sample page, you can also find out how to change language during runtime on the button click:

'''

void OnButtonClicked(object sender, EventArgs e)
{
    if (((Button)sender).Text == "Set as English")
    {
	setLanguage("en-US");
    }
    else if (((Button)sender).Text == "Set as Spanish")
    {
	setLanguage("es-US");
    }
}

public void setLanguage(string languageCode)
{

    if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android)
    {
	CultureInfo ci = new CultureInfo(languageCode);
	DependencyService.Get<Plugin._121ResxLocalization.I_121ResxLocalization>().SetLocale(ci); // set the Thread for locale-aware methods
	Resx.AppResources.Culture = ci;

	Application.Current.Properties["currentLanguage"] = languageCode;
	Application.Current.MainPage = new MainPage();
    }
}

'''

  1. To use localization programmatically or from code, for example from the sample you can find these lines:

'''

	//set localization from coding
	public void setLocalizationFromCode()
	{
	    // create UI controls
	    var myLabel = new Label();
	    var myEntry = new Entry();
	    var myButton = new Button();
	    var myPicker = new Picker();
	    myPicker.Items.Add("0");
	    myPicker.Items.Add("1");
	    myPicker.Items.Add("2");
	    myPicker.Items.Add("3");
	    myPicker.Items.Add("4");

	    // apply translated resources
	    myLabel.Text = AppResources.NotesLabel;
	    myEntry.Placeholder = AppResources.NotesPlaceholder;
	    myPicker.Title = AppResources.PickerName;
	    myButton.Text = AppResources.AddButton;

	    // button shows an alert, also translated
	    myButton.Clicked += async (sender, e) =>
	    {
		AppResources.Culture = CultureInfo.CurrentCulture;
		var message = AppResources.AddMessageN;
		if (myPicker.SelectedIndex <= 0)
		{
		    message = AppResources.AddMessage0;
		}
		else if (myPicker.SelectedIndex == 1)
		{
		    message = AppResources.AddMessage1;
		}
		else
		{
		    message = String.Format(message, myPicker.Items[myPicker.SelectedIndex]);
		}
		await DisplayAlert(message, message, AppResources.CancelButton);
	    };

	    // add to screen
	    stack1.VerticalOptions = LayoutOptions.Center;
	    stack1.HorizontalOptions = LayoutOptions.FillAndExpand;
	    stack1.Children.Add(myLabel);
	    stack1.Children.Add(myEntry);
	    stack1.Children.Add(myButton);
	    stack1.Children.Add(myPicker);

	}
	

'''

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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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.  monoandroid81 is compatible. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed.  uap10.0.16299 is compatible. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed.  xamarinios10 is compatible. 
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.7 907 11/19/2018
1.0.6 670 11/19/2018
1.0.0 661 11/12/2018

version 1.0.0