Package eu.bandm.tools.muli
Class Catalog<K>
java.lang.Object
eu.bandm.tools.muli.Catalog<K>
- Direct Known Subclasses:
CatalogByString
Each
Its structure is
All the different
muli.Catalog
represents a relation between a
MuLi
and objects of type [K]
,
serving as keys.
It can be used as a multi-lingual map, i.e. as a catalog in both directions.
Its structure is
mulitexts: (K -/-> MuLi) catalogs: (language:String -/-> name:String -/-> K)Both structures are maintained synchronuously when calling the "put()" methods.
muli.Catalog
objects are mutable. Currently there is no
immutable derived class.
All the different
put()
methods add new relation elements to the existing maps.
This can result in an override of one or more currently
stored existing relation elements, but this is not checked.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Wrapper class to prevent the translation OF AN ARGUMENT, eg. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
The string formatting process as defined withString.format(String,Object...)
is applied.protected String
_translateArgs
(List<String> pref, List<Object> args) boolean
containsKey
(K key) void
dump
(PrintStream s) For DEBUGGING: dump Catalog to printstream.Delivers an unmodifiable copy of theMuLi
for a given key object.Delivers the name of a given key object in a certain language.Delivers the name of a given key object in language chosen from a preference list.Delivers the key object for a given name in a given languagegetKeys()
Delivers all key objects for the (language, name) combinations given by theMuLi
argument.Delivers all key objects for a given name in all languages.Enters an "in-situ" definition into this translation catalog and returns the translated text immediately.Enters an "in-situ" definition into this translation catalog and returns the translated text immediately.Enters an "in-situ" definition into this translation catalog and returns the (un-translated) key.protected MuLi
static Catalog.Const
void
Add one certain key object, and a MuLi mapping languages to names.void
void
Add one certain key object, one language and one name.void
Add one certain key object, and a list of languages and namesvoid
Add the contents of a second catalog.void
Add the contents of a second catalog with a prefix added to every translation.readLanguageMap
(String lang) Delivers the mapString->K
for a given languageDelivers the set of all contained languagesreadLanguagesString
(String sep, String sep2) Delivers a list of all occuring languges, sorted alphabetically.translateAllAndFormatRobust
(K key, List<String> pref, Object... args) Translate the Key and all args by by callingtranslateRobust(Object,List)
.translateArgsAndFormatRobust
(K key, List<String> pref, Object... args) Do NOT translate the key, but call "toString()".translateKeyAndFormatRobust
(K key, List<String> pref, Object... args) Translate the Key by callingtranslateRobust(Object,List)
.translateRobust
(K key, String... pref) translateRobust
(K key, List<String> pref) Translate the key into one of the languages of the list "pref".
-
Field Details
-
keyClass
Currently only required for recursive application, when translating ARGUMENTS of a format string. -
mulitexts
-
catalogs
-
-
Constructor Details
-
Catalog
-
-
Method Details
-
getKey
Delivers the key object for a given name in a given language- Returns:
- the found key object, or
null
in case the combination of language and name has not been put.
-
getKeys
- Returns:
- all key objects in an unmodifiable copy. (FIXME could be sorted if comparable =)
-
getKeys
Delivers all key objects for a given name in all languages. -
getKeys
Delivers all key objects for the (language, name) combinations given by theMuLi
argument.
(MuLi.syntheticLanguage
,name) matches ALL languages. -
readLanguages
Delivers the set of all contained languages- Returns:
- a sorted copy of language keys
-
readLanguagesString
Delivers a list of all occuring languges, sorted alphabetically.- Parameters:
sep
- the separator between two languges keys.- Returns:
- a String containing all language keys
-
readLanguageMap
Delivers the mapString->K
for a given language- Returns:
- an unmodifiable map
-
get
Delivers an unmodifiable copy of theMuLi
for a given key object. -
get
Delivers the name of a given key object in a certain language.
(Do not mix up withget(K,String...)
which always returns some default! Bad naming design! FIXME)- Returns:
null
if no such name had been stored.
-
containsKey
- Returns:
- whether at least one language has an entry for the key.
-
get
Delivers the name of a given key object in language chosen from a preference list. This delegates toMuLi.get(String...)
, i.e. if no language in the list matches, the index field in the resultingTextFound
will be -1.- Returns:
- null in case that the key has never been stored.
-
get
- See Also:
-
translateRobust
Translate the key into one of the languages of the list "pref". If no such translation is found, then into an arbitrary selected language. If there is no single translation into any language then return "toString()".- Returns:
- always a String value, never null.
-
translateRobust
-
translateArgsAndFormatRobust
Do NOT translate the key, but call "toString()".
Translate all Objects in "args" by callingtranslateRobust(Object,List)
. Translating an "arg" means to applytranslateRobust(Object,List)
iff "arg" is instance ofkeyClass
, otherwise leave it unaltered.
Then apply string formatting.- Returns:
- always a String value, never null.
-
translateArgsAndFormatRobust
-
translateKeyAndFormatRobust
Translate the Key by callingtranslateRobust(Object,List)
.
Do NOT translate the args.
Then apply string formatting.- Returns:
- always a String value, never null.
-
translateKeyAndFormatRobust
-
translateAllAndFormatRobust
Translate the Key and all args by by callingtranslateRobust(Object,List)
.
Translating an "arg" means to applytranslateRobust(Object,List)
iff "arg" is instance ofkeyClass
, otherwise leave it unaltered.
Then apply string formatting.- Returns:
- always a String value, never null.
-
translateAllAndFormatRobust
-
_translateArgs
-
_format
-
_format
The string formatting process as defined withString.format(String,Object...)
is applied.
Whenever a formatting error occurs, this fact is represented as text and incorporated into the returned String value. So the process never fails, but the problems will be visible, normally in the output to the user.
ATTENTION FIXME make this behaviour configurable !?!? -
INSITU
Enters an "in-situ" definition into this translation catalog and returns the (un-translated) key. As a side effect the translations are stored for later retrieval. This allows to write the translation not in a separate file, but in the code at the place where it is called, which may be more convenient for some coding situation.
This variant returns the key, so it can be used as a sub-expression for the main text in a message expression.
ATTENTION more than one calls with the same key are illegal and bring unpredictable results, because only one of both storings will be executed.- Parameters:
key
-variants
- list of PAIRS of String, each language code and text
-
INSITU
-
insitu
Enters an "in-situ" definition into this translation catalog and returns the translated text immediately. As a side effect the translations are stored for later retrieval. This allows to write the translation not in a separate file, but in the code at the place where it is called, which may be more convenient for some coding situation.
This is the variant for constant texts, with no embedded "printf" codes.
(Its result can not be used as an argument for construction a message, when this shall be translated in a subsequent step. For this case useINSITU(K, java.util.List<java.lang.String>)
.)- Parameters:
key
-langprefs
- list of language preferences for the retrieved text, as usualvariants
- list of PAIRS of String, each language code and text
-
insitu
- See Also:
-
insitu
Enters an "in-situ" definition into this translation catalog and returns the translated text immediately. As a side effect the translations are stored for later retrieval. This allows to write the translation not in a separate file, but in the code at the place where it is called, which may be more convenient for soem coding situation.
The translation of the arguments happens as withtranslateAllAndFormatRobust(Object,List,List)
.
(Its result can not be used as an argument for construction a message, when this shall be translated in a subsequent step. For this case useINSITU(K, java.util.List<java.lang.String>)
.)- Parameters:
key
-langprefs
- list of language preferences, as usualvariants
- list of PAIRS of String, each language code and textargs
- objects formatted into the translated text by printf codes
-
insitu
- See Also:
-
makeMuli
-
makeMap
-
put
Add one certain key object, one language and one name.
Attention:
Existing map entries will silently be overwritten, but no further clean-up happens automatically. So re-usage ofCatalog
objects is not recommended:put (k1, L1, text_1) put (k1, L2, text_2) put (k1, L1, text_1_new)
... may lead to unintended combinations. -
put
- See Also:
-
put
Add one certain key object, and a list of languages and names- Parameters:
pairs
- sequence of key/value pairs- Throws:
IllegalArgumentException
- in case the number of Strings in not even.
-
put
Add one certain key object, and a MuLi mapping languages to names. -
putAll
Add the contents of a second catalog. ATTENTION: overriding is hard, and no concistency checks are applied. -
putAll
Add the contents of a second catalog with a prefix added to every translation. ATTENTION: overriding is hard, and no concistency checks are applied. -
dump
For DEBUGGING: dump Catalog to printstream.- Parameters:
s
-PrintStream
to print to.
-
noTranslate
-