Package eu.bandm.tools.muli
Class MuLi
java.lang.Object
eu.bandm.tools.muli.MuLi
Realizes a multi-lingual identifier or text.
Mostly it is used to contain names for the same object in different
languages.
Its structure is
language ::= (String U syntheticLanguage)
MuLi ::= language -/-> String
SYNTHETIC_LANGUAGE
is a special string value reserved for the cases
in which a language differentiation is not applicable (e.g. for pure
numeric strings or personal names).
The language
values should follow the (older) ISO
two-character language codes, as specified in
ISO 639-2. These are the codes also used by "xml:lang
",
cf. RFC 4646 / RFC 4647 / IETF BCP 47.
At least they should not have the value of the
SYNTHETIC_LANGUAGE
string.
The look-up function getSpecific(String)
delegates to a map
object and has the usual Java-like semantics, esp. returning null
if
the argument is not in the domain.
Further, there is a special look-up function
get(String...)
of type
get : preference:(SEQ language) -> MuLi.TextFoundwith
MuLi.TextFound ::= (index:(NAT U{-1}) * language:String * result:StringThe object of class
MuLi.TextFound
,
as returned by the function, reflects the most left language in
the original preference list for which an entry can be found in the
MuLi
object.
An index of minus one indicates the fact that the found language is chosen by random and was not in the list of preferred languages.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class representing the result of calls toget(String...)
and sim. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns an unmodifiable copy.boolean
containsLang
(String lang) Return whether there is an entry in the given language.Return aMuLi.TextFound
object representing the first string found when trying the listed languages from left to right.Return aMuLi.TextFound
object representing the first string found when trying the listed languages from left to right.Returns an unmodifiable copy of all languages serving as keys.getSpecific
(String lang) Return the string stored under a particular key.Deprecated, for removal: This API element is subject to removal in a future version.Put a new key/value pair into the internal map.Deprecated.use "put(Collections.literalMap(Object,Object)
)" instead!Put a multitude of key/value pairs into the internal map.toString()
Return a string representation.
-
Field Details
-
SYNTHETIC_LANGUAGE
Use this as key value forput
andget
in cases where no natural language is applicable. E.g. for technical notions, personal names, formulae.- See Also:
-
texts
Map from the target languages to their text versions.
-
-
Constructor Details
-
MuLi
public MuLi()Construct an empty instance. -
MuLi
Initialize translations, Keys if the map must be language codes, the values the translations.- Parameters:
data
- the initial translations
-
-
Method Details
-
cloneUnmodifiable
Returns an unmodifiable copy.- Returns:
- an unmodifiable copy.
-
toString
Return a string representation. -
getLanguages
Returns an unmodifiable copy of all languages serving as keys.- Returns:
- an unmodifiable copy of all languages serving as keys.
-
getSpecific
Return the string stored under a particular key. This key represents the language of the requested naming. Is directly mapped to java.util.Map, i.e. returnsnull
if the key is not in the map. In contrast to other get methods, no fall-back mechanisms take place.- Parameters:
lang
- the language for which the translation is searched.- Returns:
- the string stored for the given language.
-
containsLang
Return whether there is an entry in the given language. Equivalency holds:containsLang(l) == (getSpecific(l) != null)
.- Parameters:
lang
- the language.- Returns:
- whether there is an entry in the given language.
-
get
Return aMuLi.TextFound
object representing the first string found when trying the listed languages from left to right. If no such translation is found, return an arbitrary one. If no translation exists, return null.- Parameters:
preference
- the priority list of languages.- Returns:
- a
MuLi.TextFound
object representing the first string found.
-
get
Return aMuLi.TextFound
object representing the first string found when trying the listed languages from left to right.- Parameters:
preference
- the priority list of languages.- Returns:
- a
MuLi.TextFound
object representing the first string found. - See Also:
-
put
Put a new key/value pair into the internal map. Existing entries will silently be overwritten.- Parameters:
lang
- the key, should be a language code.text
- the value, i.e. the translation into this language.- Returns:
- this for method chaining.
-
put
Put a multitude of key/value pairs into the internal map. The map entries are separated into key and value, and passed toput(String,String)
. Thus existing entries will silently be overwritten.- Parameters:
data
- map of language to name- Returns:
- this for method chaining.
-
put
Deprecated, for removal: This API element is subject to removal in a future version.use "put(Collections.literalMap(Object,Object)
)" instead!Put a multitude of key/value pairs into the internal map. The number of arguments must be even. The arguments are intepreted as key and value, alternatingly, and passed toput(String,String)
.
So, existing entries will silently be overwritten.- Parameters:
pairs
- sequence of key/value pairs- Returns:
- this for method chaining.
- Throws:
IllegalArgumentException
- in case the number of Strings in not even.
-
put
Deprecated.use "put(Collections.literalMap(Object,Object)
)" instead!- Parameters:
pairs
- sequence of key/value pairs- Returns:
- this for method chaining.
- See Also:
-
Collections.literalMap(Object,Object)
)" instead!