Experience 13 database based localization with .NET Core app

Andy Bochmann asked on January 27, 2021 23:29

Hello,

I'm trying to get resource strings out of the Localization application inside a .NET Core MVC app, which as I understand, should be done using the build-in IHtmlLocalizer. It seems like IHtmlLocalizer only works with .resx files, but doesn't query the database.

If I use the code below, I get two different results. The first one just returns the key, because the key is not inside the .resx file, the 2nd one return the correct translation from the database.

@HtmlLocalizer[key]
@ResHelper.GetString(key)

So ResHelper.GetString(key) still works as expected and I could use that in my views. However, I believe in order to translate data annotations on my view model properties, I rely on IHtmlLocalizer.

How can I use IHtmlLocalizer or how can I translate data annotations using the database?

Thanks

Recent Answers


Andy Bochmann answered on January 28, 2021 01:35

I was able to use ResHelper by implementing a custom IStringLocalizer and IStringLocalizerFactory. Not sure if that's the proper solution. I assume Kentico would provide a build-in, better way to use the database as a localization source.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.