|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.moyoman.framework.Message
This class is responsible for the internationalization of messages. The developer should never hard code messages which the user might see, but use symbols which are then looked up by this class. It is also used for saving new symbols, or translations of symbols. All supported languages should have the exact same number of messages. The names of all of them should be the same across languages. The names are used in the Java source and are not seen by the user. Only the values are seen by the user.
This class is not used directly to create a translation, but rather the MessageTool class is used for that purpose, and it uses this class.
To create a new translation, call one of the create() methods using the ISO standard language and country codes. This will create a Message object with the default values for all of the symbols. Using repeated calls to setMessage() will accomplish the translation.
Field Summary | |
private String |
countryName
The name of the country using ISO 3166. |
private static String |
defaultDisplayableName
The displayable message name of the default language, e.g, U.S. |
private static Message |
defaultLanguage
This is the Message object for the default language. |
private static String |
defaultSymbolicName
The symbolic name of the default language, e.g, en_US. |
private static HashMap |
games
The name is a GameId object, and the value is a Message object. |
private boolean |
isDefault
Indicates if this is the Message object for the default language. |
private String |
languageName
The name of the language using ISO 639. |
private static HashMap |
languages
The name is the ISO standard name, and the value is a Message object. |
private String |
languageSymbolicName
The symbolic message name, e.g, en_US. |
private static String |
messageDir
The directory name where the message files are kept. |
private HashMap |
messages
Contains the messages for the language. |
(package private) Message[] |
orderedAlternativeMessages
This array contains the ordered alternate Message objects that can be used instead of this one. |
private static String |
prefix
The string that all message file names start with. |
private static String |
suffix
The string that all message file names end with. |
private static HashMap |
values
The name is the language specific name for a language, and the value is the symbolic name, e.g, en_US. |
Constructor Summary | |
private |
Message(String symbolicName,
boolean def)
Create a Message object for the specified language. |
protected |
Message(String symbolicName,
String displayableName,
boolean def)
Create a Message object for the specified language. |
Method Summary | |
static void |
associate(GameId id)
Associate a game with the default language. |
static void |
associate(GameId id,
String lang)
Associate the game with the specified language. |
static Message |
create(String symbolicName,
String displayableName)
Create a Message object for a language. |
static Message |
create(String symbolicLanguageName,
String symbolicCountryName,
String displayableName)
Create a Message object for a new language. |
private static void |
createMessageObjectFromFile(String fname,
boolean flag)
Create a Message object from the message file. |
private void |
defineOrderedAlternatives()
Set the orderedAlternativeMessages variable. |
boolean |
equals(Object o)
Test this object for equality with another one. |
static String[] |
getAllMessageTypes()
Get all of the symbolic message names. |
static String |
getDefaultLanguageDisplayableName()
Get the displayable name of the default language. |
static String |
getDefaultLanguageSymbolicName()
Get the symbolic name of the default language. |
protected static Message |
getDefaultMessageObject()
Get the Message object for the default language. |
static String[] |
getDisplayableLanguageNames()
Displayable names for all supportable languages, in the local language. |
protected static String |
getExactMessage(String symbolicLanguageName,
String symbolicMessageName)
Get a message in the specified language. |
private String |
getLangMessage(String symbolicMessageName)
Get the specified message. |
static String |
getMessage(GameId id,
String symbolicMessageName)
Get a message in the language associated with the game id. |
static String |
getMessage(String symbolicMessageName)
Get a message in the default language. |
static String |
getMessage(String symbolicLanguageName,
String symbolicMessageName)
Get a message in the specified language. |
protected static Message |
getMessageObject(String symbolicLanguageName)
Get the appropriate Message object. |
static String |
getSymbolicLanguageName(String dispLangName)
Get the symbolic language name for the displayable name. |
static String[] |
getSymbolicLanguageNames()
Symbolic names for all supportable languages, in the local language. |
int |
hashCode()
Get a hash code for this object. |
void |
removeMessage(String symbolicMessageName)
Remove the given symbol. |
protected void |
reset()
Restore the Message object to the values in the messages file. |
void |
save()
Save the results of creating or updating a language. |
void |
setMessage(String symbolicMessageName,
String value)
Set a new message for the given symbol. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static HashMap games
private static HashMap languages
private static Message defaultLanguage
private static String defaultSymbolicName
private static String defaultDisplayableName
private boolean isDefault
private static HashMap values
private HashMap messages
private String languageSymbolicName
private String languageName
private String countryName
private static String messageDir
private static final String prefix
private static final String suffix
Message[] orderedAlternativeMessages
Constructor Detail |
protected Message(String symbolicName, String displayableName, boolean def)
symbolicName
- This is either an ISO 639 language name,
or a string of the form: ISO 639 language name,
_ ISO 3166 country name, e.g, es, en_GB.displayableName
- - The language name in displayable format.
This string can contain any unicode characters.def
- If true, then this is the default language.private Message(String symbolicName, boolean def)
symbolicName
- This is either an ISO 639 language name,
or a string of the form: ISO 639 language name,
_ ISO 3166 country name, e.g, es, en_GB.def
- If true, then this is the default language.Method Detail |
private static void createMessageObjectFromFile(String fname, boolean flag) throws InternalErrorException
flag
- Indicates if this is the default object.
InternalErrorException
- Thrown if the operation fails for any reason.private void defineOrderedAlternatives()
The following algorithm is used for ordering Message objects:
public static void associate(GameId id)
id
- The GameId object.public static void associate(GameId id, String lang) throws NoSuchDataException
id
- The GameId object.lang
- The symbolic name of the language to be associated with the game.
NoSuchDataException
- Thrown if the language name is unknown.public static Message create(String symbolicName, String displayableName) throws DataAlreadyExistsException, InternalErrorException
symbolicName
- The new language, using ISO-639, and optionally ISO-3166.displayableName
- The displayable name of the language.
DataAlreadyExistsException
- Thrown if the Message object for this language
already exists.
InternalErrorException
- Thrown if an error occurs for any reason.public static Message create(String symbolicLanguageName, String symbolicCountryName, String displayableName) throws DataAlreadyExistsException, InternalErrorException
DataAlreadyExistsException
- Thrown if the Message object for this language
already exists.
InternalErrorException
- Thrown if an error occurs for any reason.public static String getMessage(String symbolicLanguageName, String symbolicMessageName)
symbolicLanguageName
- The name of the language to use.symbolicMessageName
- The symbolic name of the message.
protected static String getExactMessage(String symbolicLanguageName, String symbolicMessageName) throws NoSuchDataException
symbolicLanguageName
- The name of the language to use.symbolicMessageName
- The symbolic name of the message.
NoSuchDataException
- Thrown if there is
no message for the symbol name.protected static Message getMessageObject(String symbolicLanguageName) throws NoSuchDataException
symbolicLanguageName
- The symbolic name of the language to get.
NoSuchDataException
- Thrown if there is no Message object for that
language name.public static String[] getAllMessageTypes()
public static String getMessage(String symbolicMessageName) throws NoSuchDataException
symbolicMessageName
- The symbolic name of the message.
NoSuchDataException
- Thrown if there is
no message for the symbol name.public static String getMessage(GameId id, String symbolicMessageName) throws NoSuchDataException
id
- The id of the game.symbolicMessageName
- The symbolic name of the message.
NoSuchDataException
- Thrown if there is
no message for the symbol name.private String getLangMessage(String symbolicMessageName) throws NoSuchDataException
symbolicMessageName
- The symbolic name of the message.
NoSuchDataException
- Thrown if there is
no message for the symbol name.public void setMessage(String symbolicMessageName, String value) throws InconsistentStateException
symbolicMessageName
- The symbolic name of the message.value
- The message in the specified language.
InconsistentStateException
- Thrown if the symbol does
not exist in the default language. This is done
to ensure that there is consistency across languages.public void removeMessage(String symbolicMessageName)
symbolicMessageName
- The symbolic name of the message.public void save() throws InternalErrorException
InternalErrorException
- Thrown if the operation fails for any reason.public static String getSymbolicLanguageName(String dispLangName) throws NoSuchDataException
dispLangName
- The displayable language name.
NoSuchDataException
- Thrown if the language name is unknown.public static String getDefaultLanguageSymbolicName()
public static String getDefaultLanguageDisplayableName()
protected static Message getDefaultMessageObject() throws InternalErrorException
InternalErrorException
- Thrown if the operation fails for any reason.public static String[] getDisplayableLanguageNames()
public static String[] getSymbolicLanguageNames()
protected void reset() throws InternalErrorException
InternalErrorException
- Thrown if the operation fails for any reason.public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
o
- The object being tested.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |