Results 1 to 2 of 2

Thread: [SOLVED] Get system language on Mac OS X

  1. #1
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default [SOLVED] Get system language on Mac OS X

    Hi all,

    On Mac OS X, QLocale::system() refers to Region rather than Language.
    Is there a (Qt or other) way to access the Language from C++ code?
    Edit: I'm currently on Qt 5.2.

    Thx


    Added after 12 minutes:


    Supplement:
    I found this AppleScript approach which might help. However I'd prefer something more convenient... Qt-ish or at least C++-ish...
    Last edited by zaphod.b; 30th December 2013 at 16:50. Reason: mark as solved

  2. #2
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get system language on Mac OS X

    I'll solve myself:

    From the QSettings doc:
    On Mac OS X, allKeys() will return some extra keys for global settings that apply to all applications. These keys can be read using value() but cannot be changed, only shadowed. Calling setFallbacksEnabled(false) will hide these global settings.
    QSettings::allKeys() lists, among many others, "AppleLanguages" - which I have come across before, see above.

    So the solution is simple:
    Qt Code:
    1. QSettings settings; //no user specific settings needed
    2. QVariant osxLanguageSettings = settings.value("AppleLanguages"); //list of all languages (as opposed to regions) as set in the system preferences
    3. QStringList displayLanguages = osxLanguageSettings.toStringList(); //e.g. {"en", "de", "fr", "it"} on my system
    4. QString preferredLanguage = displayLanguages.first(); //first in list is the preferred one
    5. qDebug() << "preferred language is:" << preferredLanguage; //"en"
    6. //however...
    7. qDebug() << "system locale is:" << QLocale::system(); //e.g. "nb_NO" in case of 'Norwegian Bokmål' region/locale
    To copy to clipboard, switch view to plain text mode 
    You can iterate the list for a fallback.

    Hth.
    Last edited by zaphod.b; 30th December 2013 at 22:49.

Similar Threads

  1. Get file system language
    By matteo.ceruti in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2012, 09:40
  2. Replies: 8
    Last Post: 21st March 2011, 12:40
  3. 1.3.0 - UI Language
    By Asperamanca in forum Qt Tools
    Replies: 2
    Last Post: 16th December 2009, 11:19
  4. How modern is C++ language used in Qt's API?
    By piotr.dobrogost in forum Newbie
    Replies: 18
    Last Post: 31st May 2009, 03:44
  5. How can I add any other language
    By ethos0714 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 22nd February 2006, 02:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.