How to Externalize i18N folder

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Externalize i18N folder

markatharvest
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: How to Externalize i18N folder

markatharvest
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: How to Externalize i18N folder

candrews
I think there's a better way that doesn't involve symlinks or exploding the war. Here's how I'm doing it:

In Config.groovy:
---
external.i18n.dir='file:/etc/i18n'
---

In BootStrap.groovy:
---
class BootStrap {
ReloadableResourceBundleMessageSource messageSource
DirectoryWatcher i18nDirectoryWatcher

def init = { servletContext ->
        watchi18n();
}

        @TypeChecked
        /*
         * Watch the i18n directory for changes. The requirement is that changes to the i18n (message bundle) files should be reflected on the live site without requiring a restart.
         */
        void watchi18n(){
                messageSource.basename = Holders.flatConfig.get('external.i18n.dir')
                i18nDirectoryWatcher = new DirectoryWatcher()
                DirectoryWatcher.FileChangeListener fileChangeListener = new DirectoryWatcher.FileChangeListener() {
                        void onChange(File file) {
                                messageSource.clearCacheIncludingAncestors()
                        }
                       
                        void onNew(File file) {
                                messageSource.clearCacheIncludingAncestors()
                        }
                }
                i18nDirectoryWatcher.addListener(fileChangeListener)
                i18nDirectoryWatcher.addWatchDirectory((new DefaultResourceLoader()).getResource("${Holders.flatConfig.get('external.i18n.dir')}").getFile(), '*')
                i18nDirectoryWatcher.start()
        }

    def destroy = {
                i18nDirectoryWatcher.setActive(false)
    }
---