Move Mac translations to .cpp file for lupdate to pick them up.

Task-number: QTBUG-30125

Change-Id: I4e56fd3021b4ef5f344d4d36ae594dd88e2aa1bd
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
Friedemann Kleint 2013-04-22 15:14:03 +02:00 committed by The Qt Project
parent ecc11ccd65
commit ad3b61554b
5 changed files with 170 additions and 39 deletions

View File

@ -41,6 +41,8 @@ OBJECTIVE_SOURCES += main.mm \
qcocoaintrospection.mm \
qcocoakeymapper.mm \
SOURCES += messages.cpp
HEADERS += qcocoaintegration.h \
qcocoatheme.h \
qcocoabackingstore.h \
@ -75,6 +77,7 @@ HEADERS += qcocoaintegration.h \
qcocoasystemtrayicon.h \
qcocoaintrospection.h \
qcocoakeymapper.h \
messages.h
RESOURCES += qcocoaresources.qrc

View File

@ -0,0 +1,96 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "messages.h"
#include <QCoreApplication>
// Translatable messages should go into this .cpp file for them to be picked up by lupdate.
QT_BEGIN_NAMESPACE
QString msgAboutQt()
{
return QCoreApplication::translate("QCocoaMenuItem", "About Qt");
}
static const char *application_menu_strings[] =
{
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1")
};
QString qt_mac_applicationmenu_string(int type)
{
QString menuString = QString::fromLatin1(application_menu_strings[type]);
const QString translated = QCoreApplication::translate("QMenuBar", application_menu_strings[type]);
if (translated != menuString) {
return translated;
} else {
return QCoreApplication::translate("MAC_APPLICATION_MENU", application_menu_strings[type]);
}
}
QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption)
{
const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About");
if (caption.startsWith(aboutString, Qt::CaseInsensitive) || caption.endsWith(aboutString, Qt::CaseInsensitive))
return QPlatformMenuItem::AboutRole;
if (caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Config"), Qt::CaseInsensitive)
|| caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Preference"), Qt::CaseInsensitive)
|| caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Options"), Qt::CaseInsensitive)
|| caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setting"), Qt::CaseInsensitive)
|| caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setup"), Qt::CaseInsensitive)) {
return QPlatformMenuItem::PreferencesRole;
}
if (caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Quit"), Qt::CaseInsensitive)
|| caption.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Exit"), Qt::CaseInsensitive)) {
return QPlatformMenuItem::QuitRole;
}
return QPlatformMenuItem::NoRole;
}
QT_END_NAMESPACE

View File

@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MESSAGES_H
#define MESSAGES_H
#include <QString>
#include <qpa/qplatformmenu.h>
QT_BEGIN_NAMESPACE
QString msgAboutQt();
QString qt_mac_applicationmenu_string(int type);
QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption);
QT_END_NAMESPACE
#endif // MESSAGES_H

View File

@ -42,6 +42,7 @@
#include "qcocoamenuitem.h"
#include "qcocoamenu.h"
#include "messages.h"
#include "qcocoahelpers.h"
#include "qcocoaautoreleasepool.h"
#include "qt_mac_p.h"
@ -209,28 +210,24 @@ NSMenuItem *QCocoaMenuItem::sync()
case PreferencesRole:
mergeItem = [loader preferencesMenuItem];
break;
case TextHeuristicRole: {
QString aboutString = tr("About").toLower();
if (m_text.startsWith(aboutString, Qt::CaseInsensitive)
|| m_text.endsWith(aboutString, Qt::CaseInsensitive))
{
case TextHeuristicRole:
switch (detectMenuRole(m_text)) {
case QPlatformMenuItem::AboutRole:
if (m_text.indexOf(QRegExp(QString::fromLatin1("qt$"), Qt::CaseInsensitive)) == -1)
mergeItem = [loader aboutMenuItem];
else
mergeItem = [loader aboutQtMenuItem];
} else if (m_text.startsWith(tr("Config"), Qt::CaseInsensitive)
|| m_text.startsWith(tr("Preference"), Qt::CaseInsensitive)
|| m_text.startsWith(tr("Options"), Qt::CaseInsensitive)
|| m_text.startsWith(tr("Setting"), Qt::CaseInsensitive)
|| m_text.startsWith(tr("Setup"), Qt::CaseInsensitive)) {
break;
case QPlatformMenuItem::PreferencesRole:
mergeItem = [loader preferencesMenuItem];
} else if (m_text.startsWith(tr("Quit"), Qt::CaseInsensitive)
|| m_text.startsWith(tr("Exit"), Qt::CaseInsensitive)) {
break;
case QPlatformMenuItem::QuitRole:
mergeItem = [loader quitMenuItem];
break;
default:
break;
}
break;
}
default:
qWarning() << Q_FUNC_INFO << "unsupported role" << (int) m_role;
@ -323,7 +320,7 @@ QString QCocoaMenuItem::mergeText()
return qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName());
} else if (m_native== [loader aboutQtMenuItem]) {
if (m_text == QString("About Qt"))
return tr("About Qt");
return msgAboutQt();
else
return m_text;
} else if (m_native == [loader preferencesMenuItem]) {

View File

@ -41,6 +41,7 @@
#include "qcocoamenuloader.h"
#include "messages.h"
#include "qcocoahelpers.h"
#include "qcocoamenubar.h"
#include "qcocoamenuitem.h"
@ -57,30 +58,6 @@ QT_FORWARD_DECLARE_CLASS(QString)
QT_BEGIN_NAMESPACE
#ifndef QT_NO_TRANSLATION
static const char *application_menu_strings[] = {
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1"),
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1")
};
QString qt_mac_applicationmenu_string(int type)
{
QString menuString = QString::fromLatin1(application_menu_strings[type]);
QString translated = qApp->translate("QMenuBar", application_menu_strings[type]);
if (translated != menuString) {
return translated;
} else {
return qApp->translate("MAC_APPLICATION_MENU",
application_menu_strings[type]);
}
}
#endif
/*
Loads and instantiates the main app menu from the menu nib file(s).