是否有用于处理本地化的.NET标准,但允许用户自定义文本? [英] Is there any .NET standard for dealing with localization yet allowing the users to customize the texts?

查看:66
本文介绍了是否有用于处理本地化的.NET标准,但允许用户自定义文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个ASP.NET MVC应用程序,该应用程序尚无法使用大量数据注释DisplayAttribute进行本地化,这些代码在整个代码中都具有硬编码的字符串和硬编码的消息字符串.

现在,我们要求应用程序必须是可本地化的,但仍然需要允许用户自定义字段显示和文本.

到目前为止,我正在考虑将RESX文件与自定义IResourceProvider一起使用.瑞克·斯特拉尔(Rick Strahl)写了关于此的好文章.用这种方法,应用程序是用标准的RESX文件开发的,但是在运行时,当应用程序需要字符串时,定制提供程序将查询数据库以查找定制,并在找到时使用它们.

尽管这似乎是一个很好的解决方案,但它似乎并不自然.我想知道是否还有更好的选择.

这有什么标准吗?

解决方案

使用静态值作为默认值并检查数据库中的本地化值是不自然的吗?对我来说,这是一个很好的方法,因为如果有人将db中的资源弄乱了,例如,以某种方式删除了其中的一个,那么您总是会显示默认文本.

您总是可以以不同的方式进行操作,只需使用基于db的文本就不必担心更改代码中的默认值和数据库中的转换,因为在资源很少的情况下很容易错过某些内容.大约2年前,当我检查 nopCommerce 的代码时,我发现当他们使用数据库中的资源进行本地化时只要.我不确定现在如何完成,但是您可以下载源代码并进行检查.

在一年前开发的WinForms应用程序中,我正在将XML文件用于不同的语言,因为我们的客户希望能够允许非技术人员创建新的语言文件.我创建了内置在应用程序中的本地化工具,但是对于网站而言,最好使用数据库,因为您已经可以访问数据库并且可以轻松地操作数据.

您可以在此博客文章中了解有关此主题的更多信息. /p>

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?

解决方案

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.

这篇关于是否有用于处理本地化的.NET标准,但允许用户自定义文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆