Package com.sodius.oslc.server.util
Class ServletNLS
java.lang.Object
com.sodius.oslc.server.util.ServletNLS
Provides facilities to handle internationalization for servlets.
This class requires OSGi to be running.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <M> MessagesProvider<M>createMessagesProvider(Class<M> messagesClass) Returns aMessagesProviderimplementation for the specified class.static ResourceBundlegetResourceBundle(IConfigurationElement element) Returns the resource bundle containing localized messages for the plug-in contributing the specified element, depending on theLocalespreferred locale.static ResourceBundlegetResourceBundle(org.osgi.framework.Bundle plugin) Returns the resource bundle containing localized messages for the specified plug-in, depends on theLocalespreferred locale.
-
Method Details
-
getResourceBundle
Returns the resource bundle containing localized messages for the specified plug-in, depends on theLocalespreferred locale.The plug-in must have a
/OSGI-INF/I10n/folder containing*.propertiesfiles:bundle.properties: contains English messagesbundle_fr.properties: contains French messages
A class can retrieve a bundle localized message using:
String localizedMessage = ServletNLS.getResourceBundle(bundle).getString("my_message_key");The language to use is determined using the
LocalesAPI. ServletNLS iterates on the provided locales, in order of preference, and returns the translations if a properties file is found for the locale. It returns the default translations provided bybundle.propertiesif there's no match.- Parameters:
plugin- a plug-in having a/OSGI-INF/I10n/bundle.propertiesresource.- Returns:
- the resource bundle declared in the specified plug-in,
nullif none.
-
getResourceBundle
Returns the resource bundle containing localized messages for the plug-in contributing the specified element, depending on theLocalespreferred locale.- Parameters:
element- an extension whose contributing plug-in defines translations.- Returns:
- the resource bundle declared in the specified plug-in,
nullif none. - See Also:
-
createMessagesProvider
Returns aMessagesProviderimplementation for the specified class.- Type Parameters:
M- a subclass of NLS providing message keys and translations.- Parameters:
messagesClass- a class extending NLS.- Returns:
- a
MessagesProviderimplementation for the specified class.
-