/** * Check if the specified locale is supported by this translation, specifically if the {@link #getTargetLocale() * targeted locale} is a superset of it. * * @param locale the locale to check * @return {@code true} if the specified locale is supported */ protected boolean isLocaleSupported(Locale locale) { return locale.toLanguageTag().startsWith(getTargetLocale().toLanguageTag()); }
@Override public boolean isVocabularySupported(Vocabulary vocabulary) { return getTargetVocabularyId().equals(vocabulary.getIdentifier()); }
/** * Check if the current context is set to a locale {@link #isLocaleSupported(Locale) supported} by this translation. * * @return {@code true} if the current locale is supported */ protected boolean isCurrentLocaleTargeted() { return isLocaleSupported(this.localizationContext.getCurrentLocale()); }
@Override public void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary) { if (!isTargetLocaleEnabled()) { return; } Locale targetLocale = getTargetLocale(); String label = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(NAME_KEY), targetLocale); String definition = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(DESCRIPTION_KEY), targetLocale); String synonyms = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(SYNONYM_KEY), targetLocale); if (StringUtils.isNotBlank(label)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, NAME_KEY, targetLocale), label); } if (StringUtils.isNotBlank(definition)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, DESCRIPTION_KEY, targetLocale), definition); } if (StringUtils.isNotBlank(synonyms)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, SYNONYM_KEY, targetLocale), splitMultiValuedText(synonyms)); } }
@Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) if (!isCurrentLocaleTargeted()) { return; if (currentLocale != null && isLocaleSupported(currentLocale)) { Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) {
@Override public void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary) { Locale targetLocale = getTargetLocale(); String label = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(NAME_KEY), targetLocale); String definition = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(DESCRIPTION_KEY), targetLocale); String synonyms = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(SYNONYM_KEY), targetLocale); if (StringUtils.isNotBlank(label)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, NAME_KEY, targetLocale), label); } if (StringUtils.isNotBlank(definition)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, DESCRIPTION_KEY, targetLocale), definition); } if (StringUtils.isNotBlank(synonyms)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, SYNONYM_KEY, targetLocale), splitMultiValuedText(synonyms)); } }
@Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) if (!isCurrentLocaleTargeted()) { return; Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) {
/** * Check if the current context is set to a locale {@link #isLocaleSupported(Locale) supported} by this translation. * * @return {@code true} if the current locale is supported */ protected boolean isCurrentLocaleTargeted() { return isLocaleSupported(this.localizationContext.getCurrentLocale()); }
/** * Check if the specified locale is supported by this translation, specifically if the {@link #getTargetLocale() * targeted locale} is a superset of it. * * @param locale the locale to check * @return {@code true} if the specified locale is supported */ protected boolean isLocaleSupported(Locale locale) { return locale != null && locale.toLanguageTag().startsWith(getTargetLocale().toLanguageTag()); }
@Override public boolean isVocabularySupported(Vocabulary vocabulary) { return getTargetVocabularyId().equals(vocabulary.getIdentifier()); }
/** * Check if the {@link #getTargetLocale() locale targeted by this translation} is in the list of supported locales * by this instance. * * @return {@code true} if the current language is targeted, or if the instance is set as multilingual and the * targeted language is included in the list of supported locales, {@code false} otherwise */ protected boolean isTargetLocaleEnabled() { Locale currentLocale = this.localizationContext.getCurrentLocale(); if (isLocaleSupported(currentLocale)) { return true; } if (!this.config.getProperty("multilingual", Boolean.FALSE)) { return false; } Set<String> defaultValue = new HashSet<>(); defaultValue.add(currentLocale.getLanguage()); Set<String> enabledLanguages = this.config.getProperty("languages", defaultValue); for (String lang : enabledLanguages) { if (StringUtils.isBlank(lang)) { continue; } String trimmed = lang.trim(); if (isLocaleSupported(Locale.forLanguageTag(trimmed))) { return true; } } return false; }