Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any .NET standard for dealing with localization yet allowing the users to customize the texts?

We're building an ASP.NET MVC application that is yet not localizable with a lot of Data Annotations DisplayAttribute with hard-coded strings and hard-coded message strings all over the code.

Now we have a requirement that the application must be localizable, but still, we need to allow the users to customize the field displays and the texts.

So far, I'm considering using RESX files with a custom IResourceProvider. Rick Strahl has written a good article about that. In this approach, the application is developed with standard RESX files, but in runtime, when the application need the strings, the custom provider will query the DB looking for customizations and will use them when found.

Even though it seems a good solution, it doesn't seem natural. I wonder if there's some better alternative.

Is there any standard for this?

like image 734
André Pena Avatar asked Nov 13 '22 12:11

André Pena


1 Answers

What's not natural with using static values as defaults and checking database for localized ones? For me it's nice approach, because if someone will mess recources in db and, for example, remove one of them somehow, you'll always have a default text to display.

You can always do it in different way, by using only the db-based texts to not bother about changing defaults in your code and translations in database because it's easy to miss something when resources are in few places. When I was checking code of nopCommerce maybe 2 years ago, I've seen that when they do localization with resources from database only. I'm not sure how it's done now, but you can download source code and check it.

In WinForms app I developed a year ago I was using XML files for different languages because our customer wanted to be able to allow non-technical natives to create new language files. And I created localization tool built-in into app, but for websites it's best to use database, as you already have access to this and can easily manipulate data.

You can read more about this topic in this blog post.

like image 88
Konrad Gadzina Avatar answered Nov 15 '22 13:11

Konrad Gadzina