XLocalizer.TagHelpers 1.1.0

dotnet add package XLocalizer.TagHelpers --version 1.1.0
                    
NuGet\Install-Package XLocalizer.TagHelpers -Version 1.1.0
                    
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="XLocalizer.TagHelpers" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XLocalizer.TagHelpers" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="XLocalizer.TagHelpers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XLocalizer.TagHelpers --version 1.1.0
                    
#r "nuget: XLocalizer.TagHelpers, 1.1.0"
                    
#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.
#:package XLocalizer.TagHelpers@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XLocalizer.TagHelpers&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=XLocalizer.TagHelpers&version=1.1.0
                    
Install as a Cake Tool

Localizing Views in Asp.Net Core Razor Pages

By Ziya Mollamahmut

Read full docs at: docs.ziya.info.tr

XLocalizer has a handy extension pack; XLocalizer.TagHelpers for localizing views using a simple html tag.

Table of contents

Install

Install from nuget

PM > Install-Package XLocalizer.TagHelpers
Setup

Localize views using LocalizeTagHelper, first it must be added to `ViewImports.cshtml

@addTagHelper *, XLocalizer.TagHelpers
Localize texts

Localize texts/html contents using localize-content attribute with any html tag

<h1 localize-content>Sample header</h1>

<p localize-content>
    sample content...
</p>
Localize Html

Use <localize> html tag or to localize all its contents

<localize>
    <h1>Sample title</h1>
    <p>sample contents...</p>
<localize>
Localize Select Items

Use <localize-select> html tag to localize select items texts.

<localize-select asp-items="Model.MyItems"></localize-select>

Requires XLocalizer.TagHelpers v1.1.0 or later.

Localize attributes

Localize attributes like title inside <img tag using localize-att-*

<img src="/images/picture.jpg" localize-att-title="Picture title"/>
Provide arguments for localized contents

Localize a string that contains arguments by providing the arguments using localize-args

@{
    var args = new object[] { "http://demo.ziyad.info/en/localize", 8, "Asp.Net Core" }
}

<p localize-args="args">
    Visit <a href="{0}">demos website</a> to see a collection of {1} demos about "{2}".
</p>

Localized output sample: Visit demos website to see a collection of 8 demos about "Asp.Net Core".

Specify culture

Force specific culture regardless the request culture

<p localize-culture="tr">
    This content will always be localized with TR culture
</p>
Specify resource source

Specify localization resource type using localize-source

<p localize-source="typeof(MyResourceType)">
    This content will be localized from a specific shared resource.
</p>

See demo page.

Traditional localization for views

Default localization interfaces can be used to localize view contents:

@inject IStringLocalizer _localizer

<h1>@_localizer["Welcome"]</h1>
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on XLocalizer.TagHelpers:

Package Downloads
XLocalizer.DB.UI

Interface for managing localization with XLocalizer package and ability to use online translation tools.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 12,436 8/31/2021
1.0.0 3,188 11/12/2020
1.0.0-rc.1 390 11/5/2020
1.0.0-preview1 970 7/26/2020

New: localize-select taghelper for localization of select items.
Docs: https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-views.md
Release notes: https://github.com/LazZiya/XLocalizer.TagHelpers/releases