i18nStronglyTypedCore 1.0.0.6

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

// Install i18nStronglyTypedCore as a Cake Tool
#tool nuget:?package=i18nStronglyTypedCore&version=1.0.0.6                

i18nStronglyTypedCore

This is the source code for the i18nStronglyTypedCore nuget package.

Github source code

About

This is a .net core port of afana's excellent i18n (internationalization) provider for MVC 5, using xml for the resource strings.

There's also some extras, such as per request language responses and multiple resource file handling (see tutorial below).

Of course, dotnet core has its' own i18n provider but like many people, I'd rather keep things strongly typed as much as possible. It's simple to get up and running.

The upsides to this package are:

  1. Strongly typed
  2. Seems pretty solid
  3. Only takes a couple of minutes to get up and running.
  4. Can handle multiple resource files.
  5. Can handle "per request" language responses (see tutorial)

The downsides to this package are:

  1. *Doesn't work with Attributes (the standard .net core one does)
  2. If you create the c# part, but forget to put the corresponding row in the xml, the error is a bit tricky to work out.

Prerequisites

  • Dotnet core 2.1+

To get up and running

(see deeper tutorial with screenshots at Github if needed)

It's really simple to get going and only takes a few minutes. Assuming an MVC Core project:

  1. Via the CLR or Package Manager (View > Other Windows > Package Manager Console) enter the following, then hit enter:

Install-Package i18nStronglyTypedCore

  1. In wwwroot, add a folder called 'Resources' and in that add an xml file called 'Resources.xml'.

  2. In resources.xml, insert the following placeholder content:

WARNING: The following example has the default culture to be British English (en-GB). You may need en-US or another culture.

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    
    <resource culture="en-GB" type="string" name="Site_Name" value="Site name (english)"></resource>
    
    
    <resource culture="fr-FR" type="string" name="Site_Name" value="Site name (Francais)"></resource>

</resources>
  1. Create a class and have that class inherit from i18nStronglyTypedCore.i18n (I made a class called 'i18n.cs' in a 'Resources' folder). Include the following property in the class.

public static string Site_Name { get { return GetStringValue(); } }

  1. In startup.cs 'Configure' method, add the following 2 lines to initialise the resources.
var pathToResources = System.IO.Path.Combine(env.WebRootPath, @"Resources\Resources.xml");
Resources.i18n.InitResources(pathToResources);

NOTE: If you have more than one resource file, you can add multiple files as shown below (but don't copy for this tutorial, as we only have 1 resource file)

  1. In views/home/index, remove the standard content and add the following (remember to replace 'Testweb.Resources' with you own website's namespace).
@{
    ViewData["Title"] = "Home Page";
}
<h4>English Site Name</h4>
<p>@Testweb.Resources.i18n.Site_Name</p>

<h4>French Site Name</h4>
<p>@Testweb.Resources.i18n.GetLocalisedStringValue(() => Testweb.Resources.i18n.Site_Name, "fr-FR")</p>
  1. Run it to see the results.

More details

If you are unsure of how to set the culture, how to add more resource files or add more properties, see the detailed tutorial at github source readme.

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.
  • .NETStandard 2.0

    • No dependencies.

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.6 927 10/1/2018
1.0.0.5 758 9/28/2018
1.0.0.4 765 9/26/2018
1.0.0.3 808 9/20/2018
1.0.0.2 799 9/19/2018
1.0.0.1 790 9/19/2018

1.0.0.6 - New public method 'SetCustomResourcesCulture' to enable getting of all resources in a different locale to CurrentUICulture.
1.0.0.5 - Additional public method to get a list of locales available (from the resources).
1.0.0.4 - Change to metadata only
1.0.0.3 - Can now have multiple resource files