我应该如何本地化可插拔组件

发布于 2024-08-06 04:15:55 字数 663 浏览 5 评论 0原文

我们有一个应用程序将从单独的 dll 动态加载一些组件。这些组件有固定的名称,但我们希望向用户显示本地化的名称,因此需要对名称进行本地化。

名称需要本地化这一事实并不是组件本身的问题,因此我们不想用 DisplayName 或 LocalizedName 这样的属性来污染组件的模型,并且让组件的资源存在于dll 的组件。但由于这些组件是可插入的,我们无法将显示名称的资源存在于应用程序中,因为当我们添加新组件时,应用程序的资源需要更新,这就违背了使组件可插入的目的。

这个问题有通用的解决方案吗?我们可以看到的可能解决方案是:

1\ 有一个名为显示名称的属性,GUI 代码调用该属性来显示名称。这工作正常,资源存在于与包含该组件的程序集(或其附属 dll)相同的 dll 中。但这似乎会用组件不应该关心的信息污染模型。

2\ 让带有 GUI 的应用程序从其自己的资源文件中查找指定组件的资源。这会失败,因为添加包含新动态加载组件的新程序集时,应用程序需要更新其资源。

3\ 让应用程序在组件所在的程序集的资源中查找组件的本地化名称。这似乎很好,因为本地化名称存在于组件的程序集中,因此随组件一起分发,但具有表示层的应用程序会从组件 dll 中查找本地化字符串,因此组件不需要了解有关该组件的任何信息。本地化,因此其模型没有受到污染。

选项3可以吗?还有其他我们没有考虑过的选择吗?

干杯...

We have an application which will dynamically load some components from separate dlls. These components have a fixed name but we want localised names to be displayed to the user and so the names need to be localised.

The fact that the name needs to be localised is not a concern of the component itself, so we don't really want to pollute the model of the component with a property like DisplayName or LocalisedName, and have the resources for the component live in the dll for the component. But as these components are pluggable we can't have the the resource for the display name live in the application, as then when we added new components, the resources for the application would need to be updated, defeating the point of making the components pluggable.

Is there are common solution to this issue? The possible solutions we could see were:

1\ Have a property called display name which the gui code calls to display the names. This works ok, with the resources existing in the same dll as (or satellite dlls of) the assembly that contains the component. But this seems to pollute the model with information that the component should not care about.

2\ Have the app with the GUI look up the resources for the named component from its own resource files. This fails because the app needs to have its resources updated when new assemblies containing new dynamically loaded components are added.

3\ Have the app look in the resources of the assembly the component came from for the localised name of the component. This seems good as the localised name exists in the assembly for the component so is distributed with it, but the app with the presentation layer instigates the lookup of the localised string from the components dll, so the component does not need to know anything about the localisation and so its model is not polluted.

Is option 3 possible? Is there some other option we have not considered?

cheers...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2024-08-13 04:15:55

选项3是我会做的,我认为这是可能的。如果您知道插件的名称并且可以使用反射实例化一个类。然后,您可以查询该类的 LocalizedName,插件将从其资源程序集中获取该名称。我想您了解卫星资源组件的工作原理。

#3 是否有某些特定内容不适合您?如果您指定什么不可以,我可能会提供帮助......

Option 3 is what I would do, and I think it's possible. If you know the name of the plugin and can instantiate a class using reflection. You then query that class for a LocalizedName, which the plugin would fetch from its resource assembly. I presume you understand how satellite resource assemblies work.

Is there something specific about #3 that does not work for you? If you specify what doesn't I might be able to help...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文