LazZiya.TagHelpers.Localization
1.3.0
For full benefit and easier use, LocalizeTaghelper has been moved to LazZiya.ExpressLocalization nuget package.
dotnet add package LazZiya.TagHelpers.Localization --version 1.3.0
NuGet\Install-Package LazZiya.TagHelpers.Localization -Version 1.3.0
<PackageReference Include="LazZiya.TagHelpers.Localization" Version="1.3.0" />
paket add LazZiya.TagHelpers.Localization --version 1.3.0
#r "nuget: LazZiya.TagHelpers.Localization, 1.3.0"
// Install LazZiya.TagHelpers.Localization as a Cake Addin #addin nuget:?package=LazZiya.TagHelpers.Localization&version=1.3.0 // Install LazZiya.TagHelpers.Localization as a Cake Tool #tool nuget:?package=LazZiya.TagHelpers.Localization&version=1.3.0
LazZiya.TagHelpers.Localization
Use html tag to localize texts and html contents in razor pages for Asp.Net Core web applications. And automatically have the {culture}
parameter added to route values for every anchor.
Release history
- v1.3.0 - 04.01.2020
- New breaking change - CultureAnchoreTagHelper : Automatically add
{culture}
to the route values of all anchor taghelpers.
Installation
Install from nuget :
Install-Package LazZiya.TagHelpers.Localization
Then add localize tag helper to _ViewImports.cshtml file
@addTagHelper *, LazZiya.TagHelpers.Localization
@* IMPORTANT : starting from v1.3.0 *@
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.AnchorTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
Localize TagHelper Usage
Use localize tag directly:
<localize>Hellow world!</localize>
Use localize attributes in any html tag:
<h1 localize-content>Hello world!</h1>
Localize html contents:
<div localize-content>
<h2>Title</h2>
<p>Details...</p>
</div>
Use localization args:
<p localize-args="@(new object[] { 123, DateTime.Now })">
The number is {0}, the date is {1}
</p>
Localize attributes e.g. alt attribute:
<img src="/images/lost-image.png" localize-att-alt="Cake and juice image" />
CultureAnchorTagHelper
Starting from v1.3.0 it is not necessary to manually add asp-route-culture="culture"
to every link. With the new built-in CultureAnchorTagHelper
the current culture will be added to the route value automatically.
A - Enable CultureAnchorTagHelper (default)
The tag helper is enabled by default, but it requires removing the framework's AnchorTagHelper
from _ViewImports
:
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.AnchorTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
So using an anchor as below will produce link with culture /en/Index
:
<a localize-content asp-page="/Index">Home</a>
B - Disable CultureAnchorTagHelper
If you still want to use the default AnchorTagHelper
just remove the CultureAnchorTagHelper
from _ViewImports
:
@removeTagHelper LazZiya.TagHelpers.Localization.CultureAnchorTagHelper, LazZiya.TagHelpers.Localization
But in this case you will need to manually add asp-route-culture="..."
to every link.
<a localize-content asp-page="/Index" asp-route-culture="@culture">Home</a>
dependencies
Two nuget packages will be installed automatically with TagHelpers.Localization :
- LazZiya.ExpressLocalization : required for localization setup
- LazZiya.TagHelpers : main TagHelpers package
Check for updates after install.
Localization Setup
In order for localize tag helper to work the localization setup must be done in startup.cs as described in LazZiya.ExpressLocalization
Live demos:
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 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 is compatible. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
-
.NETCoreApp 2.0
- LazZiya.ExpressLocalization (>= 3.1.3)
-
.NETCoreApp 2.1
- LazZiya.ExpressLocalization (>= 3.1.3)
-
.NETCoreApp 2.2
- LazZiya.ExpressLocalization (>= 3.1.3)
-
.NETCoreApp 3.0
- LazZiya.ExpressLocalization (>= 3.1.3)
-
.NETCoreApp 3.1
- LazZiya.ExpressLocalization (>= 3.1.3)
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 |
---|
- New: automatically add culture parameter to anchor tags