public class LanguageFile
extends java.lang.Object
$
and is a so called wildcard for a language dependent label.$FILE #de = Datei #en = FileTo get the description of a label in a specific language, use
getLabel(String, String)
.
$LANGUAGES
label. Under this label you can specify
the languages and their description the language file contains, like:
$LANGUAGES #de = Deutsch #en = EnglishTo get all available languages in this language file, use
getAvailableLanguages()
.
%n
like
$HELLO_WORLD_LABEL #de = Hallo%nWelt! #en = Hello%nWorld!Language identifiers:
#
followed by the id string. With the assignment operator =
you can assign a language
specific description of the label.//
is marked as a comment and is skipped.
But beware, a comment can not start behind a label id or something else, that means the whole line is a comment or nothing!
charset
parameter of a constructor (by default the charset
is UTF-8
Project -> Properties -> Resources
,
enable Other
and select the corresponding encoding// This is a language file of software XYZ. // Copyright (c) 2013, XYZ Company $LANGUAGES #en = English #de = Deutsch $FILE #en = File #de = Datei $FILE_NEW #en = New... #de = Neu... $FILE_SAVE #en = Save #de = Speichern $FILE_SAVE_AS #en = Save as... #de = Speichern unter... ...Including other files:
include(LanguageFile)
to include another language file to this one.
getLabel(LanguageFile, String, String, String)
to load label descriptions.Constructor and Description |
---|
LanguageFile(java.io.File file)
Loads a new language file.
|
LanguageFile(java.io.File file,
java.lang.String charset)
Loads a new language file.
|
LanguageFile(java.io.InputStream stream)
Loads a new language file.
|
LanguageFile(java.io.InputStream stream,
java.lang.String charset)
Loads a new language file.
|
LanguageFile(java.lang.String filename)
Loads a new language file.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<LabelEntry> |
getAvailableLanguages()
Gets the available languages in this language file if the
$LANGUAGES label exists. |
static java.lang.String |
getLabel(LanguageFile file,
java.lang.String labelID,
java.lang.String langID)
Gets a the description of a label of a language file.
|
static java.lang.String |
getLabel(LanguageFile file,
java.lang.String labelID,
java.lang.String langID,
java.lang.String defValue)
Gets a the description of a label of a language file.
|
java.lang.String |
getLabel(java.lang.String labelID,
java.lang.String langID)
Gets a language specific label.
|
java.lang.String |
getLabel(java.lang.String labelID,
java.lang.String langID,
java.lang.String defValue)
Gets a language specific label.
|
void |
include(LanguageFile file)
Includes the language data of the given file into this one.
|
public LanguageFile(java.lang.String filename) throws java.io.IOException
filename
- the file path and name of the language filejava.io.IOException
- public LanguageFile(java.io.File file) throws java.io.IOException
UTF-8
. Use LanguageFile(File, String)
to specify another one.file
- the language filejava.io.IOException
- public LanguageFile(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- the language filecharset
- the charset of the language filejava.io.IOException
- public LanguageFile(java.io.InputStream stream) throws java.io.IOException
UTF-8
. Use LanguageFile(InputStream, String)
to specify another one.stream
- the language file streamjava.io.IOException
- public LanguageFile(java.io.InputStream stream, java.lang.String charset) throws java.io.IOException
stream
- the language file streamcharset
- the charset of the language filejava.io.IOException
- public java.util.List<LabelEntry> getAvailableLanguages()
$LANGUAGES
label exists.
$LANGUAGES
label, like:
$LANGUAGES #de = Deutsch #en = English
public java.lang.String getLabel(java.lang.String labelID, java.lang.String langID)
labelID
- the label idlangID
- the language idpublic java.lang.String getLabel(java.lang.String labelID, java.lang.String langID, java.lang.String defValue)
labelID
- the label idlangID
- the language iddefValue
- the default value of the label if it does not exist in the given language or null
if no default value is defined (then the labelID is returned)public static java.lang.String getLabel(LanguageFile file, java.lang.String labelID, java.lang.String langID)
file
- the language file or null
if no language file existslabelID
- the label idlangID
- the language idpublic static java.lang.String getLabel(LanguageFile file, java.lang.String labelID, java.lang.String langID, java.lang.String defValue)
file
- the language file or null
if no language file existslabelID
- the label idlangID
- the language iddefValue
- the default value of the label if it does not exist in the given language or null
if no default value is defined (then the labelID is returned)null
or no suitable language is foundpublic void include(LanguageFile file) throws java.lang.IllegalArgumentException
file
- the language file its labels should be transfered to this onejava.lang.IllegalArgumentException
-