.NET equivalent of choices in Java resource bundles?

只愿长相守 提交于 2019-12-06 02:57:21

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.

The code looks a bit like this...

String.Format(new ChoiceFormatProvider(Session["CultureInfo"]), rb.GetString("resxkey", Session["CultureInfo"]), new object[] { 5 });

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}

These two features coupled with a set of custom pluraliser objects allow for very complex localisation features to be implemented.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!