如何合并多个资源包?
我有一个由几个文件组成的资源包,比如说:
address_en_us.properties
address_nl_nl.properties
address_fr_ca.properties
我如何获取和合并两个属性文件,并将 en_us
作为“默认”属性文件?
一些背景:
当我使用其中一个本地化属性(例如,fr_ca
)时,对于 fr_ca
中未本地化的每个键,我想使用 fr_ca
中指定的默认值代码>en_us
I have a resource bundle which consist of a few files, lets say:
address_en_us.properties
address_nl_nl.properties
address_fr_ca.properties
How do I obtain and merge two of the properties file with en_us
being the 'default' property file?
Some background:
When I use one of the localized property, say, fr_ca
, for each keys that are not localized in fr_ca
, I want to use the default value specified in en_us
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将“address_en_us.properties”重命名为“address.properties”,该文件始终用作“默认”属性文件。
Just rename your "address_en_us.properties" to "address.properties" and this file is always used as 'default' property file.
我见过的一种工作方法是在代码中设置默认值,它是在 java 类中硬编码的。这样,任何未在属性文件中设置但在代码中使用的属性将始终获得默认值。
从架构的角度来看,这也是一个非常好的主意,在代码中提供具有默认属性值的产品,并由属性文件中的值覆盖。如果你让产品(在我看来是 Android 应用程序)在启动时调用服务器来检查并覆盖属性文件的值,那么你可以为产品增加很多灵活性。
One way I have seen work is to have the default values set in code, where it is hard-coded in java class. That way any property not set in properties file but used in code will always get the default value.
And from an architecture perspective this is also a really good idea, shipping products with default properties values in code, overridden by the values in properties file. And if you make it so that the product (Android app in my perspective) makes a server call at start-up to check and overwrite the values of properties files then you can add a lot of flexibility to the product.