XperienceCommunity.Localization 1.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package XperienceCommunity.Localization --version 1.4.1
                    
NuGet\Install-Package XperienceCommunity.Localization -Version 1.4.1
                    
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="XperienceCommunity.Localization" Version="1.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XperienceCommunity.Localization" Version="1.4.1" />
                    
Directory.Packages.props
<PackageReference Include="XperienceCommunity.Localization" />
                    
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 XperienceCommunity.Localization --version 1.4.1
                    
#r "nuget: XperienceCommunity.Localization, 1.4.1"
                    
#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 XperienceCommunity.Localization@1.4.1
                    
#: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=XperienceCommunity.Localization&version=1.4.1
                    
Install as a Cake Addin
#tool nuget:?package=XperienceCommunity.Localization&version=1.4.1
                    
Install as a Cake Tool

XperienceCommunity.Localization

CI: Build and Test Localization NuGet Package

Description

This project enables creating and using localizations and translations in Xperience by Kentico project. Create translations in Xperience admin UI or programatically and use in your pages.

Screenshots

Administration localization edit form Administration key listing page

Library Version Matrix

Xperience Version Library Version
>= 29.6.0 >= 1.4.0
>= 29.2.0 >= 1.2.0
>= 28.4.3 1.0.0

Dependencies

Package Installation

Add the package to your application using the .NET CLI

dotnet add package XperienceCommunity.Localization

Quick Start

  1. Add this library to the application services.

    // Program.cs
     builder.Services.AddXperienceCommunityLocalization();
    
  2. Open the Localization application added by this library in the Xperience's Administration.

  3. Press Create to add a localization.

  4. Fill out the key and the description of the localized content.

  5. Add translations for the desired content languages. Administration localization edit form

  6. Display the results on your site with a ViewComponent.

    
    // ViewModelLocalizedWidgetViewComponent.cs
    private readonly IKenticoStringLocalizer localizer;

    public ViewModelLocalizedWidgetViewComponent(IKenticoStringLocalizer localizer)
        => this.localizer = localizer;

    public IViewComponentResult Invoke()
    {
        var model = new ViewModelLocalizedWidgetViewModel
        {
            Title = localizer["Title"],
            Content = localizer["Content"]
        };

        return View("~/Components/Widgets/ViewModelLocalizedWidget/_ViewModelLocalizedWidget.cshtml", model);
    }

Administration string localizer example

  1. Or display the results on your site with a Razor View 👍

@using XperienceCommunity.Localization

@inject IKenticoHtmlLocalizer localizer

<div>
    <h1>@localizer["Title"]</h1>
    <p>@localizer["Content"]</p>
</div>

Administration html localizer example

Customization

Administration does not allow for storing empty string values as the translations. By default, if a specified key in a specified language does not exist the name of the key is returned.

You can override this functionality by specifying your own implmentation of IKenticoHtmlLocalizer and IKenticoStringLocalizer. Default implementations are the KenticoHtmlLocalizer and the KenticoStringLocalizer.

This can be useful if you want to display a value in one language and display nothing in a different language. To achieve this, you can inherit the KenticoHtmlLocalizer or the KenticoStringLocalizer.

public class ExampleHtmlLocalizer : KenticoHtmlLocalizer
{
    public override string? GetStringByName(string name)
    {
        string culture = CultureInfo.CurrentCulture.ToString();

        // return empty string instead of null.
        return localizationService.GetValueByNameAndCulture(name, culture) ?? string.Empty;
    }
}

Similarly implement the IKenticoStringLocalizer, or use the default KenticoStringLocalizer

// In your Program.cs
// ... Other registrations
builder.Services.AddXperienceCommunityLocalization<ExampleHtmlLocalizer, KenticoStringLocalizer>();

Contributing

Instructions and technical details for contributing to this project can be found in Contributing Setup.

License

Distributed under the MIT License. See LICENSE.md for more information.

Support

This project has Limited support.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on XperienceCommunity.Localization:

Package Downloads
XperienceCommunity.Baseline.Localization.Admin.Xperience

The Baseline a set of Core Systems, Tools, and Structure to ensure a superior Kentico Website that's easy to migrate, for Kentico Xperience 13 and eventually Xperience by Kentico

XperienceCommunity.Essentials

Package Description

XperienceCommunity.AdminExtensions

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 4,772 2/14/2025
2.0.0 585 12/20/2024
1.4.1 425 10/18/2024
1.4.1-pre.9c79180 126 10/18/2024
1.4.1-pre.782df4b 124 10/18/2024
1.4.1-pre.501b2b6 115 10/18/2024
1.2.2 314 7/11/2024
1.2.2-pre.e63914d 118 10/18/2024
1.2.2-pre.95a5373 81 7/11/2024
1.2.2-pre.8fa780a 87 7/11/2024
1.2.2-pre.614044a 106 10/18/2024
1.2.2-pre.2a9f442 118 10/18/2024
1.2.2-pre.107ba0f 85 7/11/2024
1.2.1 153 7/11/2024
1.2.1-pre.db6a0d4 86 7/11/2024
1.2.1-pre.8fa780a 94 7/11/2024
1.1.1 477 5/15/2024
1.1.1-pre.5b89503 90 5/14/2024
1.1.1-pre.2aea3c9 83 7/11/2024
1.0.7-pre.bb77ad6 100 5/14/2024
1.0.7-pre.903c108 102 5/14/2024
1.0.6 176 5/14/2024
1.0.6-pre.bb77ad6 84 5/14/2024
1.0.4 200 5/14/2024
1.0.4-pre.5b89503 97 5/14/2024