开发者

Administrating internationalized wicket applications

Is there a good/right way to maintain/administrate the internationalization of a Wicket application?

At the moment there are several *.properties-files with the translations in it just as you do it in Wicket. Can you access these on runtime and change the values so that the changes take place without restarting the app?

(Another way would be to store the value开发者_C百科s in a database but I just leave that for now.)


You can write your own implementation of IStringResourceLoader and register it with your application as follows:

getApplication().getResourceSettings().addStringResourceLoader(  
                                                     new CustomResourceLoader());

Your resource loader should fetch the resources from some place outside of the WAR file so it can be modified by administrators as suggested by Aaron Digulla.

To get Wicket to pick up modifications at runtime you have to adapt your resource settings like this:

getApplication().getResourceSettings().setResourcePollFrequency( 
                                                           Duration.seconds(1));


I'm aware of any existing solution but here are some ideas we had:

  • Store the translations in a directory outside the application. This way, they won't end up in JAR files so you can change them at runtime.

  • Make sure the resource bundles can be refreshed (for example by using an event bus or a listener that you can invoke when a text changes)

  • Add a "translation mode" to the app. With a little bit of JavaScript and a careful design of the HTML, it should be possible to make every text from a resource bundle "editable" by clicking on it. Use AJAX to send the change event back to the server and update the resource bundle.

    This way, translators can do their work in the live system so they see online what needs to be changed (you can give the texts a CSS class depending on whether they have been or still need to be translated) and what the translation looks like, etc.

[EDIT]

I mean outside the WAR file. Otherwise, you will need to recreate the WAR every time the translation changes.

Alternatively, you can put the property files into WEB-INF/classes (alongside the normal class files) and use a small script to replace the files in the WAR.

In a batch/shell script, use jar -u to replace existing files. In ant, use the old WAR file as source via zipfileset, add your new files first and use duplicate="preserve".

This way, you don't have to compress the whole file again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜