.NET相当于在Java资源包的选择? [英] .NET equivalent of choices in Java resource bundles?
问题描述
在Java资源包我可能有以下的资源包定义:
In Java resource bundles I may have the following Resource Bundle definitions:
EN_GB - 英国英语
en_GB - British English
jobs.search.resultstr = There {1,choice,0#are no jobs|1#is one job|1<are {1,number,integer} jobs} for your search
ceb_PH - 宿务
ceb_PH - Cebuano
jobs.search.resultstr = Adunay {1,choice,0#mga walay mga|1#mao ang 1 nga|1<{1,number,integer}} trabaho alang sa {1,choice,0#inyong mga|1#imong|1<inyong mga} search
的code口将使用以提取资源将根据所输入的数据作出选择,并正确地格式化从而在三个不同的输出中的一个字符串
The code I would use to extract the resource would make choices based on the input data and format the string correctly resulting in one of three different outputs.
伪code:
myResultStr = resourceBundle.getResource("jobs.search.resultStr", jobs.recordCount)
这将导致以下字符串被输出取决于所选择的语言环境和返回结果的数目中的一个。
This would result in one of the following strings being output dependent on chosen locale and number of results returned.
EN_GB
- 在没有作业进行搜索
- 在这里为您搜索一个作业
- 有2个职位进行搜索
或
ceb_PH
- Adunay MGA walay MGA trabaho阿郎山inyong MGA搜索
- Adunay毛昂1尔雅trabaho阿郎山imong搜索
- Adunay 2 trabaho阿郎山inyong MGA搜索
我是比较新的.NET开发,我一直在寻找的.NET .resource和的.resx接近本地化和我似乎并没有能够找到任何提示,我如何能实现本地化的灵活性,因为我已经在.NET框架内,如上图所示相同的水平。
I'm relatively new to .NET development and I've been looking at the .NET .resource and .resx approaches to localisation and I don't seem to be able to find any hint as to how I can achieve the same level of localisation flexibility as I've illustrated above within the .NET framework.
任何指导和指针,以我怎么能做到这一点的.NET将是最受欢迎的。
Any guidance and pointers as to how I could achieve this in .NET would be most welcome.
感谢
推荐答案
我解决这确实是使用的CustomFormatter实施ChoiceFormat的是使用自定义的资源包对象代理访问.NET RESX等效的方法文件。通过实施涵盖了所有我需要的语言Pluraliser对象层次结构(多在未来)与ChoiceFormat,我可以准确地定位字符串。
The way I solved this was indeed to use the CustomFormatter to implement an equivalent of ChoiceFormat which is used by a custom ResourceBundle object to proxy access to the .NET resx files. By implementing a Pluraliser object hierarchy covering all the languages I need (and more in the future) along with ChoiceFormat, I can localise strings accurately.
在code看起来有点像这样...
The code looks a bit like this...
String.Format(new ChoiceFormatProvider(Session["CultureInfo"]), rb.GetString("resxkey", Session["CultureInfo"]), new object[] { 5 });
通过的GetString返回的字符串由RESX文件的本地化,但随后被定义格式处理,他们是这样的....
The strings returned by GetString are localised by the resx file but are then processed by the custom formatter and they look like this....
{0:choice,0#zero str|1#one str|1<more than one}
以这进一步,我可以处理的格式像这样的字符串...
Taking this further, I can process strings formatted like so...
{0:plural,zero#zero str|one#singular str|two#dual str|few#few str|many#many str|other#other plural str}
这两个特点再加上一组自定义pluraliser对象允许被实施非常复杂的本地化功能。
These two features coupled with a set of custom pluraliser objects allow for very complex localisation features to be implemented.
这篇关于.NET相当于在Java资源包的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!