@Override public String[] getCountries() { return baseLanguage.getCountries(); }
private boolean hasCountry() { return getCountries().length == 1; }
@Nullable private static Language getLanguageForLanguageNameAndCountry(Locale locale) { for (Language language : LANGUAGES) { if (language.getShortCode().equals(locale.getLanguage())) { List<String> countryVariants = Arrays.asList(language.getCountries()); if (countryVariants.contains(locale.getCountry())) { return language; } } } return null; }
/** * Get this language's Java locale, considering language code and country code (if any). * @since 2.1 */ public Locale getLocaleWithCountryAndVariant() { if (getCountries().length > 0) { if (getVariant() != null) { return new Locale(getShortCode(), getCountries()[0], getVariant()); } else { return new Locale(getShortCode(), getCountries()[0]); } } else { return getLocale(); } }
/** * Get the short name of the language with country and variant (if any), if it is * a single-country language. For generic language classes, get only a two- or * three-character code. * @since 3.6 */ public final String getShortCodeWithCountryAndVariant() { String name = getShortCode(); if (getCountries().length == 1 && !name.contains("-x-")) { // e.g. "de-DE-x-simple-language" name += "-" + getCountries()[0]; if (getVariant() != null) { // e.g. "ca-ES-valencia" name += "-" + getVariant(); } } return name; }
for (Language element : LANGUAGES) { if (parts[0].equalsIgnoreCase(element.getShortCode()) && element.getCountries().length == 1 && parts[1].equalsIgnoreCase(element.getCountries()[0])) { result = element; break; for (Language element : LANGUAGES) { if (parts[0].equalsIgnoreCase(element.getShortCode()) && element.getCountries().length == 1 && parts[1].equalsIgnoreCase(element.getCountries()[0]) && parts[2].equalsIgnoreCase(element.getVariant())) { result = element;
/** * Gets the ResourceBundle (i18n strings) for the given user interface language. */ static ResourceBundle getMessageBundle(Language lang) { try { ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocaleWithCountryAndVariant()); if (!isValidBundleFor(lang, bundle)) { bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocale()); if (!isValidBundleFor(lang, bundle)) { // happens if 'xx' is requested but only a MessagesBundle_xx_YY.properties exists: Language defaultVariant = lang.getDefaultLanguageVariant(); if (defaultVariant != null && defaultVariant.getCountries().length > 0) { Locale locale = new Locale(defaultVariant.getShortCode(), defaultVariant.getCountries()[0]); bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale); } } } ResourceBundle fallbackBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH); return new ResourceBundleWithFallback(bundle, fallbackBundle); } catch (MissingResourceException e) { return ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH); } }
@Override protected void init() throws IOException { super.init(); String langCountry = language.getShortCode(); if (language.getCountries().length > 0) { langCountry += "_" + language.getCountries()[0]; } String shortDicPath = "/" + language.getShortCode() + "/hunspell/" + langCountry + FILE_EXTENSION; String wordChars = ""; // set dictionary only if there are dictionary files: if (JLanguageTool.getDataBroker().resourceExists(shortDicPath)) { String path = getDictionaryPath(langCountry, shortDicPath); if ("".equals(path)) { hunspellDict = null; } else { hunspellDict = Hunspell.getInstance().getDictionary(path); if (!hunspellDict.getWordChars().isEmpty()) { wordChars = "(?![" + hunspellDict.getWordChars().replace("-", "\\-") + "])"; } addIgnoreWords(); } } nonWordPattern = Pattern.compile(wordChars + NON_ALPHABETIC); needsInit = false; }
private boolean hasCountry() { return getCountries().length == 1; }
@Override public String[] getCountries() { return baseLanguage.getCountries(); }
Language lang = Language.English; lang.getCountries(); // England, USA
@Nullable private static Language getLanguageForLanguageNameAndCountry(Locale locale) { for (Language language : LANGUAGES) { if (language.getShortCode().equals(locale.getLanguage())) { List<String> countryVariants = Arrays.asList(language.getCountries()); if (countryVariants.contains(locale.getCountry())) { return language; } } } return null; }
/** * Get the short name of the language with country and variant (if any), if it is * a single-country language. For generic language classes, get only a two- or * three-character code. * @since 3.6 */ public final String getShortCodeWithCountryAndVariant() { String name = getShortCode(); if (getCountries().length == 1 && !name.contains("-x-")) { // e.g. "de-DE-x-simple-language" name += "-" + getCountries()[0]; if (getVariant() != null) { // e.g. "ca-ES-valencia" name += "-" + getVariant(); } } return name; }
/** * Get this language's Java locale, considering language code and country code (if any). * @since 2.1 */ public Locale getLocaleWithCountryAndVariant() { if (getCountries().length > 0) { if (getVariant() != null) { return new Locale(getShortCode(), getCountries()[0], getVariant()); } else { return new Locale(getShortCode(), getCountries()[0]); } } else { return getLocale(); } }
for (Language element : LANGUAGES) { if (parts[0].equalsIgnoreCase(element.getShortCode()) && element.getCountries().length == 1 && parts[1].equalsIgnoreCase(element.getCountries()[0])) { result = element; break; for (Language element : LANGUAGES) { if (parts[0].equalsIgnoreCase(element.getShortCode()) && element.getCountries().length == 1 && parts[1].equalsIgnoreCase(element.getCountries()[0]) && parts[2].equalsIgnoreCase(element.getVariant())) { result = element;
/** * Gets the ResourceBundle (i18n strings) for the given user interface language. */ static ResourceBundle getMessageBundle(Language lang) { try { ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocaleWithCountryAndVariant()); if (!isValidBundleFor(lang, bundle)) { bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocale()); if (!isValidBundleFor(lang, bundle)) { // happens if 'xx' is requested but only a MessagesBundle_xx_YY.properties exists: Language defaultVariant = lang.getDefaultLanguageVariant(); if (defaultVariant != null && defaultVariant.getCountries().length > 0) { Locale locale = new Locale(defaultVariant.getShortCode(), defaultVariant.getCountries()[0]); bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale); } } } ResourceBundle fallbackBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH); return new ResourceBundleWithFallback(bundle, fallbackBundle); } catch (MissingResourceException e) { return ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH); } }
String morfoFile = "/de/hunspell/de_" + language.getCountries()[0] + ".dict"; if (JLanguageTool.getDataBroker().resourceExists(morfoFile)) {
@Override protected void init() throws IOException { super.init(); String langCountry = language.getShortCode(); if (language.getCountries().length > 0) { langCountry += "_" + language.getCountries()[0]; } String shortDicPath = "/" + language.getShortCode() + "/hunspell/" + langCountry + FILE_EXTENSION; String wordChars = ""; // set dictionary only if there are dictionary files: if (JLanguageTool.getDataBroker().resourceExists(shortDicPath)) { String path = getDictionaryPath(langCountry, shortDicPath); if ("".equals(path)) { hunspellDict = null; } else { hunspellDict = Hunspell.getInstance().getDictionary(path); if (!hunspellDict.getWordChars().isEmpty()) { wordChars = "(?![" + hunspellDict.getWordChars().replace("-", "\\-") + "])"; } addIgnoreWords(); } } nonWordPattern = Pattern.compile(wordChars + NON_ALPHABETIC); needsInit = false; }
for (Language ltLang : ltLangs) { if (omLang.equalsIgnoreCase(ltLang.getShortName())) { List<String> countries = Arrays.asList(ltLang.getCountries()); if (countries.contains(omCountry)) { return ltLang;