Package org.languagetool
Class Languages
java.lang.Object
org.languagetool.Languages
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Language
addLanguage
(String name, String code, File dictPath) private static Language
createLanguageObjects
(URL url, String className) get()
Language classes are detected at runtime by searching the classpath for files namedMETA-INF/org/languagetool/language-module.properties
.private static @Nullable Language
private static @Nullable Language
getLanguageForLanguageNameOnly
(Locale locale) static Language
getLanguageForLocale
(Locale locale) Get the best match for a locale, using American English as the final fallback if nothing else fits.static @Nullable Language
getLanguageForName
(String languageName) Get the Language object for the given language name.static Language
getLanguageForShortCode
(String langCode) Get the Language object for the given language code.static Language
getLanguageForShortCode
(String langCode, List<String> noopLanguageCodes) Get the Language object for the given language code.private static @Nullable Language
getLanguageForShortCodeOrNull
(String langCode) Likeget()
but the list contains also LanguageTool's internal 'Demo' language, if available.static boolean
isLanguageSupported
(String langCode) Return whether a language with the given language code is supported.
-
Field Details
-
PROPERTIES_PATH
- See Also:
-
PROPERTIES_KEY
- See Also:
-
NOOP_LANGUAGE
-
languages
-
dynLanguages
-
-
Constructor Details
-
Languages
private Languages()
-
-
Method Details
-
addLanguage
- Since:
- 4.5
-
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
Likeget()
but the list contains also LanguageTool's internal 'Demo' language, if available. Only useful for tests.- Returns:
- an unmodifiable list
-
getStaticAndDynamicLanguages
-
getAllLanguages
-
createLanguageObjects
-
getLanguageForName
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
Get the Language object for the given language code.- Parameters:
langCode
- e.g.en
oren-US
- Throws:
IllegalArgumentException
- if the language is not supported or if the language code is invalid- Since:
- 3.6
-
getLanguageForShortCode
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:
IllegalArgumentException
- if the language is not supported or if the language code is invalid- Since:
- 4.4
-
isLanguageSupported
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:
IllegalArgumentException
- in some cases of an invalid language code format
-
getLanguageForLocale
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:
RuntimeException
- if no language was found and American English as a fallback is not available
-
getLanguageForShortCodeOrNull
-
getLanguageForLanguageNameAndCountry
-
getLanguageForLanguageNameOnly
-