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
  • Field Details

    • PROPERTIES_PATH

      private static final String PROPERTIES_PATH
      See Also:
    • PROPERTIES_KEY

      private static final String PROPERTIES_KEY
      See Also:
    • NOOP_LANGUAGE

      private static final Language NOOP_LANGUAGE
    • languages

      private static final List<Language> languages
    • dynLanguages

      private static final List<Language> dynLanguages
    • staticAndDynamicLanguages

      private static final List<Language> staticAndDynamicLanguages
    • staticAndDynamicLanguagesImmutable

      private static final List<Language> staticAndDynamicLanguagesImmutable
  • Constructor Details

    • Languages

      private Languages()
  • Method Details

    • addLanguage

      public static Language addLanguage(String name, String code, File dictPath)
      Since:
      4.5
    • get

      public static List<Language> get()
      Language classes are detected at runtime by searching the classpath for files named META-INF/org/languagetool/language-module.properties. Those file(s) need to contain a key languageClasses 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()
      Like get() but the list contains also LanguageTool's internal 'Demo' language, if available. Only useful for tests.
      Returns:
      an unmodifiable list
    • getStaticAndDynamicLanguages

      private static List<Language> getStaticAndDynamicLanguages()
    • getAllLanguages

      private static List<Language> getAllLanguages()
    • createLanguageObjects

      private static Language createLanguageObjects(URL url, String className)
    • hasPremium

      static boolean hasPremium(String className)
    • getOrAddLanguageByClassName

      public static Language getOrAddLanguageByClassName(String className)
      Get the Language object for the given language class name or try to create it and add to dynamic languages.
      Parameters:
      className - e.g. org.languagetool.language.English
      Returns:
      a Language object
      Throws:
      RuntimeException - if language not found in classpath
      Since:
      5.0
    • getLanguageForName

      @Nullable public static Language getLanguageForName(String languageName)
      Get the Language object for the given language name.
      Parameters:
      languageName - e.g. English or German (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 or en-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 or en-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
    • getLangCodes

      @NotNull private static List<String> getLangCodes()
    • 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 the Language object is initialized.
      Parameters:
      langCode - e.g. en or en-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
    • getLongCodeToLangMapping

      public static Map<String,Language> getLongCodeToLangMapping()
      For internal use only. Returns a mapping from fr-FR to its language etc. Used to support requests from LibreOffice 7.4, which sends these language codes.
    • getLanguageForShortCodeOrNull

      @Nullable private static Language getLanguageForShortCodeOrNull(String langCode)
    • getLanguageForLanguageNameAndCountry

      @Nullable private static Language getLanguageForLanguageNameAndCountry(Locale locale)
    • getLanguageForLanguageNameOnly

      @Nullable private static Language getLanguageForLanguageNameOnly(Locale locale)