- java.lang.Object
-
- util.i18n.Localizer
-
- Direct Known Subclasses:
PooledLocalizer
public class Localizer extends java.lang.Object
Does the localization of texts.Each class that uses String that reach the user interface has its own Localizer. You can get a localized String by using one of the msg methods.
The msg methods have all the same pattern:
String msg(key, defaultValue, [args]);
- The
key
is a String that identifies the message. Each class has its own namespace. - The defaultValue is the value you would expect on an English system. (But note: Even on an English system you may get a different String!)
- The optional
args
are arguments that will be parsed into the message. SeeMessageFormat
for details.
- Author:
- Til Schneider, www.murfman.de
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
I18N_ADD
static java.lang.String
I18N_BACK
static java.lang.String
I18N_CANCEL
static java.lang.String
I18N_CHANNEL
static java.lang.String
I18N_CHANNELS
static java.lang.String
I18N_CLEAR_SELECTION
static java.lang.String
I18N_CLOSE
static java.lang.String
I18N_COPY
static java.lang.String
I18N_DEFAULT
static java.lang.String
I18N_DELETE
static java.lang.String
I18N_DOWN
static java.lang.String
I18N_EDIT
static java.lang.String
I18N_ERROR
static java.lang.String
I18N_FILE
static java.lang.String
I18N_HELP
static java.lang.String
I18N_INFO
static java.lang.String
I18N_LEFT
static java.lang.String
I18N_NEXT
static java.lang.String
I18N_OK
static java.lang.String
I18N_OPTIONS
static java.lang.String
I18N_PICTURES
static java.lang.String
I18N_PROGRAM
static java.lang.String
I18N_PROGRAMS
static java.lang.String
I18N_RIGHT
static java.lang.String
I18N_SELECT
static java.lang.String
I18N_SELECT_ALL
static java.lang.String
I18N_SETTINGS
static java.lang.String
I18N_STANDARD
static java.lang.String
I18N_TODAY
static java.lang.String
I18N_TOMORROW
static java.lang.String
I18N_UP
static java.lang.String
I18N_WARNING
static java.lang.String
I18N_YESTERDAY
-
Constructor Summary
Constructors Modifier Constructor Description protected
Localizer(java.lang.Class<?> clazz)
Creates a new instance of Localizer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
addLocalizerToCache(java.lang.Class<?> clazz, Localizer localizer)
java.lang.String
ellipsis(java.lang.String someString)
return the given String with an ellipsis appendedjava.lang.String
ellipsisMsg(java.lang.String key, java.lang.String defaultMessage)
get a localized message with an ellipsis as suffixjava.lang.String
ellipsisMsg(java.lang.String key, java.lang.String defaultMsg, java.lang.Object arg1)
Gets a localized message ending with ellipsis suffixstatic void
emptyLocalizerCache()
Clears the localizer cache.java.util.Locale[]
getAllAvailableLocales()
Scans all Language-Directories for different Versions of tvbrowser/tvbrowser.properties.protected static Localizer
getCachedLocalizerFor(java.lang.Class<?> clazz)
static java.lang.String
getEllipsisLocalization(java.lang.String key)
get a standard localization with ellipsis as suffixstatic java.util.Locale
getLocaleForString(java.lang.String string)
Get the Locale for a specific String.static java.lang.String
getLocalization(java.lang.String key)
get a standard localizationstatic Localizer
getLocalizerFor(java.lang.Class<?> clazz)
Gets the Localizer for the specified Class.boolean
hasMessage(java.lang.String key)
check if a given message key existsprotected void
initializeForClass(java.lang.Class<?> clazz)
java.lang.String
msg(java.lang.String key, java.lang.String defaultMsg)
Gets a localized message.java.lang.String
msg(java.lang.String key, java.lang.String defaultMsg, boolean warn)
Gets a localized message.java.lang.String
msg(java.lang.String key, java.lang.String defaultMsg, java.lang.Object... args)
Gets a localized message.
-
-
-
Field Detail
-
I18N_OK
public static final java.lang.String I18N_OK
- See Also:
- Constant Field Values
-
I18N_CANCEL
public static final java.lang.String I18N_CANCEL
- See Also:
- Constant Field Values
-
I18N_CLOSE
public static final java.lang.String I18N_CLOSE
- See Also:
- Constant Field Values
-
I18N_COPY
public static final java.lang.String I18N_COPY
- See Also:
- Constant Field Values
-
I18N_DELETE
public static final java.lang.String I18N_DELETE
- See Also:
- Constant Field Values
-
I18N_EDIT
public static final java.lang.String I18N_EDIT
- See Also:
- Constant Field Values
-
I18N_PROGRAM
public static final java.lang.String I18N_PROGRAM
- See Also:
- Constant Field Values
-
I18N_PROGRAMS
public static final java.lang.String I18N_PROGRAMS
- See Also:
- Constant Field Values
-
I18N_CHANNEL
public static final java.lang.String I18N_CHANNEL
- See Also:
- Constant Field Values
-
I18N_CHANNELS
public static final java.lang.String I18N_CHANNELS
- See Also:
- Constant Field Values
-
I18N_HELP
public static final java.lang.String I18N_HELP
- See Also:
- Constant Field Values
-
I18N_FILE
public static final java.lang.String I18N_FILE
- See Also:
- Constant Field Values
-
I18N_ADD
public static final java.lang.String I18N_ADD
- See Also:
- Constant Field Values
-
I18N_SETTINGS
public static final java.lang.String I18N_SETTINGS
- See Also:
- Constant Field Values
-
I18N_UP
public static final java.lang.String I18N_UP
- See Also:
- Constant Field Values
-
I18N_DOWN
public static final java.lang.String I18N_DOWN
- See Also:
- Constant Field Values
-
I18N_LEFT
public static final java.lang.String I18N_LEFT
- See Also:
- Constant Field Values
-
I18N_RIGHT
public static final java.lang.String I18N_RIGHT
- See Also:
- Constant Field Values
-
I18N_BACK
public static final java.lang.String I18N_BACK
- See Also:
- Constant Field Values
-
I18N_NEXT
public static final java.lang.String I18N_NEXT
- See Also:
- Constant Field Values
-
I18N_PICTURES
public static final java.lang.String I18N_PICTURES
- See Also:
- Constant Field Values
-
I18N_OPTIONS
public static final java.lang.String I18N_OPTIONS
- See Also:
- Constant Field Values
-
I18N_SELECT
public static final java.lang.String I18N_SELECT
- See Also:
- Constant Field Values
-
I18N_SELECT_ALL
public static final java.lang.String I18N_SELECT_ALL
- See Also:
- Constant Field Values
-
I18N_CLEAR_SELECTION
public static final java.lang.String I18N_CLEAR_SELECTION
- See Also:
- Constant Field Values
-
I18N_ERROR
public static final java.lang.String I18N_ERROR
- See Also:
- Constant Field Values
-
I18N_DEFAULT
public static final java.lang.String I18N_DEFAULT
- See Also:
- Constant Field Values
-
I18N_STANDARD
public static final java.lang.String I18N_STANDARD
- See Also:
- Constant Field Values
-
I18N_YESTERDAY
public static final java.lang.String I18N_YESTERDAY
- See Also:
- Constant Field Values
-
I18N_TODAY
public static final java.lang.String I18N_TODAY
- See Also:
- Constant Field Values
-
I18N_TOMORROW
public static final java.lang.String I18N_TOMORROW
- See Also:
- Constant Field Values
-
I18N_INFO
public static final java.lang.String I18N_INFO
- See Also:
- Constant Field Values
-
I18N_WARNING
public static final java.lang.String I18N_WARNING
- See Also:
- Constant Field Values
-
-
Method Detail
-
initializeForClass
protected void initializeForClass(java.lang.Class<?> clazz)
-
getCachedLocalizerFor
protected static Localizer getCachedLocalizerFor(java.lang.Class<?> clazz)
-
getLocalizerFor
public static Localizer getLocalizerFor(java.lang.Class<?> clazz)
Gets the Localizer for the specified Class.- Parameters:
clazz
- The Class to get the localizer for.- Returns:
- the Localizer for the specified Class.
-
addLocalizerToCache
protected static void addLocalizerToCache(java.lang.Class<?> clazz, Localizer localizer)
-
emptyLocalizerCache
public static void emptyLocalizerCache()
Clears the localizer cache.
-
msg
public java.lang.String msg(java.lang.String key, java.lang.String defaultMsg, java.lang.Object... args)
Gets a localized message.- Parameters:
key
- The key of the message.defaultMsg
- The default message. (English)args
- The arguments that should replace the appropriate place holder. SeeMessageFormat
for details.- Returns:
- a localized message.
-
msg
public java.lang.String msg(java.lang.String key, java.lang.String defaultMsg)
Gets a localized message.- Parameters:
key
- The key of the message.defaultMsg
- The default message (English)- Returns:
- a localized message.
-
msg
public java.lang.String msg(java.lang.String key, java.lang.String defaultMsg, boolean warn)
Gets a localized message.- Parameters:
key
- The key of the message.defaultMsg
- The default message (English)warn
- If warnings should be logged if key is not found.- Returns:
- a localized message.
- Since:
- 2.5.1
-
getAllAvailableLocales
public java.util.Locale[] getAllAvailableLocales()
Scans all Language-Directories for different Versions of tvbrowser/tvbrowser.properties. This is faster than analyzing all Files- Returns:
- all available Locales
- Since:
- 2.3
-
getLocaleForString
public static java.util.Locale getLocaleForString(java.lang.String string)
Get the Locale for a specific String. The String is in this format: "lang_country_variant"- Parameters:
string
- String with Locale- Returns:
- Locale
-
getLocalization
public static java.lang.String getLocalization(java.lang.String key)
get a standard localization- Parameters:
key
- one of the constant values defined in the Localizer class- Returns:
- localized message for key
-
getEllipsisLocalization
public static java.lang.String getEllipsisLocalization(java.lang.String key)
get a standard localization with ellipsis as suffix- Parameters:
key
- one of the constant values defined in the Localizer class- Returns:
- localized message for key
-
ellipsisMsg
public java.lang.String ellipsisMsg(java.lang.String key, java.lang.String defaultMessage)
get a localized message with an ellipsis as suffix- Parameters:
key
- localization keydefaultMessage
- default (English) message- Returns:
- localized message
- Since:
- 3.0
-
ellipsisMsg
public java.lang.String ellipsisMsg(java.lang.String key, java.lang.String defaultMsg, java.lang.Object arg1)
Gets a localized message ending with ellipsis suffix- Parameters:
key
- The key of the message.defaultMsg
- The default message (English)arg1
- The argument that should replace{0}
.- Returns:
- a localized message.
-
hasMessage
public boolean hasMessage(java.lang.String key)
check if a given message key exists- Parameters:
key
- The key- Returns:
- true if the given key exists
- Since:
- 3.0
-
ellipsis
public java.lang.String ellipsis(java.lang.String someString)
return the given String with an ellipsis appended- Parameters:
someString
- The string.- Returns:
- ellipsis appended String or
null
- Since:
- 3.0
-
-