@Override protected String convertLocalizedString(final LocalizedString localizedString, final Attribute attribute, final ProductType productType) { return localizedString.getTranslation(getLocales()); }
@Override protected String convertLocalizedString(final LocalizedString localizedString, final Attribute attribute, final ProductType productType) { return localizedString.getTranslation(getLocales()); }
@Override protected String convertLocalizedString(final LocalizedString localizedString, final Attribute attribute, final ProductType productType) { return localizedString.getTranslation(getLocales()); }
@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
@Override protected String convertLocalizedEnumValue(final LocalizedEnumValue localizedEnumValue, final Attribute attribute, final ProductType productType) { return localizedEnumValue.getLabel().getTranslation(getLocales()); }
@Test public void defaultUseCases() { final LocalizedString ls = LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food"); assertThat(ls.getTranslation(singletonList(Locale.US))).isEqualTo("dog food");//fuzzy search assertThat(ls.getTranslation(singletonList(Locale.ENGLISH))).isEqualTo("dog food");//strict search assertThat(ls.getLocales()).isEqualTo(new HashSet<>(asList(Locale.GERMAN, Locale.ENGLISH)));//inspecting locales assertThat(ls.slugified())//slugified values for urls .isEqualTo(LocalizedString.of(Locale.GERMAN, "hundefutter", Locale.ENGLISH, "dog-food")); final LocalizedString slugifiedUnique = ls.slugifiedUnique(); assertThat(slugifiedUnique.get(Locale.GERMAN)).matches("hundefutter-\\d+");//example: hundefutter-62899407 assertThat(slugifiedUnique.get(Locale.ENGLISH)).matches("dog-food-\\d+"); }
.plus(Locale.US, "en_US"); assertThat(ls.getTranslation(asList(Locale.US, Locale.ENGLISH))).isEqualTo("en_US"); assertThat(ls.getTranslation(asList(Locale.ENGLISH, Locale.US))).isEqualTo("en"); assertThat(ls.getTranslation(asList(Locale.FRENCH, Locale.ENGLISH))).isEqualTo("en"); assertThat(ls.getTranslation(asList(Locale.UK, Locale.ENGLISH))).isEqualTo("en"); assertThat(ls.getTranslation(asList(Locale.GERMAN, Locale.UK))).isEqualTo("de"); assertThat(ls.getTranslation(asList(Locale.UK, Locale.GERMAN))) .overridingErrorMessage( "the plain language fallback wins also in the case after that comes a concrete match") .isEqualTo("en"); assertThat(ls.getTranslation(asList(Locale.FRENCH, Locale.UK, Locale.GERMAN))) .overridingErrorMessage("automatic fallback to plain English") .isEqualTo("en"); assertThat(LocalizedString.of(Locale.US, "en_US").getTranslation(asList(Locale.ENGLISH))) .overridingErrorMessage("no fallback to locale with country") .isNull(); assertThat(ls.getTranslation(asList(Locale.UK, Locale.US, Locale.GERMAN))) .isEqualTo(ls.get(asList(Locale.UK, Locale.ENGLISH, Locale.US, Locale.ENGLISH, Locale.GERMAN)));