简体   繁体   English

CultureInfo和(resx)资源文件

[英]CultureInfo and (resx) Resource Files

Ive been using C#s (Visual Studios) resourcing mechanism and its worked nicely. 我一直在使用C#(Visual Studios)的资源配置机制,并且运行良好。 I have a need to be able to use resources but instead of using CultureInfo as the determinator use something else. 我需要能够使用资源,但不能将CultureInfo用作决定因素,而要使用其他东西。 This is my current setup which works fine however I have to workout which Resource Manager to use. 这是我当前的设置,可以正常工作,但是我必须锻炼要使用的资源管理器。 Either Brussels or Paris. 布鲁塞尔或巴黎。 The Resource Manager then works out which resource to use within Brussels or Paris to invoke. 然后,资源管理器确定要在布鲁塞尔或巴黎使用的资源。 What I want is one resource manager for both, so I dont need to decide which resource manager to use. 我想要的是两者都使用一个资源管理器,因此我不需要决定要使用哪个资源管理器。 Part of the problem is the PublicResXFileCodeGenerator Custom Tool generates the code for you (which is very nice if you use the standard approach) 问题的一部分是PublicResXFileCodeGenerator定制工具为您生成代码(如果您使用标准方法,这非常好)

This is what it currently looks like (This is working fine) 这是当前的样子(工作正常)

Brussels Resources 布鲁塞尔资源

  • brussels.en-GB.resx 布鲁塞尔-GB.resx
  • brussels.ja-JP.resx 布鲁塞尔
  • brussels.fr-FR.resx brussels.fr-FR.resx
  • brussels.resx 布鲁塞尔

Paris 巴黎

  • paris.en-GB.resx paris.en-GB.resx
  • paris.ja-JP.resx paris.ja-JP.resx
  • paris.fr-FR.resx paris.fr-FR.resx
  • paris.resx 巴黎resx

I dont want to use the CultureInfo but instead specify my own resx identifier. 我不想使用CultureInfo,而是指定自己的resx标识符。 Is there a way to do this using resx file? 有没有办法使用resx文件来做到这一点?

etc 等等

Brussels and Paris Resources 布鲁塞尔和巴黎资源

  • MyResourceManager.brussels-en-GB.resx MyResourceManager.brussels-en-GB.resx
  • MyResourceManager.brussels-ja-JP.resx MyResourceManager.brussels-ja-JP.resx
  • MyResourceManager.brussels-fr-FR.resx MyResourceManager.brussels-fr-FR.resx
  • MyResourceManager.paris-en-GB.resx MyResourceManager.paris-en-GB.resx
  • MyResourceManager.paris-ja-JP.resx MyResourceManager.paris-ja-JP.resx
  • MyResourceManager.paris-fr-FR.resx MyResourceManager.paris-fr-FR.resx
  • MyResourceManager.resx MyResourceManager.resx

EDIT: An example of how I would like to use it (or something similar) 编辑:我想如何使用它(或类似的东西)的示例

MyResourceManager.Header MyResourceManager.Header

instead of 代替

brussels.Header 布鲁塞尔

paris.Header 巴黎标头

An example of a similar problem but solved through Custom Cultures can be found here. 在此处可以找到类似问题的示例,但可以通过“习惯文化”解决。 How to load different RESX files based on some parameter I dont want to do this however as installing cultures on different machines is not an option. 如何基于某些参数加载不同的RESX文件我不想这样做,但是由于无法在不同的计算机上安装区域性。

Use CultureInfo to determine the resource set to load, it will be easier since it integrates into the Thread.CurrentUICulture . 使用CultureInfo确定要加载的资源集,因为它已集成到Thread.CurrentUICulture中 ,所以将更加容易。

If you have cultures that are not standard out of the box supported cultures, use CultureAndRegionInfoBuilder to build any additional cultures that you need. 如果您所支持的文化不是开箱即用的标准文化,请使用CultureAndRegionInfoBuilder来构建所需的任何其他文化。 See http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.aspx . 请参阅http://msdn.microsoft.com/zh-cn/library/system.globalization.cultureandregioninfobuilder.aspx There should be ample StackOverflow examples of using this API, ie Create custom culture in ASP.NET . 应该有很多使用此API的StackOverflow示例,即在ASP.NET中创建自定义区域性

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM