XperienceCommunity.Localizer
13.5.3
See the version list below for details.
dotnet add package XperienceCommunity.Localizer --version 13.5.3
NuGet\Install-Package XperienceCommunity.Localizer -Version 13.5.3
<PackageReference Include="XperienceCommunity.Localizer" Version="13.5.3" />
paket add XperienceCommunity.Localizer --version 13.5.3
#r "nuget: XperienceCommunity.Localizer, 13.5.3"
// Install XperienceCommunity.Localizer as a Cake Addin #addin nuget:?package=XperienceCommunity.Localizer&version=13.5.3 // Install XperienceCommunity.Localizer as a Cake Tool #tool nuget:?package=XperienceCommunity.Localizer&version=13.5.3
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...
- Install the
XperienceCommunity.Localizer
package into your MVC site - 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
- Create a folder
Resources
under the root of your project. - Create a class
SharedResources.cs
(namespace didn't seem to matter, but i put no namespace myself) - Create a
SharedResources.resx
for your default translations,SharedResources.en.resx
for your language translations, andSharedResources.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 | Versions 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. |
-
net5.0
- Kentico.Xperience.AspNetCore.WebApp (>= 13.0.5)
- Scrutor (>= 3.3.0)
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.
Made Resolution use the dictionary from cached call, so once resource string updated it would properly rebuild the cache.