Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_IMPLEMENTATION_ERROR
Error code when default implementation cannot be instantiated.
|
static int |
FORM_INDEX_OUT_OF_BOUNDS_ERROR
Error code when the plural form index resulting from a plural expression is negative or larger than the number of
available forms for the locale.
|
static int |
MISSING_BINARY
Error code when binary is missing.
|
static String |
NLS_DEFAULT_IMPLEMENTATION
Property which allows to define a fallback NLS implementation.
|
static String |
NLS_DEFAULT_LOCALE
Property which allows to fix the default locale at compiletime.
|
static int |
REQUIRED_IMPLEMENTATION_ERROR
Error code when required implementation cannot be instantiated.
|
static int |
WRONG_CRC
Error code when binary is incompatible: wrong CRC.
|
static int |
WRONG_FORMAT_VERSION
Error code when binary is incompatible: wrong format version.
|
static int |
WRONG_HEADER
Error code when binary is incompatible: wrong header.
|
static int |
WRONG_LOCALE_INDEX
Error code when the provided locale index does not correspond to an available one.
|
Constructor and Description |
---|
BinaryNLS(Class<? extends Object> nlsInterface,
int keysCRC32)
Decodes a binary NLS file for the given interface.
|
BinaryNLS(String nlsInterfaceName,
int keysCRC32)
Decodes a binary NLS file for the given interface.
|
BinaryNLS(String nlsInterfaceName,
int keysCRC32,
NLSPlural pluralInfo)
Decodes a binary NLS file for the given interface.
|
Modifier and Type | Method and Description |
---|---|
String[] |
getAvailableLocales()
Gets the list of available locales.
|
String |
getCurrentLocale()
Gets the current locale.
|
String |
getDisplayName(String locale)
Gets the human-readable name of the given locale.
|
static String |
getErrorMessage(int errorCode)
Builds a Severe-level error message.
|
String |
getMessage(int messageID)
Gets the message matching an ID in the current language.
|
String |
getMessage(int messageID,
int count)
Gets the message or one of its plural forms matching an ID and a count value in the current language.
|
String |
getMessage(int messageID,
int count,
String locale)
Gets the message or one of its plural forms matching an ID and a count value in a specific language.
|
String |
getMessage(int messageID,
String locale)
Gets the message matching an ID in a specific language.
|
static NLS |
newBinaryNLS(String nlsInterfaceName,
int keysCRC32)
Decodes a binary NLS file for the given interface.
|
static NLS |
newBinaryNLS(String nlsInterfaceName,
int keysCRC32,
NLSPlural pluralInfo)
Decodes a binary NLS file for the given interface.
|
void |
setCurrentLocale(String locale)
Changes the current locale.
|
public static final int DEFAULT_IMPLEMENTATION_ERROR
public static final int FORM_INDEX_OUT_OF_BOUNDS_ERROR
public static final int MISSING_BINARY
public static final String NLS_DEFAULT_IMPLEMENTATION
newBinaryNLS(String, int)
,
Constant Field Valuespublic static final String NLS_DEFAULT_LOCALE
public static final int REQUIRED_IMPLEMENTATION_ERROR
public static final int WRONG_CRC
public static final int WRONG_FORMAT_VERSION
public static final int WRONG_HEADER
public static final int WRONG_LOCALE_INDEX
public BinaryNLS(Class<? extends Object> nlsInterface, int keysCRC32) throws IOException
nlsInterface
- the NLS interface which lists the messages ID.keysCRC32
- the CRC32 of all messages keys. This allows to verify the coherence between the encoded messages and
the given interface. This CRC32 is a field of the given interface.IOException
- if the expected binary file is not available in application classpath or if the binary file content
is not recognized (probably because not encoded by the Binary NLS addon processor).IllegalArgumentException
- if the default locale defined by the property NLS_DEFAULT_LOCALE
is not available in the
binary file.public BinaryNLS(String nlsInterfaceName, int keysCRC32) throws IOException
No NLSPlural plural form processing class will be provided, all messages will be considered as singular form only.
nlsInterfaceName
- the name of the NLS interface which lists the messages ID.keysCRC32
- the CRC32 of all messages keys. This allows to verify the coherence between the encoded messages and
the given interface. This CRC32 is a field of the given interface.IOException
- if the expected binary file is not available in application classpath or if the binary file content
is not recognized (probably because not encoded by the Binary NLS addon processor).IllegalArgumentException
- if the default locale defined by the property NLS_DEFAULT_LOCALE
is not available in the
binary file.public BinaryNLS(String nlsInterfaceName, int keysCRC32, @Nullable NLSPlural pluralInfo) throws IOException
nlsInterfaceName
- the name of the NLS interface which lists the messages ID.keysCRC32
- the CRC32 of all messages keys. This allows to verify the coherence between the encoded messages and
the given interface. This CRC32 is a field of the given interface.pluralInfo
- an instance of NLSPlural containing the necessary information for plural messages management, can be
null if there are no plural messages in an interface.IOException
- if the expected binary file is not available in application classpath or if the binary file content
is not recognized (probably because not encoded by the Binary NLS addon processor).IllegalArgumentException
- if the default locale defined by the property NLS_DEFAULT_LOCALE
is not available in the
binary file.public String[] getAvailableLocales()
NLS
getAvailableLocales
in interface NLS
public String getCurrentLocale()
NLS
getCurrentLocale
in interface NLS
public String getDisplayName(String locale)
NLS
getDisplayName
in interface NLS
locale
- the locale.public static String getErrorMessage(int errorCode)
errorCode
- The error code.public String getMessage(int messageID)
NLS
getMessage
in interface NLS
messageID
- the ID of the message to retrieve.public String getMessage(int messageID, int count)
NLS
The count argument is intended to be positive, negative values will however still be accepted and plugged into the plural expressions defined in the translations files.
getMessage
in interface NLS
messageID
- the ID of the message to retrieve.count
- the count value.public String getMessage(int messageID, int count, String locale)
NLS
The count argument is intended to be positive, negative values will however still be accepted and plugged into the plural expressions defined in the translations files.
getMessage
in interface NLS
messageID
- the ID of the message to retrieve.count
- the count value.locale
- the locale to use.public String getMessage(int messageID, String locale)
NLS
getMessage
in interface NLS
messageID
- the ID of the message to retrieve.locale
- the locale to use.@Nullable public static NLS newBinaryNLS(String nlsInterfaceName, int keysCRC32)
If an error occurs while creating the NLS, a default NLS implementation instance is returned if the property
NLS_DEFAULT_IMPLEMENTATION
is defined, otherwise, null
is returned.
nlsInterfaceName
- the name of the NLS interface which lists the messages ID.keysCRC32
- the CRC32 of all messages keys.IllegalArgumentException
- if the default implementation cannot be instantiated.BinaryNLS(String, int)
@Nullable public static NLS newBinaryNLS(String nlsInterfaceName, int keysCRC32, NLSPlural pluralInfo)
If an error occurs while creating the NLS, a default NLS implementation instance is returned if the property
NLS_DEFAULT_IMPLEMENTATION
is defined, otherwise, null
is returned.
nlsInterfaceName
- the name of the NLS interface which lists the messages ID.keysCRC32
- the CRC32 of all messages keys.pluralInfo
- an instance of NLSPlural containing the necessary information for plural messages management, can be
null if there are no plural messages in an interface.IllegalArgumentException
- if the default implementation cannot be instantiated.BinaryNLS(String, int)
public void setCurrentLocale(String locale)
NLS
setCurrentLocale
in interface NLS
locale
- the locale to set.