简体   繁体   English

跨多个应用程序和共享库(.net)处理多种语言

[英]Handling multiple languages across multiple applications and shared libraries (.net)

We are developing products that will be used in the following way: 我们正在开发将以以下方式使用的产品:

  • Various shared libraries which may be used by multiple products. 可以由多种产品使用的各种共享库。 I anticipate these libraries will mostly need to access string resources that contain error messages/exceptions. 我预计这些库将最需要访问包含错误消息/异常的字符串资源。
  • Various end-user based applications, designed to run as standalone apps on a PC. 各种基于最终用户的应用程序,旨在作为独立应用程序在PC上运行。 They will be required to support multiple languages upon deployment/installation. 在部署/安装时,将要求他们支持多种语言。
  • Various web-sites which may be required to support multiple languages either at deployment time or possibly at runtime (ie minimal or zero downtime). 可能需要在部署时或在运行时(即最少的停机时间或零停机时间)支持多种语言的各种网站。 Potentially the site might need to support multiple languages at the same time if being accessed globally. 如果全局访问该站点,则可能需要同时支持多种语言。
  • We may be required to allow customers access to our language files for editing themselves. 可能需要我们允许客户访问我们的语言文件以进行自我编辑。 We would not wish to allow them access to our source code (other than the resource files/dlls) in order to achieve this. 我们不希望允许他们访问我们的源代码(资源文件/ dll除外)以实现此目的。
  • We might need to incorporate a facility to log exceptions in our native language (English in this case) and display them in the translated language. 我们可能需要合并一种功能,以我们的母语(在这种情况下为英语)记录异常并以翻译后的语言显示它们。 This will help us debug our customers solutions in the field. 这将帮助我们调试现场的客户解决方案。

I am already aware of products like RCWinTrans and handling multiple languages in VC++/MFC applications. 我已经知道诸如RCWinTrans之类的产品,并且可以在VC ++ / MFC应用程序中处理多种语言。 However, the requirements we are faced with here are more extensive and thus require us to make a few up front decisions that could be difficult to change long term, so ideally we want to make the best choice now. 但是,我们在这里面临的要求更加广泛,因此要求我们做出一些长期的决定,这些决定可能很难长期改变,因此理想情况下,我们希望现在做出最佳选择。

Based on my own knowledge, I have a few questions although I may be missing some tricks with .net that will be happily received. 根据我自己的知识,我有几个问题,尽管我可能会缺少一些将很高兴获得的.net技巧。 Here are my questions: 这是我的问题:

  1. What would be best? 什么是最好的? Put all our resources in a seperate DLL per VS solution OR put the resources in each VS project. 每个VS解决方案将所有资源放入单独的DLL中,或者将资源放入每个VS项目中。 The way I see it per solution is easier to manage, modify, and allow customer access. 我对每个解决方案的查看方式更易于管理,修改和允许客户访问。 The per project solution seems cleaner though and makes the individual projects more portable. 每个项目的解决方案看起来更干净,并且使单个项目更具可移植性。 This method would apply to our shared library based solutions as well as our end-application based solutions. 此方法将适用于我们基于共享库的解决方案以及基于最终应用程序的解决方案。
  2. Does the solution above still stand with web sites? 上面的解决方案仍然适用于网站吗? Is there a better way? 有没有更好的办法? Does this way require downtime? 这样是否需要停机?
  3. Is it possible to have two seperate resource files loaded at once ie if we want to log the exceptions in English but supply them back up the food chain (as a message in an exception) in the translated language? 是否可以一次加载两个单独的资源文件,即如果我们要用英语记录例外情况,但以翻译后的语言将它们提供给整个食物链(作为例外情况的消息)? Are there any tricks we can use to automate this like AOP? 有什么技巧可以像AOP一样自动执行吗?

Thanks in Advance, 提前致谢,

Roger 罗杰

Have you considered using an Inversion of Control container like StructureMap or Unity ? 您是否考虑过使用Inversion of Control容器(例如StructureMapUnity) That may allow you to keep the default resources together with the project (which IMHO makes most sense), while still allowing a customer to locally override resources as necessary. 这可能使您可以将默认资源与项目(IMHO最有意义)保持在一起,同时仍允许客户根据需要在本地覆盖资源。

As an example, assume you have the following interface: 例如,假设您具有以下界面:

public interface IResourceSupplier
{
    // Returns the localized text for a given identifier.
    string Localized(string identifier);

    // Returns the invariant (English) text for a given identifier.
    string Invariant(string identifier);
}

Using IOC, you could create a centralized resource supplier for the solution which would check for user-supplied overrides. 使用IOC,您可以为解决方案创建集中式资源供应商,该供应商将检查用户提供的替代。 If no user override is provided, then you could query each of the project-specific resource suppliers (detected at application startup) until you locate one which returns the desired resource. 如果没有提供用户替代,则可以查询每个特定于项目的资源供应商(在应用程序启动时检测到),直到找到一个返回所需资源的供应商为止。

Obviously, depending on your needs you may need to tweak for performance, for example by caching frequently used resources. 显然,根据您的需求,您可能需要调整性能,例如,通过缓存常用资源。 Using IOC does give the advantage that as long as the interface does not change, plugging in an alternate implementation can be a relatively trivial task. 使用IOC的确具有以下优点:只要接口不变,插入替代实现可能是相对琐碎的任务。

Does this help? 这有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Auth 在多个 .net 核心应用程序之间共享 - Windows Auth shared across multiple .net core applications 使共享库可用于多个应用程序的最佳方法是什么? - What is the best way to make shared libraries available to multiple applications? 在多个应用程序中以SQL Server模式访问ASP.NET会话 - Access ASP.NET Session in SQL Server mode across multiple applications 多个.NET应用程序共享身份验证 - Multiple .NET Applications Share Authentication 添加本地化资源以在多个项目之间共享 - Add localization resources to be shared across multiple projects 跨多个连接的共享事务,或PostgreSQL中的ReadUncommitted - Shared transaction across multiple connections, or ReadUncommitted in PostgreSQL Linq获取的值不在多个列表中共享 - Linq get values not shared across multiple lists 跨多个用户和浏览器的会话处理 - Session handling across multiple users and browsers 跨多个域的多个应用程序(Web 和 Silverlight)之间的 SSO - SSO between multiple applications (web and silverlight) across multiple domain 记录和显示多种语言的.NET异常 - Log and display .NET exceptions in multiple languages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM