saleor-dashboard icon indicating copy to clipboard operation
saleor-dashboard copied to clipboard

Language detection fails on Mac Safari

Open karer opened this issue 4 years ago • 3 comments

What I'm trying to achieve

When entering dashboard using Polish language, I want to see page in Polish. On Chrome it works, on Safari not (it displays English).

Steps to reproduce the problem

  1. Enter dashboard on Mac on Chrome
  2. Enter dashboard on Mac on Safari

What I expected to happen

Page should detect Polish on Safari.

Important information - I've debugged it and I know the reason. navigator.languages returns 'pl' on Chrome, but pl-pl on Safari. In src/components/Locale, we support only 'pl.

System information

Operating system:

  • [ ] Windows
  • [ ] Linux
  • [x ] MacOS
  • [ ] Other

Browser:

  • [x ] Safari
  • [x ] Chrome
  • [ ] Edge
  • [ ] Other

karer avatar Nov 06 '20 21:11 karer

@karer Hey! Thanks for reporting. Could you provide some screenshots? What's your version of Saleor?

karolkielecki avatar Nov 10 '20 13:11 karolkielecki

Zrzut ekranu 2020-11-12 o 13 06 33

I am using macOS 10.15.7 (latest), Safari 14.0 (latest), language of system and browser - Polish. Saleor using 2.11 (both API and Dashboard).

// Edit: After implementing hotfix by myself, it works. Be aware, that it could potentially use for example "en-US" when having browser as "en-GB", as it doesn't check by first part as the latest try.

saleor-dashboard/src/components/Locale/Locale.tsx

From:

for (const preferredLocale of languages) {
    for (const localeEntry of localeEntries) {
      if (
        localeEntry[1].toLowerCase() === preferredLocale.toLowerCase()
      ) {
        return Locale[localeEntry[0]];
      }
    }
  }

To:

for (const preferredLocale of languages) {
    for (const localeEntry of localeEntries) {
      if (
        localeEntry[1].toLowerCase() === preferredLocale.toLowerCase() ||
        localeEntry[1].toLowerCase() === preferredLocale.split("-")[0]?.toLowerCase()
      ) {
        return Locale[localeEntry[0]];
      }
    }
  }

karer avatar Nov 12 '20 12:11 karer

Issue reported: SALEOR-7292

michalina-graczyk avatar Jun 21 '22 09:06 michalina-graczyk