i18nStronglyTypedCore 1.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package i18nStronglyTypedCore --version 1.0.0.1                
NuGet\Install-Package i18nStronglyTypedCore -Version 1.0.0.1                
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.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add i18nStronglyTypedCore --version 1.0.0.1                
#r "nuget: i18nStronglyTypedCore, 1.0.0.1"                
#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.1

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

i18nStronglyTypedCore

This is the source code for the i18nStronglyTypedCore nuget package.

Github source code

About

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

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.

Prerequisites

  • Dotnet core 2.1+

To get up and running (quick tutorial)

  1. Create an asp.net core application.
  • In Visual Studio this is:

  • File > New > Project > Web Tab > Asp.NET Core Web Application

  • Give it a name (and location, not the one used in the pic) and hit ok

alt tag

  1. Choose the mvc option (which this tutorial uses) and hit ok.

alt tag

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

Install-Package i18nStronglyTypedCore

alt tag

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

alt tag

  1. 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>

alt tag

  1. Add a top level folder called 'Resources' (not in wwwroot) and create a class called i18n.

  2. Have that class inherit from i18nStronglyTypedCore.i18n and include the following property in the class.

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

alt tag

  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);

` alt tag

  1. In views/home/index, remove the standard content and add the following (remember to replace 'Testweb' 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>

alt tag

  1. Run the website. The end result should look like this.

NOTE: The provider will take from the current culture by default.

alt tag

  1. There are many ways to change the default culture. As a quick example, you could place the following in Startup.cs Configure method (before the resources code!)
var cultureInfo = new System.Globalization.CultureInfo("fr-FR");
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

alt tag `

  1. Now run the site. The default culture will also be in french. Remove the work done in step 10 to get back to normal.

alt tag

`

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 929 10/1/2018
1.0.0.5 760 9/28/2018
1.0.0.4 767 9/26/2018
1.0.0.3 810 9/20/2018
1.0.0.2 801 9/19/2018
1.0.0.1 792 9/19/2018