|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.nand.util.i18n.mgr.StringManager soc.util.SOCStringManager
public class SOCStringManager
String Manager for retrieving I18N localized text from .properties
bundle files
with special methods for formatting JSettlers objects.
See comments at the top of .properties
files for more details on key-value formatting and message parameters.
Remember that .properties
bundle files are encoded not in UTF-8
but in ISO-8859-1
:
VERSION_FOR_I18N
.
I18n
Field Summary | |
---|---|
private static SOCStringManager |
clientManager
Manager for all client strings. |
private static java.lang.String[][] |
GETSPECIAL_RSRC_KEYS
Resource type-and-count text keys for getSpecial(SOCGame, String, Object...) . |
private static java.util.Hashtable<java.lang.String,SOCStringManager> |
serverManagerForClientLocale
Manager at server for strings sent to the client. |
private static SOCStringManager |
serverManagerForClientLocale_fallback
Fallback for serverManagerForClientLocale using server's default locale. |
static int |
VERSION_FOR_I18N
Minimum version (2.0.00) of client/server with I18N localization. |
Fields inherited from class net.nand.util.i18n.mgr.StringManager |
---|
bundle |
Constructor Summary | |
---|---|
SOCStringManager(java.lang.String bundlePath)
Create a string manager for the bundles at bundlePath with the default locale. |
|
SOCStringManager(java.lang.String bundlePath,
java.util.Locale loc)
Create a string manager for the bundles at bundlePath with a certain Locale. |
Method Summary | |
---|---|
static SOCStringManager |
getClientManager()
Create or retrieve the cached client string manager, with the default Locale. |
static SOCStringManager |
getClientManager(java.util.Locale loc)
Create or retrieve the cached client string manager, with a certain Locale. |
static SOCStringManager |
getFallbackServerManagerForClient()
Create or retrieve the server's string manager for fallback to send text to clients with unknown locale. |
static SOCStringManager |
getServerManagerForClient(java.util.Locale loc)
Create or retrieve the server's string manager to send text to a clients with a certain locale. |
java.lang.String |
getSOCResourceCount(int rtype,
java.lang.Integer rcountObj)
Get a resource count, such as "5 sheep"; used by getSpecial(SOCGame, String, Object...) . |
java.lang.String |
getSpecial(SOCGame game,
java.lang.String key,
java.lang.Object... arguments)
Get and format a localized string (with special SoC-specific parameters) with the given key. |
Methods inherited from class net.nand.util.i18n.mgr.StringManager |
---|
get, get |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int VERSION_FOR_I18N
private static SOCStringManager clientManager
private static java.util.Hashtable<java.lang.String,SOCStringManager> serverManagerForClientLocale
Key = locale.toString, value = SOCStringManager
for server strings to clients in that locale.
Uses Hashtable to gain synchronization.
private static SOCStringManager serverManagerForClientLocale_fallback
serverManagerForClientLocale
using server's default locale.
private static final java.lang.String[][] GETSPECIAL_RSRC_KEYS
getSpecial(SOCGame, String, Object...)
.
Each subarray's indexes are the same values as SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
.
The string key at index 0 is used for resources out of range (unknown types).
getSOCResourceCount(int, Integer)
Constructor Detail |
---|
public SOCStringManager(java.lang.String bundlePath)
bundlePath
with the default locale.
Remember that bundle files are encoded not in UTF-8
but in ISO-8859-1
, see class javadoc.
bundlePath
- Bundle path, will be retrieved with ResourceBundle.getBundle(String)
public SOCStringManager(java.lang.String bundlePath, java.util.Locale loc)
bundlePath
with a certain Locale.
Remember that bundle files are encoded not in UTF-8
but in ISO-8859-1
, see class javadoc.
bundlePath
- Bundle path, will be retrieved with ResourceBundle.getBundle(String, Locale)
loc
- Locale to use; not null
Method Detail |
---|
public final java.lang.String getSOCResourceCount(int rtype, java.lang.Integer rcountObj) throws java.util.MissingResourceException
getSpecial(SOCGame, String, Object...)
.
rtype
- Type of resource, in the range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
rcountObj
- Resource count; uses the Integer object passed into getSpecial
.
As a special case, -1 will localize with the indefinite article, such as "a sheep" or "an ore".
-2 will localize to the plural resource name without a count, as in "clay" or "la lana".
rtype
is out of range,
"3 resources of unknown type 37"
java.util.MissingResourceException
- if no string can be found for key
; this is a RuntimeExceptionpublic java.lang.String getSpecial(SOCGame game, java.lang.String key, java.lang.Object... arguments) throws java.util.MissingResourceException, java.lang.IllegalArgumentException
I18n.listItems(List, SOCStringManager)
. Use a List
in arguments
.
SOCResourceSet
in arguments
.
Resource names ("5 sheep") take 2 argument slots: an Integer for the count, and a
resource type Integer in the range SOCResourceConstants.CLAY
- SOCResourceConstants.WOOD
.
Special case: A count of -1 will localize with "a/an", such as "a sheep" or "an ore".
A count of -2 will localize to the plural resource name without a number, for uses such as "Joe monopolized clay".
arguments
should contain a single Integer or SOCInventoryItem
, or a List
of them,
in the range SOCDevCardConstants.MIN
- SOCDevCardConstants.TOW
.
The returned format will include indefinite articles: "a Year of Plenty", "a Market (1 VP)", etc.
game
- Game, in case its options influence the strings (such as dev card Knight -> Warship in scenario _SC_PIRI)key
- Key to use for string retrieval. Can contain {0,rsrcs} and or {0,dcards}.
You can use {1, {2, or any other slot number.arguments
- Objects to go with {0,list}, {0,rsrcs}, {0,dcards}, etc in key
;
see above for the expected object types.
java.util.MissingResourceException
- if no string can be found for key
; this is a RuntimeException
java.lang.IllegalArgumentException
- if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)getSOCResourceCount(int, Integer)
public static SOCStringManager getClientManager()
public static SOCStringManager getClientManager(java.util.Locale loc)
loc
- Locale to use; not null
public static SOCStringManager getServerManagerForClient(java.util.Locale loc)
loc
- Locale to use, or null
for the Locale.getDefault()
public static SOCStringManager getFallbackServerManagerForClient()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |