实施行业特定资源
我们有一个用于某个特定行业的程序,并且具有特定于该行业的字符串。我们现在的情况是它可以在另一个行业中使用,并且我们希望为该行业定制字符串而不重复我们的代码库。
问题空间看起来与本地化非常相似。我们是否要为每个行业建立单独的资源集合?如果是这样,我们什么时候选择使用哪个程序集,我们可以在安装时执行此操作还是需要在编译时执行此操作?我们如何保持单独的资源程序集同步,以便每个资源程序集中出现相同的消息键?
最好的方法是什么?
We have a program that is used in one specific industry and has strings that are specific to that industry. We now have the situation where it can be used in another industry and we want to customise the strings for that industry without duplicating our code base.
The problem space appears very similar to localisation. Are we going to have a separate resource assembly for each industry? If so when would we choose which assembly to use, could we do this at install time or would it need to be at compile time?. How do we keep the separate resource assemblies synchronised, so that the same keys to messages appear in each one?
What is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我重新表述一下:您有一个可用于各个行业的工业应用程序,唯一不同的是资源(即字符串、布局,也许还有图像和声音)。其他代码保持不变。
在这种情况下,您的问题不仅相似,而且实际上与本地化相同。因此,您可以使用卫星程序集.
现在,您可以选择单独打包此类创建的应用程序,还是将一个应用程序与两个问题空间一起分发。
第一个场景对我来说似乎更现实 - 您需要决定在编译时包含哪个 .resx 文件(即在项目准备期间,您将使用问题空间资源覆盖现有资源,然后继续编译,这应该为您的应用程序提供不同的风格;在这种情况下我也会修改它们的名称)。
后者需要您在运行时手动实例化
ResourceManager
以从有效的卫星程序集中读取 - 它可能基于某些配置文件。这意味着更多的工作(您需要实际修改您的代码),并且您最终将同时分发两种风格的应用程序,也就是说您将无法控制客户如何使用它。从商业角度来看,这可能有点危险。编辑(自我注意:仔细阅读整个问题)
不知何故,我设法错过了安装时间与编译时间。我相信编译时间就是答案,因为我在配置驱动切换部分给出的原因相同:您将打包资源,并且您将无法控制客户如何使用它。一些聪明的人会想到这一点,这是肯定的。
Let me re-phrase it: you have an industrial application which could be used in various industries and the only things that are different are resources (that is strings, layout, maybe images and sounds). The other code stays the same.
In such case your problem is not just similar it is actually identical to Localization. And as such you can use Satellite Assemblies.
Now, it is up to you if you want to package such created applications separately or distribute one application with both problem spaces.
The first seem more realistic scenario to me - you would need to decide on which .resx file to include at compile time (i.e. during project preparation you would overwrite existing resources with problem-space resources and then proceed with compilation, that should give you different flavors of your application; I would also modify their names in such case).
The latter would require you to manually instantiate
ResourceManager
at runtime to read from valid satellite assembly - it could be based on some configuration file. It means more work (you would need to actually modify your code) and you will end up distributing both flavors of your application at once, that is you won't have control over how your customers will use it. From the business perspective it could be a little dangerous.EDIT (Note to self: read whole question carefully)
Somehow I managed to miss install time vs. compile time. I believe compile time is the answer because of the same reason I gave in config-driven switch section: you would package the resources and you won't have any control on how customers use it. Some clever guy would figure it out, that is for sure.
我建议使用带有键值对的属性文件。如果您当前拥有行业特定字符串,请将其替换为对属性文件的调用。显然,您会将这些字符串缓存在某个容器中。我不知道 C# 容器 - Java 会使用 java.util.Properties。
I would recommend having a properties file with key value pairs. Where you currently have industry specific strings, replace them with calls to the properties file. Obviously you would cache these strings in some container. I don't know the C# container - Java would use
java.util.Properties
.