iosswiftrequest

Multilanguage bug


I have faced very strange bug in my application where I show list of news from remote server.

I have two languages - English as main, and Russian as supplementary. My server has two JSON files, for eng and ru localisations. When requesting for data from server I do language check like this:

let preferredLanguage = NSLocale.preferredLanguages[0]
    
    if preferredLanguage == "uk" || preferredLanguage == "ru" {
        requestLink = RequestLinks.secondDateProgram.rawValue
    } else {
        requestLink = RequestLinksEng.secondDateProgram.rawValue
    }

And this all system works fine, correct link being generated and request shows correct data, all works fine but ONLY on my iPhone 7. When I install and launch exactly the same app version (from TestFlight or Diawi) on any other device my list of news in Russian version of app for some reason has first item from English JSON file, but when I switch phone to English - everything works fine.

I don't have any cache, and I don't store any news to Realm. I do manual cache cleaning before each request and still the same - on my iPhone it works fine, on other nope (tested on iPhone 7 plus, and 11).

If anyone had same issue before - would be grateful for any help.


Solution

  • My problem was here - let preferredLanguage = NSLocale.preferredLanguages[0] This detects Application language, but not iPhone's, that's why I got english instead of russian.

    Changing it to NSLocale.current.languageCode did the trick.