Using ResourceBundles (without having to restart container)
Marc.johnen (Talk | contribs) |
Marc.johnen (Talk | contribs) |
||
Line 28: | Line 28: | ||
<nowiki><%</nowiki> | <nowiki><%</nowiki> | ||
− | <nowiki>org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache();</nowiki> | + | <nowiki>org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache(); // this is probably just good for testing</nowiki> |
<nowiki>java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new</nowiki> | <nowiki>java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new</nowiki> |
Revision as of 20:58, 2 March 2007
taken from the newsgroup:
It's a pain to work with i18n'ed jsp pages, and restart the container every time I want to see if the keys are working ok.
Actually there is a feature in OpenCms 6.2 for this:
All OpenCms module based message bundles are flushed if you clear the cache, which can be triggered by "Administration View > Workplace Tools > Re-Initialize the Workplace".
You can also use this caching behaviour in your Java code like this:
org.opencms.i18n.CmsResourceBundleLoader.getBundle(baseName, locale);
which is the same as
java.util.resourceBundle.getBundle(baseName, locale);
only that we do have the flushable bundle cache.
Example:
<%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %>
<%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %>
<%
org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache(); // this is probably just good for testing
java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new
java.util.Locale("es"));
%>
<%= messages.getString("test.label1") %>