|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.client.gui.i18n.Messages
public class Messages
Represents a collection of messages in a particular locale.
The individual messages are read from property files in the
data/strings directory. The property files are called
"FreeColMessages[_LANGUAGE[_COUNTRY[_VARIANT]]].properties", where
LANGUAGE should be an ISO 639-2 or ISO 639-3 language code, COUNTRY
should be an ISO 3166-2 country code, and VARIANT is an arbitrary
string. The encoding of the property files is UTF-8. Since the Java
Properties class is unable to handle UTF-8 directly, this class
uses its own implementation.
The individual messages may include variables, which must be delimited by percent characters (e.g. "%nation%"), and will be replaced when the message is formatted. Furthermore, the messages may include choice formats consisting of a tag followed by a colon (":"), a selector and one or several choices separated from the selector and each other by pipe characters ("|"). The entire choice format must be enclosed in double brackets ("{{" and "}}", respectively).
Each choice must consist of a key and a value separated by an equals character ("="), unless it is a variable, in which case the variable must resolve to another choice format. The selector may also be a variable. If the selector is omitted, then one of the choices should use the key "default". Choice formats may be nested.
key1=%colony% tuottaa tuotetta {{tag:acc|%goods%}}.
key2={{plural:%amount%|one=ruoka|other=ruokaa|default={{tag:|acc=viljaa|default=Vilja}}}}
key3={{tag:|acc=viljaa|default={{plural:%amount%|one=ruoka|other=ruokaa|default=Ruoka}}}}
This class is NOT thread-safe. (CO: I cannot find any place that really has a problem)
| Field Summary | |
|---|---|
private static java.lang.String[] |
DESCRIPTION_KEYS
|
static java.lang.String |
FILE_PREFIX
|
static java.lang.String |
FILE_SUFFIX
|
private static java.util.logging.Logger |
logger
|
private static java.util.Map<java.lang.String,java.lang.String> |
messageBundle
|
static java.lang.String |
STRINGS_DIRECTORY
|
private static java.util.Map<java.lang.String,Selector> |
tagMap
A map with Selector values and the tag keys used in choice formats. |
| Constructor Summary | |
|---|---|
Messages()
|
|
| Method Summary | |
|---|---|
static boolean |
containsKey(java.lang.String key)
Returns true if the message bundle contains the given key. |
private static int |
findMatchingBracket(java.lang.String input,
int start)
Return the index of the matching pair of brackets, or -1 if none is found. |
static int |
getBreakingPoint(java.lang.String string)
Breaks a line between two words. |
private static java.lang.String |
getChoice(java.lang.String input,
java.lang.String key)
Return the choice tagged with the given key, or null, if the given input string does not contain the key. |
static java.lang.String |
getDefaultRegionName(Player player,
Region.RegionType regionType)
Creates a unique region name by fetching a new default name from the list of default names if possible. |
static java.lang.String |
getDescription(FreeColObject object)
|
static java.lang.String |
getDescription(Option object)
|
static java.io.File |
getI18nDirectory()
Returns the directory containing language property files. |
static java.lang.String |
getKey(java.lang.String preferredKey,
java.lang.String defaultKey)
Returns the preferred key if it is contained in the message bundle and the default key otherwise. |
static java.lang.String |
getLabel(AbstractUnit unit)
Returns the name of a unit in a human readable format. |
static StringTemplate |
getLabel(Unit unit)
Returns the name of a unit in a human readable format. |
static java.lang.String |
getLabel(UnitType someType,
Unit.Role someRole,
int count)
Returns the name of a unit in a human readable format. |
static java.lang.String |
getName(FreeColObject object)
|
static java.lang.String |
getName(Option object)
|
static java.lang.String |
getNewLandName(Player player)
|
private static Selector |
getSelector(java.lang.String tag)
Returns the Selector with the given tag. |
static java.util.List<java.lang.String> |
getSettlementNames(Player player)
Gets a list of settlement names and a fallback prefix for a player. |
static java.lang.String |
getShortDescription(FreeColObject object)
|
static java.lang.String |
getShortDescription(Option object)
|
static java.lang.String |
getStanceAsString(Player.Stance stance)
Returns a string describing the given stance. |
static java.lang.String |
getTurnsText(int turns)
Gets a string describing the number of turns left for a colony to finish building something. |
static void |
loadResources(java.io.File resourceFile)
Loads a new resource file into the current message bundle. |
static void |
loadResources(java.io.InputStream is)
Loads a new resource file into the current message bundle. |
static java.lang.String |
message(java.lang.String messageId)
Returns the text mapping for a particular ID in the default locale message bundle. |
static java.lang.String |
message(StringTemplate template)
Localizes a StringTemplate. |
private static java.lang.String |
replaceChoices(java.lang.String input,
StringTemplate template)
Replace all choice formats in the given string, using keys and replacement values from the given template, which may be null. |
static void |
setGrammaticalNumber(Number number)
Set the grammatical number rule. |
static void |
setMessageBundle(java.util.Locale locale)
Set the resource bundle for the given locale |
private static void |
setMessageBundle(java.lang.String language,
java.lang.String country,
java.lang.String variant)
Set the resource bundle to the given locale |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
public static final java.lang.String STRINGS_DIRECTORY
public static final java.lang.String FILE_PREFIX
public static final java.lang.String FILE_SUFFIX
private static final java.lang.String[] DESCRIPTION_KEYS
private static java.util.Map<java.lang.String,java.lang.String> messageBundle
private static java.util.Map<java.lang.String,Selector> tagMap
| Constructor Detail |
|---|
public Messages()
| Method Detail |
|---|
private static Selector getSelector(java.lang.String tag)
tag - a String value
Selector valuepublic static void setGrammaticalNumber(Number number)
number - a Number valuepublic static void setMessageBundle(java.util.Locale locale)
locale -
private static void setMessageBundle(java.lang.String language,
java.lang.String country,
java.lang.String variant)
language - The language for this locale.country - The language for this locale.variant - The variant for this locale.public static java.io.File getI18nDirectory()
File valuepublic static java.lang.String message(java.lang.String messageId)
messageId - The key of the message to find
private static java.lang.String replaceChoices(java.lang.String input,
StringTemplate template)
input - a String valuetemplate - a StringTemplate value
String value
private static java.lang.String getChoice(java.lang.String input,
java.lang.String key)
input - a String valuekey - a String value
String value
private static int findMatchingBracket(java.lang.String input,
int start)
input - a String valuestart - an int value
int valuepublic static java.lang.String message(StringTemplate template)
template - a StringTemplate value
String valuepublic static boolean containsKey(java.lang.String key)
key - a String value
boolean value
public static java.lang.String getKey(java.lang.String preferredKey,
java.lang.String defaultKey)
preferredKey - a String valuedefaultKey - a String value
String valuepublic static java.lang.String getName(FreeColObject object)
public static java.lang.String getDescription(FreeColObject object)
public static java.lang.String getShortDescription(FreeColObject object)
public static java.lang.String getName(Option object)
public static java.lang.String getDescription(Option object)
public static java.lang.String getShortDescription(Option object)
public static StringTemplate getLabel(Unit unit)
unit - an Unit value
public static java.lang.String getLabel(UnitType someType,
Unit.Role someRole,
int count)
someType - an UnitType valuesomeRole - a Role valuecount - an int value
public static java.lang.String getLabel(AbstractUnit unit)
unit - an AbstractUnit value
public static java.lang.String getStanceAsString(Player.Stance stance)
stance - The stance.
public static java.lang.String getTurnsText(int turns)
turns - the number of turns left
public static java.lang.String getNewLandName(Player player)
public static java.lang.String getDefaultRegionName(Player player,
Region.RegionType regionType)
player - PlayerregionType - a RegionType value
String valuepublic static java.util.List<java.lang.String> getSettlementNames(Player player)
player - The Player to get names for.
public static void loadResources(java.io.File resourceFile)
resourceFile - public static void loadResources(java.io.InputStream is)
is - an InputStream valuepublic static int getBreakingPoint(java.lang.String string)
string - The line for which we should determine a
breaking point.
-1 if there
are none.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||