i18nStronglyTypedCore 1.0.0.6
dotnet add package i18nStronglyTypedCore --version 1.0.0.6
NuGet\Install-Package i18nStronglyTypedCore -Version 1.0.0.6
<PackageReference Include="i18nStronglyTypedCore" Version="1.0.0.6" />
paket add i18nStronglyTypedCore --version 1.0.0.6
#r "nuget: i18nStronglyTypedCore, 1.0.0.6"
// 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.
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:
- Strongly typed
- Seems pretty solid
- Only takes a couple of minutes to get up and running.
- Can handle multiple resource files.
- Can handle "per request" language responses (see tutorial)
The downsides to this package are:
- *Doesn't work with Attributes (the standard .net core one does)
- 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:
- 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>
- 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(); } }
- 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)
- 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>
- 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 | 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.
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