i18nStronglyTypedCore 1.0.0.1
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
<PackageReference Include="i18nStronglyTypedCore" Version="1.0.0.1" />
paket add i18nStronglyTypedCore --version 1.0.0.1
#r "nuget: i18nStronglyTypedCore, 1.0.0.1"
// 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.
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)
- 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
- Choose the mvc option (which this tutorial uses) and hit ok.
- Via the CLR or Package Manager (View > Other Windows > Package Manager Console) enter the following, then hit enter:
Install-Package i18nStronglyTypedCore
- In wwwroot, add a folder called Resources and in that add an xml file called Resources.xml
- 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>
Add a top level folder called 'Resources' (not in wwwroot) and create a class called
i18n
.Have that class inherit from
i18nStronglyTypedCore.i18n
and include the following property in the class.
public static string Site_Name { get { return GetStringValue(); } }
- 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);
`
- 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>
- Run the website. The end result should look like this.
NOTE: The provider will take from the current culture by default.
- 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;
`
- Now run the site. The default culture will also be in french. Remove the work done in step 10 to get back to normal.
`
Product | Versions 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. |
-
.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.