commercetools / commercetools-sdk-java-v2

The e-commerce SDK from commercetools for Java.
https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/index.html
Apache License 2.0
34 stars 15 forks source link

LocalizedString.localValues() returns wrong Locale if key is not plain languageTag #482

Closed th1nkgr33n closed 1 year ago

th1nkgr33n commented 1 year ago

Describe the bug The Method LocalizedString.localValues() returns wrong locale as MapKey if the source values contains not only plain languageTags but combined tag+country as well. This method works well if you have configured only "2-digit" languages inside the Commercetools UI, but apparently its possible to configure "4-digit+Hypen" languages as well (see screenshots).

To Reproduce

  1. Configure localizedLanguages in Commercetools (e.g. "de-DE" and "de-AT")
  2. Create any Kind of ProductType to call it later via API
  3. call a ProductTypeDraft via API with SDK
  4. Try to access the translations of label of an ProductTypeDraft Attribute via SDK
  5. The Locale has not the correct language and country split, instead it has "de-de" als language (see screenshots)

Expected behavior The method should return a proper Map of Locales + values where language and country of the locale are separated.

Screenshots/Code snippet

  1. Configuration of languages inside Commercetools image

  2. Adapt a ProductType to call it later image

  3. Actual value of the LocalizedString Bildschirmfoto 2023-09-07 um 12 04 34

  4. Outcome of the localValues() Method Bildschirmfoto 2023-09-07 um 12 06 10

Stack information (please complete the following information):

Additional context

https://github.com/commercetools/commercetools-sdk-java-v2/blame/4c51dff63e55e906f9e0bb42ba78293df0d4dddb/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedString.java#L75

jenschude commented 1 year ago

Uh nice catch. This method was ported from the v1 SDK where it already has this faulty behavior. Fixed it to resolve the correct locale now.

Will soon to a release.

jenschude commented 1 year ago

Fixed with 16.2.0