Getting current device language in iOS?

前端 未结 30 2957
星月不相逢
星月不相逢 2020-11-22 09:10

I\'d like to show the current language that the device UI is using. What code would I use?

I want this as an NSString in fully spelled out format. (Not

30条回答
  •  青春惊慌失措
    2020-11-22 09:43

    iOS13, Swift 5+, WWDC2019 https://developer.apple.com/videos/play/wwdc2019/403/

    Users can select the preferred language of an app independently from the OS language.

    You can use these:

        // Returns a list of the user's preferred languages.
        // Maybe more than (or none of) your app supports!
        Locale.preferredLanguages
    
        // a subset of this bundle's localizations, re-ordered into the preferred order
        // for this process's current execution environment; the main bundle's preferred localizations
        // indicate the language (of text) the user is most likely seeing in the UI
        Bundle.main.preferredLocalizations
    
    
    
        // The current running app language
        Bundle.main.preferredLocalizations.first
    
        // list of language names this bundle appears to be localized to
        Bundle.main.localizations
    

提交回复
热议问题