public static String en(final Optional<LocalizedStrings> localizedStringsOption) { return localizedStringsOption.get().get(ENGLISH).get(); }
/** * Creates a LocalizedStrings for the {@code Locale.ENGLISH}. * @param value the value of the english translation * @return localized string with value */ public static LocalizedStrings en(final String value) { return LocalizedStrings.of(Locale.ENGLISH, value); }
@JsonIgnore public static LocalizedStrings of(final Map<Locale, String> translations) { requireNonNull(translations); return new LocalizedStrings(translations); }
private static Map<LocaleSlugPair, Category> buildBySlugMap(final Collection<Category> categories) { final Map<LocaleSlugPair, Category> map = new HashMap<>(); for (final Category category : categories) { for (final Locale locale : category.getSlug().getLocales()) { map.put(new LocaleSlugPair(locale, category.getSlug().get(locale).get()), category); } } return map; }
public static AttributeAccess<LocalizedStrings> ofLocalizedStrings() { return ofPrimitive(LocalizedStrings.typeReference(), LocalizedStringsType.class); }
private static Map<LocaleSlugPair, Category> buildBySlugMap(final Collection<Category> categories) { final Map<LocaleSlugPair, Category> map = new HashMap<>(); for (final Category category : categories) { for (final Locale locale : category.getSlug().getLocales()) { map.put(new LocaleSlugPair(locale, category.getSlug().get(locale).get()), category); } } return map; }
public static AttributeAccess<LocalizedStrings> ofLocalizedStrings() { return ofPrimitive(LocalizedStrings.typeReference(), LocalizedTextAttributeDefinition.class); }
public Optional<String> get(final Iterable<Locale> locales) { final Optional<Locale> firstFoundLocale = toStream(locales).filter(locale -> translations.containsKey(locale)).findFirst(); return firstFoundLocale.flatMap(foundLocale -> get(foundLocale)); }
/** * Creates an instance without any value. * * @return instance without any value */ public static LocalizedStrings empty() { return of(); }
@JsonIgnore public static LocalizedStrings of(final Locale locale, final String value) { requireNonNull(locale); requireNonNull(value); return new LocalizedStrings(locale, value); }
public static String englishSlugOf(final WithLocalizedSlug model) { return model.getSlug().get(ENGLISH).get(); }
@JsonIgnore public static LocalizedStrings ofEnglishLocale(final String value) { return of(Locale.ENGLISH, value); }
@JsonIgnore public static LocalizedStrings of(final Locale locale1, final String value1, final Locale locale2, final String value2) { return new LocalizedStrings(mapOf(locale1, value1, locale2, value2)); }
public LocalizedStringsAssert contains(final Locale locale, final String value) { if (!value.equals(actual.get(locale).orElse(null))) { failIfCustomMessageIsSet(); throw failure(String.format("%s does not contain an entry %s -> %s", actual, locale, value)); } return this; }
/** * Creates an instance without any value. * * @return instance without any value */ @JsonIgnore public static LocalizedStrings of() { return of(new HashMap<>()); }
/** * LocalizedStrings containing the given entries. * @param locale the additional locale of the new entry * @param value the value for the <code>locale</code> * @return a LocalizedStrings containing this data and the from the parameters. * @throws IllegalArgumentException if duplicate locales are provided */ public LocalizedStrings plus(final Locale locale, final String value) { if (translations.containsKey(locale)) { throw new IllegalArgumentException(format("Duplicate keys (%s) for map creation.", locale)); } final Map<Locale, String> newMap = ImmutableMapBuilder.<Locale, String>of(). putAll(translations). put(locale, value). build(); return new LocalizedStrings(newMap); }
public LocalizedStringsAssert doesNotContain(final Locale locale, final String value) { if (value.equals(actual.get(locale).orElse(null))) { failIfCustomMessageIsSet(); throw failure(String.format("%s does contain an entry %s -> %s", actual, locale, value)); } return this; } }
public static LocalizedStrings randomSlug() { return LocalizedStrings.of(Locale.ENGLISH, randomKey()); }
public static MetaAttributes metaAttributesOf(final Locale locale, final String metaTitle, final String metaDescription, final String metaKeywords) { return MetaAttributesDsl.of() .withTitle(LocalizedStrings.of(locale, metaTitle)) .withDescription(LocalizedStrings.of(locale, metaDescription)) .withKeywords(LocalizedStrings.of(locale, metaKeywords)); } }