Skip to content

Localize TagHelper

Ziya Mollamahmut edited this page Mar 19, 2020 · 8 revisions

Setup

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

@addTagHelper *, LazZiya.ExpressLocalization

LocalizeTagHelper is included in LazZiya.ExpressLocalization starting from v4.0, for earlier versions it must be installed separately. See the bottom of this page for instructions.

Localize views

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 Tag

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

<localize>
    <h1>Sample title</h1>
    <p>sample contents...</p>
<localize>

Localize attributes

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

<img src="/images/picture.jpg" localize-att-title="Picture title"/>

Specify culture

Force specific culture regardless the request culture

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

Provide arguments for localized contents

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

@{
    var args = new[] { "http://demo.ziyad.info", 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".

Localization resource

Specify localization resource type using localize-source

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

See demo page.

Applies to ExpressLocalization versions:

4.0

Clone this wiki locally