This repository was archived by the owner on Oct 5, 2024. It is now read-only.
Localization (L10n) in the DB #4
markdav-is
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@Rolyac and I were talking about English/Spanish requirement for LHB and how it's a combination of strings in the UI and strings in the database. He shared a link to the UI guidance here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-7.0 and I recognized that's how Oqtane implements things in the UI using IStringLocalizer. Now I'm starting to think about the best way to deal with strings in the data using a similar method. RESX files are fine for the app UI but the format is not human readable so is a poor choice for storing in the database.
Here is a JSON localization implementation that might be useful https://github.com/AlexTeixeira/Askmethat-Aspnet-JsonLocalizer My thought being that each row in the database would have English as the default and then a i18n column with JSON for each column where locatization is available. Here's an example:
the L10n column holds JSON that looks like this:
Borrowing some code from the AskMeThat repo (link above) we should be able to have UI that looks similar to the following:
To accomplish the context. Localizer[] magic we'll need to extend the EF models with an IStringLocalizer implementation that digs into the Localized column JSON to fetch the proper value. Again, the AskMeThat repo (linked above) should have examples.
The added value to this approach is that it would be trivial to create SQL localized views using this method. A French view for example would look like this:
Beta Was this translation helpful? Give feedback.
All reactions