Use systems preferred language on Mac.

And ensure that the menu items don't vanish from the application menu
when they are translated.
This commit is contained in:
con
2009-09-11 14:37:17 +02:00
parent 8213e5bda7
commit 1a0134a9de
3 changed files with 45 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ win32 {
} else:macx {
CONFIG(debug, debug|release):LIBS *= -lExtensionSystem_debug -lAggregation_debug
else:LIBS *= -lExtensionSystem -lAggregation
LIBS += -framework CoreFoundation
ICON = qtcreator.icns
QMAKE_INFO_PLIST = Info.plist
FILETYPES.files = profile.icns prifile.icns

View File

@@ -48,6 +48,20 @@
#ifdef Q_OS_MAC
# include <sys/resource.h>
# include <CoreFoundation/CoreFoundation.h>
// Helper function CoreFoundation -> Qt
static QString stringFromCFString(CFStringRef value) {
QString retVal;
CFIndex maxLength = 2 * CFStringGetLength(value) + 1/*zero term*/; // max UTF8
char *cstring = new char[maxLength];
if (CFStringGetCString(CFStringRef(value), cstring, maxLength, kCFStringEncodingUTF8)) {
retVal = QString::fromUtf8(cstring);
}
delete cstring;
return retVal;
}
#endif
enum { OptionIndent = 4, DescriptionIndent = 24 };
@@ -216,7 +230,29 @@ int main(int argc, char **argv)
QTranslator translator;
QTranslator qtTranslator;
const QString &locale = QLocale::system().name();
QString locale = QLocale::system().name();
#ifdef Q_OS_MAC
// because QLocale's system locale is basically useless on the Mac.
// Try to get the real system setting via core foundation
CFLocaleRef maclocale = CFLocaleCopyCurrent();
CFTypeRef value = CFLocaleGetValue(maclocale, kCFLocaleLanguageCode);
QString preferredLanguage = stringFromCFString(CFStringRef(value));
if (!preferredLanguage.isEmpty())
locale = preferredLanguage;
CFRelease(maclocale);
CFArrayRef languages = (CFArrayRef)CFPreferencesCopyValue(
CFSTR("AppleLanguages"),
kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
// CFShow(languages);
if (CFArrayGetCount(languages) > 0) {
QString preferredLanguage = stringFromCFString(CFStringRef(CFArrayGetValueAtIndex(languages, 0)));
if (!preferredLanguage.isEmpty())
locale = preferredLanguage;
}
CFRelease(languages);
#endif
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
+ QLatin1String(SHARE_PATH "/translations");
if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) {

View File

@@ -678,6 +678,7 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(m_optionsAction, Constants::OPTIONS, m_globalContext);
#ifdef Q_WS_MAC
cmd->setDefaultKeySequence(QKeySequence("Ctrl+,"));
cmd->action()->setMenuRole(QAction::PreferencesRole);
#endif
mtools->addAction(cmd, Constants::G_DEFAULT_THREE);
connect(m_optionsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
@@ -735,7 +736,11 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(tmpaction, Constants::ABOUT_QTCREATOR, m_globalContext);
mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
tmpaction->setEnabled(true);
#ifdef Q_WS_MAC
cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
#endif
connect(tmpaction, SIGNAL(triggered()), this, SLOT(aboutQtCreator()));
//About Plugins Action
tmpaction = new QAction(tr("About &Plugins..."), this);
cmd = am->registerAction(tmpaction, Constants::ABOUT_PLUGINS, m_globalContext);