public class Messages
extends java.lang.Object
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.
Te 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)| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String[] |
DESCRIPTION_KEYS |
static java.lang.String |
DESCRIPTION_SUFFIX |
private static java.util.logging.Logger |
logger |
private static java.util.List<java.lang.String> |
mercenaryLeaders
Mercenary leaders.
|
static java.lang.String |
MESSAGE_FILE_PREFIX |
static java.lang.String |
MESSAGE_FILE_SUFFIX |
private static java.util.Map<java.lang.String,java.lang.String> |
messageBundle
The mapping from language-independent key to localized message
for the established locale.
|
static java.lang.String |
NAME_SUFFIX |
private static java.util.List<java.lang.String> |
otherRivers
Extra river names.
|
static java.lang.String |
RULER_SUFFIX |
static java.lang.String |
SHORT_DESCRIPTION_SUFFIX |
private static java.util.Map<java.lang.String,Selector> |
tagMap
A map with Selector values and the tag keys used in choice
formats.
|
| Constructor and Description |
|---|
Messages() |
| Modifier and Type | Method and Description |
|---|---|
private static void |
collectNames(java.lang.String prefix,
java.util.List<java.lang.String> names)
Collects all the names with a given prefix.
|
static boolean |
containsKey(java.lang.String key)
Does the message bundle contain the given key?
|
static java.lang.String |
descriptionKey(java.lang.String id) |
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 java.lang.String |
getBestDescription(ObjectWithId object) |
static java.lang.String |
getBestDescription(java.lang.String id) |
static java.lang.String[] |
getBestNameAndDescription(java.lang.String id)
Get the name and best description for a given identifier.
|
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(ObjectWithId object) |
static java.lang.String |
getDescription(java.lang.String id) |
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.util.Locale |
getLocale(java.lang.String languageID)
Get the
Locale corresponding to a given language name. |
static int |
getMercenaryLeaderCount()
Get the number of mercenary leaders.
|
static java.lang.String |
getMercenaryLeaderName(int n)
Get the name of the nth mercenary leader.
|
private static java.util.List<java.lang.String> |
getMessageFileNames(java.util.Locale locale)
Get a list of candidate message file names for a given locale.
|
static java.lang.String |
getName(ObjectWithId object) |
static java.lang.String |
getName(java.lang.String id) |
static java.lang.String |
getNewLandName(Player player)
Get the new land name for a player.
|
static java.lang.String |
getRulerName(java.lang.String id) |
private static Selector |
getSelector(java.lang.String tag)
Gets 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.util.List<java.lang.String> |
getShipNames(Player player)
Gets a list of ship names and a fallback prefix for a player.
|
static java.lang.String |
getShortDescription(ObjectWithId object) |
static java.lang.String |
getShortDescription(java.lang.String id) |
static java.lang.String |
getTurnsText(int turns)
Gets a string describing the number of turns left for a colony
to finish building something.
|
static StringTemplate |
getUnitLabel(java.lang.String name,
java.lang.String typeId,
int number,
java.lang.String nationId,
java.lang.String roleId,
java.lang.String equipment)
Get a label for a collection of units given a name, type,
number, nation, role and extra equipment.
|
static void |
loadMessages(java.io.InputStream is)
Loads messages from a resource file into the current message bundle.
|
static java.lang.String |
message(java.lang.String messageId)
Get the text mapping for a particular identifier in the
default locale message bundle.
|
static java.lang.String |
message(StringTemplate template)
Localizes a StringTemplate.
|
static java.lang.String |
nameKey(ObjectWithId object) |
static java.lang.String |
nameKey(java.lang.String id) |
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.
|
private static void |
requireMercenaryLeaders()
Initialize the mercenary leaders collection.
|
static void |
requireOtherRivers()
Initialize the otherRivers collection.
|
static java.lang.String |
rulerKey(java.lang.String id) |
static void |
setGrammaticalNumber(Number number)
Set the grammatical number rule.
|
static void |
setMessageBundle(java.util.Locale locale)
Set the message bundle for the given locale
Error messages have to go to System.err as this routine is called
before logging is enabled.
|
static void |
setModMessageBundle(java.util.Locale locale)
Load localized messages for mods.
|
static java.lang.String |
shortDescriptionKey(java.lang.String id) |
private static final java.util.logging.Logger logger
public static final java.lang.String MESSAGE_FILE_PREFIX
public static final java.lang.String MESSAGE_FILE_SUFFIX
public static final java.lang.String DESCRIPTION_SUFFIX
public static final java.lang.String SHORT_DESCRIPTION_SUFFIX
public static final java.lang.String NAME_SUFFIX
public static final java.lang.String RULER_SUFFIX
private static final java.lang.String[] DESCRIPTION_KEYS
private static final java.util.Map<java.lang.String,java.lang.String> messageBundle
private static java.util.Map<java.lang.String,Selector> tagMap
private static java.util.List<java.lang.String> otherRivers
private static java.util.List<java.lang.String> mercenaryLeaders
private static Selector getSelector(java.lang.String tag)
tag - The tag to check.Selector.public static void setGrammaticalNumber(Number number)
number - a Number valueprivate static java.util.List<java.lang.String> getMessageFileNames(java.util.Locale locale)
locale - The Locale to generate file names for.public static void setMessageBundle(java.util.Locale locale)
locale - The Locale to set resources for.public static void loadMessages(java.io.InputStream is)
throws java.io.IOException
is - The InputStream to read from.java.io.IOExceptionpublic static void setModMessageBundle(java.util.Locale locale)
locale - The Locale to load resources for.public static java.util.Locale getLocale(java.lang.String languageID)
Locale corresponding to a given language name.
Public as this is needed for language option processing and the
initial locale setting.languageID - An underscore separated language/country/variant tuple.Locale for the specified language.public static java.lang.String nameKey(java.lang.String id)
public static java.lang.String nameKey(ObjectWithId object)
public static java.lang.String getName(java.lang.String id)
public static java.lang.String getName(ObjectWithId object)
public static java.lang.String descriptionKey(java.lang.String id)
public static java.lang.String getDescription(java.lang.String id)
public static java.lang.String getDescription(ObjectWithId object)
public static java.lang.String shortDescriptionKey(java.lang.String id)
public static java.lang.String getShortDescription(java.lang.String id)
public static java.lang.String getShortDescription(ObjectWithId object)
public static java.lang.String rulerKey(java.lang.String id)
public static java.lang.String getRulerName(java.lang.String id)
public static boolean containsKey(java.lang.String key)
key - The key String to check.public static java.lang.String getKey(java.lang.String preferredKey,
java.lang.String defaultKey)
preferredKey - a String valuedefaultKey - a String valueString valuepublic static java.lang.String getBestDescription(ObjectWithId object)
public static java.lang.String getBestDescription(java.lang.String id)
public static java.lang.String[] getBestNameAndDescription(java.lang.String id)
id - The identifier to look up.public static StringTemplate getUnitLabel(java.lang.String name, java.lang.String typeId, int number, java.lang.String nationId, java.lang.String roleId, java.lang.String equipment)
name - An optional unit name.typeId - The unit type identifier.number - The number of units.nationId - An optional nation identifier.roleId - The unit role identifier.equipment - An optional equipment annotation.StringTemplate to describe the given unit.public static java.lang.String getTurnsText(int turns)
turns - the number of turns leftpublic static java.lang.String getNewLandName(Player player)
player - The Player to query.public static void requireOtherRivers()
public static java.lang.String getDefaultRegionName(Player player, Region.RegionType regionType)
player - PlayerregionType - a RegionType valueString valueprivate static void requireMercenaryLeaders()
public static int getMercenaryLeaderCount()
public static java.lang.String getMercenaryLeaderName(int n)
n - The index of the leader required.private static void collectNames(java.lang.String prefix,
java.util.List<java.lang.String> names)
prefix - The prefix to check.names - A list to fill with the names found.public static java.util.List<java.lang.String> getSettlementNames(Player player)
player - The Player to get names for.public static java.util.List<java.lang.String> getShipNames(Player player)
player - The Player to get names for.public static int getBreakingPoint(java.lang.String string)
string - The line for which we should determine a
breaking point.-1 if there
are none.public static java.lang.String message(java.lang.String messageId)
messageId - The key of the message to find.public static java.lang.String message(StringTemplate template)
template - a StringTemplate valueString valueprivate static java.lang.String replaceChoices(java.lang.String input,
StringTemplate template)
input - a String valuetemplate - a StringTemplate valueString valueprivate static java.lang.String getChoice(java.lang.String input,
java.lang.String key)
input - a String valuekey - a String valueString valueprivate static int findMatchingBracket(java.lang.String input,
int start)
input - a String valuestart - an int valueint value