[英]read only some properties using ResourceBundle
I have a big file with messages specified in locale. 我有一个很大的文件,其中包含在区域设置中指定的消息。 For example: 例如:
book.registration.error.service = ..
book.registration.error.empty.book = ..
book.registration.error.file.format.book = ..
publisher.register.firstpublisher = ..
publisher.register.publisherNameUa = ..
publisher.register.nameRu = ..
publisher.register.NameEn = ..
There is a lot of messages. 有很多消息。 To read them I use 要阅读它们,我使用
java.util.ResourceBundle.getBundle(messagesLocation, locale)
but with whis i will read ALL messages. 但是我会读所有消息。 Is there any way to read only a piace of messages. 有什么办法只能读取大量消息。 For example read only messages which start with 'book'? 例如,仅读取以“ book”开头的消息?
The best way to accomplish what you want is to break up your very large resource bundle into multiple bundles - and put all the "book" ones into a specific bundle. 实现所需目标的最佳方法是将非常大的资源捆绑包分成多个捆绑包,然后将所有“书本”捆绑到一个特定的捆绑包中。
You could parse the file yourself, but you'd still have to essentially read through the entire file (unless it's sorted), but that seems to defeat the purpose of what you're trying to achieve. 您可以自己解析文件,但实际上您仍然必须通读整个文件(除非已排序),但这似乎违反了您要实现的目的。
Typically you'd only go down this road if you're having memory or performance problems with a single bundle - if it's memory problems, breaking up bundles might help; 通常,只有在单个捆绑软件遇到内存或性能问题时,才需要走这条路–如果是内存问题,拆开捆绑软件可能会有所帮助; if it's performance problems, initializing your bundle on a background thread may help. 如果是性能问题,则在后台线程上初始化包可能会有所帮助。
And in case it's not obvious - you should always cache the bundle! 如果情况不太明显-您应该始终缓存该捆绑包! Re-creating your bundle every time is a waste - if you want to support dynamically changing resources, just invalidate the cache when resources actually change. 每次都重新创建捆绑包是一种浪费-如果您想支持动态更改资源,只需在实际更改资源时使缓存无效即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.