public class Localizer extends Object implements Externalizable
| Constructor and Description |
|---|
Localizer()
Default constructor.
|
Localizer(boolean fallbackDefaultLocale,
boolean fallbackDefaultForm)
Full constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addAvailableLocale(String locale)
Create a new locale (with no mappings).
|
static String |
clearArguments(String text) |
boolean |
destroyLocale(String locale)
Undefine a locale and remove all its data.
|
boolean |
equals(Object o) |
static List<String> |
getArgs(String text) |
String[] |
getAvailableLocales()
Get a list of defined locales.
|
String |
getDefaultLocale()
Get the default locale.
|
boolean |
getFallbackForm()
Get default form fallback mode
|
boolean |
getFallbackLocale()
Get default locale fallback mode
|
String |
getLocale()
Get the current locale.
|
OrderedMap<String,String> |
getLocaleData(String locale)
Get the set of mappings for a locale.
|
OrderedMap<String,String> |
getLocaleMap(String locale)
Get the mappings for a locale, but throw an exception if locale is not defined.
|
String |
getLocalizedText(String textID)
Retrieve localized text for a text handle in the current locale.
|
String |
getNextLocale()
Return the next locale in order, for cycling through locales.
|
String |
getRawText(String locale,
String textID)
Get text for locale and exact text ID only, not using any fallbacks.
|
String |
getText(String textID)
Retrieve the localized text for a text handle in the current locale.
|
String |
getText(String textID,
HashMap<String,String> args)
Retrieve the localized text for a text handle in the current locale.
|
String |
getText(String textID,
String locale)
Retrieve the localized text for a text handle in the given locale.
|
String |
getText(String textID,
String[] args)
Retrieve the localized text for a text handle in the current locale.
|
boolean |
hasLocale(String locale)
Get whether a locale is defined.
|
boolean |
hasMapping(String locale,
String textID)
Determine whether a locale has a mapping for a given text handle.
|
static String |
processArguments(String text,
HashMap<String,String> args) |
static String |
processArguments(String text,
String[] args) |
static String |
processArguments(String text,
String[] args,
int currentArg) |
void |
readExternal(DataInputStream dis,
PrototypeFactory pf)
Reads the object from a stream.
|
void |
registerLocaleResource(String locale,
LocaleDataSource resource)
Registers a resource file as a source of locale data for the specified
locale.
|
void |
registerLocalizable(Localizable l)
Register a Localizable to receive updates when the locale is changed.
|
void |
setDefaultLocale(String defaultLocale)
Set the default locale.
|
void |
setLocale(String currentLocale)
Set the current locale.
|
void |
setToDefault()
Set the current locale to the default locale.
|
void |
unregisterAll()
Unregister all ILocalizables.
|
void |
unregisterLocalizable(Localizable l)
Unregister an Localizable from receiving locale change updates.
|
void |
writeExternal(DataOutputStream dos)
Writes the object to a stream.
|
public Localizer()
public Localizer(boolean fallbackDefaultLocale,
boolean fallbackDefaultForm)
fallbackDefaultLocale - If true, search the default locale when no translation for a particular text handle
is found in the current locale.fallbackDefaultForm - If true, search the default text form when no translation is available for the
specified text form ('long', 'short', etc.). Note: form is specified by appending
';[form]' onto the text ID.public boolean getFallbackLocale()
public boolean getFallbackForm()
public boolean addAvailableLocale(String locale)
locale - Locale to add. Must not be null.NullPointerException - if locale is nullpublic String[] getAvailableLocales()
public boolean hasLocale(String locale)
locale - Localepublic String getNextLocale()
public String getLocale()
public void setLocale(String currentLocale)
currentLocale - Locale. Must be defined and not null.UnregisteredLocaleException - If locale is null or not defined.public String getDefaultLocale()
public void setDefaultLocale(String defaultLocale)
defaultLocale - Default locale. Must be defined. May be null, in which case there will be no default locale.UnregisteredLocaleException - If locale is not defined.public void setToDefault()
IllegalStateException - If default locale is not set.public void registerLocaleResource(String locale, LocaleDataSource resource)
locale - The locale of the definitions provided.resource - A LocaleDataSource containing string data for the locale providedNullPointerException - if resource or locale are nullpublic OrderedMap<String,String> getLocaleData(String locale)
locale - Localepublic OrderedMap<String,String> getLocaleMap(String locale)
locale - LocaleUnregisteredLocaleException - If locale is not defined or null.public boolean hasMapping(String locale, String textID)
locale - Locale. Must be defined and not null.textID - Text handle.UnregisteredLocaleException - If locale is not defined.public boolean destroyLocale(String locale)
locale - Locale to remove. Must not be null. Need not be defined. Must not be the current locale.IllegalArgumentException - If locale is the current locale.NullPointerException - if locale is nullpublic String getText(String textID)
textID - Text handle (text ID appended with optional text form). Must not be null.UnregisteredLocaleException - If current locale is not set.NullPointerException - if textID is nullpublic String getText(String textID, String[] args)
textID - Text handle (text ID appended with optional text form). Must not be null.args - arguments for string variables.UnregisteredLocaleException - If current locale is not set.NullPointerException - if textID is nullNoLocalizedTextException - If there is no text for the specified idpublic String getText(String textID, HashMap<String,String> args)
textID - Text handle (text ID appended with optional text form). Must not be null.args - arguments for string variables.UnregisteredLocaleException - If current locale is not set.NullPointerException - if textID is nullNoLocalizedTextException - If there is no text for the specified idpublic String getLocalizedText(String textID)
textID - Text handle (text ID appended with optional text form). Must not be null.NoLocalizedTextException - If there is no text for the specified idUnregisteredLocaleException - If current locale is not setNullPointerException - if textID is nullpublic String getText(String textID, String locale)
The search order is thus: 1) Specified locale, specified text form 2) Specified locale, default text form 3) Default locale, specified text form 4) Default locale, default text form
(1) and (3) are only searched if a text form ('long', 'short', etc.) is specified. If a text form is specified, (2) and (4) are only searched if default-form-fallback mode is enabled. (3) and (4) are only searched if default-locale-fallback mode is enabled. It is not an error in this situation if no default locale is set; (3) and (4) will simply not be searched.
textID - Text handle (text ID appended with optional text form). Must not be null.locale - Locale. Must be defined and not null.UnregisteredLocaleException - If the locale is not defined or null.NullPointerException - if textID is nullpublic String getRawText(String locale, String textID)
NOTE: This call will only return the full compliment of available strings if and only if the requested locale is current. Otherwise it will only retrieve strings declared at runtime.
locale - Locale. Must be defined and not null.textID - Text handle (text ID appended with optional text form). Must not be null.UnregisteredLocaleException - If the locale is not defined or null.NullPointerException - if textID is nullpublic void registerLocalizable(Localizable l)
l - Localizable to register.public void unregisterLocalizable(Localizable l)
l - Localizable to unregister.public void unregisterAll()
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException
readExternal in interface ExternalizableIOExceptionDeserializationExceptionpublic void writeExternal(DataOutputStream dos) throws IOException
writeExternal in interface ExternalizableIOExceptionCopyright © 2021. All rights reserved.