Aspnetcore: Allow custom localization of blazor components from an external library

Created on 8 Nov 2019  路  4Comments  路  Source: dotnet/aspnetcore

Is your feature request related to a problem? Please describe.

If an app uses a third-party blazor components library (i.e. a library that I have no control over), it might be necessary to customize some of the localization strings that the library provides out of the box.

For example, consider the following repo:
https://github.com/Stamo-Gochev/blazor-test-localization/tree/external-lib

A custom component is localized using resx files.

I want to override the the displayed output of this component, so that the value of key1 is something different in let's say French.

Describe the solution you'd like

I would like a way override the .resx files from an blazor app that uses this external blazor components library. The following is just one suggestion for how this can be done, there might be a better way.

For example, adding a file called CustomLocalizedComponent.fr.resx in a special (not currently supported) folder called App_GlobalResources (or use a better name) will allow the custom localization strings to be read from App_GlobalResources/CustomLocalizedComponent.fr.resx instead of the ones from the location of the external library.

area-blazor question

Most helpful comment

This is an example:
https://github.com/aspnet/AspNetCore/blob/master/src/Identity/Extensions.Core/src/IdentityErrorDescriber.cs

The idea here is you derive from the class and override the error messages you want, and register the implementation in DI so that it gets applied transparently.

All 4 comments

@Stamo-Gochev thanks for contacting us.

I don't think that is something specific to Blazor or that we can generally do.

I think its the library authors to provide a good way to localize their library if they choose to do so, in a way that other developers do it. For example, ASP.NET Core Identity offers a class with all the messages that are meant to be user facing and that developers can customize to change or localize the contents.

Unfortunately, I don't think we plan to do anything in this regard, as it will not be a trivial investment, it is not directly tied to Blazor but to the resx localization system (as far as I understand) and there are existing patterns to offer this functionality without resorting in the platform implementing something.

I know this doesn't help your case, but my recommendation would be to contact the developers of the third party library and ask them to make the localization content extensible.

@javiercn Thanks for the clarification.
Can you share a link to this class, so I can check if the approach can be used?

This is an example:
https://github.com/aspnet/AspNetCore/blob/master/src/Identity/Extensions.Core/src/IdentityErrorDescriber.cs

The idea here is you derive from the class and override the error messages you want, and register the implementation in DI so that it gets applied transparently.

I'm closing this issue as the question has been answered.

Was this page helpful?
0 / 5 - 0 ratings