简体   繁体   中英

Spring resource bundle delimer

We are using Spring LocaleChangeInterceptor and ReloadableResourceBundleMessageSource for all our localization needs. 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. 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.

I have been searching up and down the web but I cannot find such example. Can this even be done in Spring 3?

Maybe you can extent class ResourceBundle and override its method handleGetObject like this:

    @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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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