Package org.languagetool
Class Languages
- java.lang.Object
-
- org.languagetool.Languages
-
public final class Languages extends java.lang.Object
Helper methods to list all supported languages and to get language objects by their name or language code etc.- Since:
- 2.9
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<Language>
dynLanguages
private static java.util.List<Language>
languages
private static Language
NOOP_LANGUAGE
private static java.lang.String
PROPERTIES_KEY
private static java.lang.String
PROPERTIES_PATH
-
Constructor Summary
Constructors Modifier Constructor Description private
Languages()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Language
addLanguage(java.lang.String name, java.lang.String code, java.io.File dictPath)
private static Language
createLanguageObjects(java.net.URL url, java.lang.String className)
static java.util.List<Language>
get()
Language classes are detected at runtime by searching the classpath for files namedMETA-INF/org/languagetool/language-module.properties
.private static java.util.List<Language>
getAllLanguages()
private static @Nullable Language
getLanguageForLanguageNameAndCountry(java.util.Locale locale)
private static @Nullable Language
getLanguageForLanguageNameOnly(java.util.Locale locale)
static Language
getLanguageForLocale(java.util.Locale locale)
Get the best match for a locale, using American English as the final fallback if nothing else fits.static @Nullable Language
getLanguageForName(java.lang.String languageName)
Get the Language object for the given language name.static Language
getLanguageForShortCode(java.lang.String langCode)
Get the Language object for the given language code.static Language
getLanguageForShortCode(java.lang.String langCode, java.util.List<java.lang.String> noopLanguageCodes)
Get the Language object for the given language code.private static @Nullable Language
getLanguageForShortCodeOrNull(java.lang.String langCode)
private static java.util.List<Language>
getStaticAndDynamicLanguages()
static java.util.List<Language>
getWithDemoLanguage()
Likeget()
but the list contains also LanguageTool's internal 'Demo' language, if available.static boolean
isLanguageSupported(java.lang.String langCode)
Return whether a language with the given language code is supported.
-
-
-
Field Detail
-
PROPERTIES_PATH
private static final java.lang.String PROPERTIES_PATH
- See Also:
- Constant Field Values
-
PROPERTIES_KEY
private static final java.lang.String PROPERTIES_KEY
- See Also:
- Constant Field Values
-
NOOP_LANGUAGE
private static final Language NOOP_LANGUAGE
-
languages
private static final java.util.List<Language> languages
-
dynLanguages
private static final java.util.List<Language> dynLanguages
-
-
Method Detail
-
addLanguage
public static Language addLanguage(java.lang.String name, java.lang.String code, java.io.File dictPath)
- Since:
- 4.5
-
get
public static java.util.List<Language> get()
Language classes are detected at runtime by searching the classpath for files namedMETA-INF/org/languagetool/language-module.properties
. Those file(s) need to contain a keylanguageClasses
which specifies the fully qualified class name(s), e.g.org.languagetool.language.English
. Use commas to specify more than one class.- Returns:
- an unmodifiable list of all supported languages
-
getWithDemoLanguage
public static java.util.List<Language> getWithDemoLanguage()
Likeget()
but the list contains also LanguageTool's internal 'Demo' language, if available. Only useful for tests.- Returns:
- an unmodifiable list
-
getStaticAndDynamicLanguages
private static java.util.List<Language> getStaticAndDynamicLanguages()
-
getAllLanguages
private static java.util.List<Language> getAllLanguages()
-
createLanguageObjects
private static Language createLanguageObjects(java.net.URL url, java.lang.String className)
-
getLanguageForName
@Nullable public static @Nullable Language getLanguageForName(java.lang.String languageName)
Get the Language object for the given language name.- Parameters:
languageName
- e.g.English
orGerman
(case is significant)- Returns:
- a Language object or
null
if there is no such language
-
getLanguageForShortCode
public static Language getLanguageForShortCode(java.lang.String langCode)
Get the Language object for the given language code.- Parameters:
langCode
- e.g.en
oren-US
- Throws:
java.lang.IllegalArgumentException
- if the language is not supported or if the language code is invalid- Since:
- 3.6
-
getLanguageForShortCode
public static Language getLanguageForShortCode(java.lang.String langCode, java.util.List<java.lang.String> noopLanguageCodes)
Get the Language object for the given language code.- Parameters:
langCode
- e.g.en
oren-US
noopLanguageCodes
- list of languages that can be detected but that will not actually find any errors (can be used so non-supported languages are not detected as some other language)- Throws:
java.lang.IllegalArgumentException
- if the language is not supported or if the language code is invalid- Since:
- 4.4
-
isLanguageSupported
public static boolean isLanguageSupported(java.lang.String langCode)
Return whether a language with the given language code is supported. Which languages are supported depends on the classpath when theLanguage
object is initialized.- Parameters:
langCode
- e.g.en
oren-US
- Returns:
- true if the language is supported
- Throws:
java.lang.IllegalArgumentException
- in some cases of an invalid language code format
-
getLanguageForLocale
public static Language getLanguageForLocale(java.util.Locale locale)
Get the best match for a locale, using American English as the final fallback if nothing else fits. The returned language will be a country variant language (e.g. British English, not just English) if available. Note: this does not consider languages added dynamically- Throws:
java.lang.RuntimeException
- if no language was found and American English as a fallback is not available
-
getLanguageForShortCodeOrNull
@Nullable private static @Nullable Language getLanguageForShortCodeOrNull(java.lang.String langCode)
-
getLanguageForLanguageNameAndCountry
@Nullable private static @Nullable Language getLanguageForLanguageNameAndCountry(java.util.Locale locale)
-
getLanguageForLanguageNameOnly
@Nullable private static @Nullable Language getLanguageForLanguageNameOnly(java.util.Locale locale)
-
-