How to identify Application language preference programatically

In the mac general setting, we can provide the language preference for an individual application like in the image below, I have provided for TextEdit app.

Now based on the system preferred languages, TextEdit will have a default language. However if I explicitly set the language for TextEdit (arabic in my example), then the application will use that language. I wanted to identify in my program the language that an app is currently running in. I have tried the below code, but it always return 'en', even after my preference is set to 'Arabic'.

    let u = URL(fileURLWithPath: "/System/Applications/TextEdit.app")
    let b = Bundle(url: u)!
    let textedit_preference = b.preferredLocalizations
    print(textedit_preference)  //["en"]

How can I identify what language is being set by the user for an individual application? I have followed this link but it does not contain this information.

So, just to be clear:

  • You’re not asking about the setting for your app.

  • Rather, you want to get the setting for some other arbitrary app on the system.

Is that right?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Have you tried checking Locale.current?
You can read the language & region settings for your current app with Locale.
https://developer.apple.com/documentation/foundation/locale

Actually I want to know about the language setting for my app that the user has currently configured

Oh, cool, that makes things easier. See tomn94’s answer for locale info and the various language properties on NSBundle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to identify Application language preference programatically
 
 
Q