XperienceCommunity.Localizer 13.5.5

dotnet add package XperienceCommunity.Localizer --version 13.5.5
NuGet\Install-Package XperienceCommunity.Localizer -Version 13.5.5
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.Localizer" Version="13.5.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XperienceCommunity.Localizer --version 13.5.5
#r "nuget: XperienceCommunity.Localizer, 13.5.5"
#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.
// Install XperienceCommunity.Localizer as a Cake Addin
#addin nuget:?package=XperienceCommunity.Localizer&version=13.5.5

// Install XperienceCommunity.Localizer as a Cake Tool
#tool nuget:?package=XperienceCommunity.Localizer&version=13.5.5

XperienceCommunity.Localizer

Adds fallback support of Kentico Xperience's Localization keys/translations to the default IHtmlLocalizer/IStringLocalizer/IViewLocalizer)

In the past, most translation keys / translations were controlled through Kentico Xperience's Localization → Resource strings. This allowed users to create keys and translate them, with fall back to the default language.

This package restores that functionality, while allowing normal .resx resource file translations.

Installation and Requirements

Kentico Xperience 13 (.net 5.0) required (minimum hotfix 5). To install...

  1. Install the XperienceCommunity.Localizer package into your MVC site
  2. add this line of code in your startup
	services
		.AddLocalization()
        .AddXperienceLocalizer() // MUST call after AddLocalization() !

Usage

Use IHtmlLocalizer<> / IStringLocalizer<> as you would normally. Now you also can put in Kentico Xperience Localization macros in your strings as well. Here's some examples:

@inject IHtmlLocalizer<SharedResources> HtmlLocalizer;

<p>@HtmlLocalizer["myresource.key"]</p>
<p>@HtmlLocalizer.GetString("{$ general.greeting $}") Bob</p>

Resx help

.Net core can be confusing for resource file placement...very confusing. So let me lay out what i have:

In Startup

services.AddLocalization()
	.AddXperienceLocalizer() // Call after AddLocalization, adds Kentico Resource String support
	.AddControllersWithViews()
	.AddViewLocalization() // honestly couldn't get View Localization to ever work...
	.AddDataAnnotationsLocalization(options =>
	    {
	        options.DataAnnotationLocalizerProvider = (type, factory) =>
	        {
		        // This will use your ~/Resources/SharedResources.resx, with kentico fall back
	            return factory.Create(typeof(SharedResources));
	        };
	    });

In your Project

  1. Create a folder Resources under the root of your project.
  2. Create a class SharedResources.cs (namespace didn't seem to matter, but i put no namespace myself)
  3. Create a SharedResources.resx for your default translations, SharedResources.en.resx for your language translations, and SharedResources.en-US.resx for your culture specific language translations.

Logic will prefer the .language-Region.resx first, then the .language.resx second, then .resx third, and lastly it will use Xperience's Localization Resource Strings (matching language-Region first followed by site default).

Other Resource Files You can also add resource files specifically for certain areas, for example if you have a View Component /Components/MyThing/MyThingViewComponent , you can place a MyThingViewComponent.resx in the same folder as your class, and call IHtmlLocalizer<MyThingViewComponent> componentLocalizer and it should use that, and still fall back to Xperience's Localization Resource Strings.

Contributions, bug fixes and License

Thanks to Sean Wright for some more help on this one.

Feel free to Fork and submit pull requests to contribute.

You can submit bugs through the issue list and i will get to them as soon as i can, unless you want to fix it yourself and submit a pull request!

Check the License.txt for License information

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. 
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 XperienceCommunity.Localizer:

Package Downloads
XperienceCommunity.Baseline.Localization.Library.KX13

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
13.5.5 891 9/22/2023
13.5.5-beta 113 9/22/2023
13.5.4 2,916 2/1/2023
13.5.3 240 1/31/2023
13.5.2 260 1/24/2023
13.5.1 2,459 10/12/2022
13.5.0 6,378 12/30/2021

Fixed bug with Localization Strings containing {#} for string formatting, that it was not properly passing the string as is back.