Xcode 7 UITests with localized UI

后端 未结 11 955
既然无缘
既然无缘 2020-12-07 17:38

In my App I\'m using NSLocalizedString to localize my app. Now I want to switch to UITests and habe Testcode like this:

[tabBarsQue         


        
11条回答
  •  感动是毒
    2020-12-07 18:03

    The answer of Volodymyr helped me a lot, but it can fail if the localization bundle folder name differs from the deviceLanguage set in Snapshot. This snippet works fine for me in Swift 3.0 and with languages like italian (where current locale is "it" but device language is "it-IT").

        func localizedString(key:String) -> String {
          let languageBundlePath = Bundle(for: PlinthUITests.self).path(forResource: deviceLanguage, ofType: "lproj") ?? Bundle(for: PlinthUITests.self).path(forResource: NSLocale.current.languageCode!, ofType: "lproj")
          let localizationBundle = Bundle(path: languageBundlePath!)
          let result = NSLocalizedString(key, bundle:localizationBundle!, comment: "")
        return result
    }
    

提交回复
热议问题