简体   繁体   English

春季资源包delimer

[英]Spring resource bundle delimer

We are using Spring LocaleChangeInterceptor and ReloadableResourceBundleMessageSource for all our localization needs. 我们使用Spring LocaleChangeInterceptor和ReloadableResourceBundleMessageSource来满足我们所有的本地化需求。 All is well until a strange requirement comes. 一切都很好,直到出现一个奇怪的要求。

What the new requirement needs is that we have to allow each language property file to "float", which means that these resource bundles are no longer required to have all keys to be in sync. 新需求需要的是我们必须允许每个语言属性文件“浮动”,这意味着不再需要这些资源束使所有键都同步。

Missing keys, in this use case, will have to default to use en_US properties. 在这种情况下,缺少键将必须默认使用en_US属性。 We have proposed to write tools to fill the missing keys with English messages, but that got push back hard from above. 我们已经提议编写工具来用英文消息填充丢失的键,但是这从上面很难进行。 They say that it was doable in Struts and Spring should also do the same. 他们说在Struts中可行,Spring也应该这样做。

I have been searching up and down the web but I cannot find such example. 我一直在网上上下搜索,但是找不到这样的例子。 Can this even be done in Spring 3? 甚至可以在春季3做到这一点吗?

Maybe you can extent class ResourceBundle and override its method handleGetObject like this: 也许您可以扩展类ResourceBundle并重写其方法handleGetObject如下所示:

    @Override
    public Object handleGetObject(String key) {
        try {
            return messages.getMessage(key, null, getLocale());
        } catch (NoSuchMessageException e) {
            return messages.getMessage(key, null, new Locale("en_US"));;
        }
    }

I did something very similar to his in my project. 在我的项目中,我做了与他非常相似的事情。 I also had to handle missing keys. 我还必须处理丢失的钥匙。

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

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