Package com.sodius.oslc.server.util
Interface MessagesProvider<M>
- Type Parameters:
M- a class providing message keys and translations.
public interface MessagesProvider<M>
Provides server side messages whose language depends on the
Locales preferred locale.
A class providing localized messages looks like:
public class Messages {
public String MyClass_MESSAGE_1;
public String MyClass_MESSAGE_2;
public String MyOtherClass_MESSAGE;
private static final MessagesProvider<Messages> PROVIDER = ServletNLS.createMessagesProvider(Messages.class);
public static Messages getInstance() {
return PROVIDER.getInstance();
}
}
Translated messages must be defined in *.properties files along the implemented Messages class, organized like:
messages.properties: contains English messagesmessages_fr.properties: contains French messages
A class can retrieve a localized message using:
String aLocalizedMessage = Messages.getInstance().MyClass_MESSAGE_1; String aMessageWithArg = NLS.bind(Messages.getInstance().MyOtherClass_MESSAGE, "hello");
The language to use is determined using the Locales API.
MessagesProvider 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 by messages.properties if there's no match.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionProvides translations depending on the preferred locale configured with theLocalesAPI.