更改运行时提取资源的位置?

发布于 2024-09-04 08:16:41 字数 754 浏览 10 评论 0原文

我有一个面向多个客户的网站。有时客户会坚持要求进行微小的更改。由于我无法控制的原因,无论多么微小的要求,我都必须遵守。通常这不是问题,我只需创建一个特定于客户端版本的用户控件或页面,并在构建时覆盖默认版本或进行配置设置来处理它。

现在我正在本地化该网站,我很好奇进行细微措辞更改的最佳方法。

假设我有一个名为 Resources.resx 的资源文件,其中包含 300 个资源。它有一个名为Continue 的资源。英语值为“Continue”,法语值为“Continuez”。

现在,无论出于何种原因,一位客户希望它说“下一步”和“之后”,而其他客户则希望保持不变。满足此类请求的最佳方式是什么? (这只是一个简单的例子)。

我能想到的唯一两种方法是

  • 创建另一个特定于客户端的 Resources.resx,并在构建时替换 .dll。由于我将完全替换 dll,因此新资源文件必须包含所有 300 个字符串。明显的问题是我现在有 2 个资源文件,每个资源文件有 300 个字符串需要维护。
  • 创建自定义用户控件/页面并将其更改为使用自定义资源文件。例如,SignIn.ascx 将在构建期间被替换,并且将从 ClientName.resx 而不是 Resources.resx 提取其资源。

还有其他我可以尝试的事情吗?有什么方法可以更改它,以便应用程序在实际查看指定的资源文件之前始终在 ClientResources.resx 文件中查找覆盖的值?

I have a website that goes out to multiple clients. Sometimes a client will insist on minor changes. For reasons beyond my control, I have to comply no matter how minor the request. Usually this isn't a problem, I would just create a client specific version of the user control or page and overwrite the default one during build time or make a configuration setting to handle it.

Now that I am localizing the site, I'm curious about the best way to go about making minor wording changes.

Lets say I have a resource file called Resources.resx that has 300 resources in it. It has a resource called Continue. English value is "Continue", the French value is "Continuez".

Now one client, for whatever reason, wants it to say "Next" and "Après" and the others want to keep it the same. What is the best way to accomodate a request like this? (This is just a simple example).

The only two ways I can think of is to

  • Create another Resources.resx specific to the client, and replace the .dll during build time. Since I'd be completely replacing the dll, the new resource file would have to contain all 300 strings. The obvious problem being that I now have 2 resource files, each with 300 strings to maintain.
  • Create a custom user control/page and change it to use a custom resource file. e.g. SignIn.ascx would be replaced during the build and it would pull its resources from ClientName.resx instead of Resources.resx.

Are there any other things I could try? Is there any way to change it so that the application will always look in a ClientResources.resx file for the overridden values before actually look at the specified resource file?

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

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

发布评论

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

评论(2

初熏 2024-09-11 08:16:41

您也许可以使用以下模板:

#if ClientName1 
Continue="Next";
#elif ClientName2
    Continue="Apres";
#else 
Continue="Continue" 
#endif

这允许您在同一文件中指定所有可能的值(以及同一区域中的相同变量),并且您可以在构建期间从命令行轻松定义符号“ClientName1”。

You could perhaps use the following template :

#if ClientName1 
Continue="Next";
#elif ClientName2
    Continue="Apres";
#else 
Continue="Continue" 
#endif

This allows you to specify all possible values in the same file (and the same variable in the same region), and you can easily define the symbol "ClientName1" from the commandline during the build.

何以畏孤独 2024-09-11 08:16:41

我不想这么说,但最简单的事情可能是在安装时使用自定义操作修改应用程序资源文件。

使用 ResXResourceWriter / ResXResourceReader 打开目标区域性的现有资源文件,并迭代要更改的标签。显然,只有在针对特定客户进行一些细微更改的情况下,这才有意义。这还假设资源文件未嵌入到程序集中。

为 Windows Installer 创建自定义操作非常简单,只要您愿意在安装完成后运行它们即可。

另一种方法是将默认的 ComponentResourceManager 替换为您自己的版本,该版本可以有选择地更改标签的值。这也会很快变得丑陋。

我能想到的最后一个技巧是将所有默认翻译放在基础资源文件中。自定义资源文件只需要更改它感兴趣的标签即可。任何留空的标签都将获取原始值。我不确定这有多现实,因为默认区域性可能是英语...

编辑:这可能是一个不那么黑客(仍然是黑客!)的解决方案。您可以在同一文化中创建另一个资源文件,例如比利时法语。比利时法语资源文件本质上继承自法语资源文件。这将允许您仅更改少数文本资源。然后,在您的应用程序中,将当前区域性更改为“fr-BE”而不是“fr”。客户可能永远不会知道。

I hate to say it, but the easiest thing might be to modify the application resource files with a custom action upon installation.

Using ResXResourceWriter / ResXResourceReader you and open the existing resource file(s) for the target culture and iterate through the tags you want to change. This obviously only makes sense if there are a few minor changes for a particular customer. This also assumes that the resource files are not embedded in the assembly.

Creating custom actions for Windows Installer is really easy as long as you are OK with running them after the installation completes.

An alternative would be to replace the default ComponentResourceManager with a version of your own that selectively changes the values of tags. This can also get ugly fast.

The last hack I can think of is to put all the default translation in the base resource file. The custom resource file only needs to change the tags it is interested in. Any tag left blank will get the original value. I'm not sure how realistic this is, as the default culture is likely English...

Edit: This may be a less hackish (still a hack!) solution. You can create another resource file within the same culture, like Belgian French. The Belgian French resource file will in essence inherit from the French resource file. This will allow you to change only a handful of text resources. Then, within your application, change the current culture to "fr-BE" instead of "fr". The customer will probably never know.

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