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

  • 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)
    • getLanguageForName

      @Nullable public static @Nullable 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
    • 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
    • getLanguageForShortCodeOrNull

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

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

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