Package org.languagetool
Class Languages
- java.lang.Object
-
- org.languagetool.Languages
-
public final class Languages extends Object
Helper methods to list all supported languages and to get language objects by their name or language code etc.- Since:
- 2.9
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Language
addLanguage(String name, String code, File dictPath)
static List<Language>
get()
Language classes are detected at runtime by searching the classpath for files namedMETA-INF/org/languagetool/language-module.properties
.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.static List<Language>
getWithDemoLanguage()
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.
-
-
-
Method Detail
-
get
public static 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 List<Language> getWithDemoLanguage()
Likeget()
but the list contains also LanguageTool's internal 'Demo' language, if available. Only useful for tests.- Returns:
- an unmodifiable list
-
getLanguageForName
@Nullable public static @Nullable Language getLanguageForName(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(String langCode)
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
public static Language getLanguageForShortCode(String langCode, List<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:
IllegalArgumentException
- if the language is not supported or if the language code is invalid- Since:
- 4.4
-
isLanguageSupported
public static boolean isLanguageSupported(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:
IllegalArgumentException
- in some cases of an invalid language code format
-
getLanguageForLocale
public static Language getLanguageForLocale(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:
RuntimeException
- if no language was found and American English as a fallback is not available
-
-