Skip to content

Commit

Permalink
Merge pull request #5798 from ligfx/qttranslation
Browse files Browse the repository at this point in the history
Qt: use translations
  • Loading branch information
lioncash committed Sep 15, 2017
2 parents 030dc11 + 60cba57 commit 5576af0
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 9 deletions.
34 changes: 34 additions & 0 deletions Source/Core/DolphinQt2/CMakeLists.txt
Expand Up @@ -28,6 +28,7 @@ set(SRCS
Resources.cpp
Settings.cpp
ToolBar.cpp
Translation.cpp
WiiUpdate.cpp
WiiUpdate.h
Config/ControllersWindow.cpp
Expand Down Expand Up @@ -99,6 +100,39 @@ set(DOLPHINQT2_BINARY dolphin-emu-qt2)
add_executable(${DOLPHINQT2_BINARY} ${SRCS} ${UI_HEADERS})
target_link_libraries(${DOLPHINQT2_BINARY} ${LIBS} Qt5::Widgets)

# Handle localization
find_package(Gettext)
if(GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
set(pot_file "${CMAKE_SOURCE_DIR}/Languages/po/dolphin-emu.pot")
file(GLOB LINGUAS ${CMAKE_SOURCE_DIR}/Languages/po/*.po)

target_sources(dolphin-emu-qt2 PRIVATE ${pot_file} ${LINGUAS})
source_group("Localization" FILES ${LINGUAS})
source_group("Localization\\\\Generated" FILES ${pot_file})

foreach(po ${LINGUAS})
get_filename_component(lang ${po} NAME_WE)
set(mo_dir ${CMAKE_CURRENT_BINARY_DIR}/${lang})
set(mo ${mo_dir}/dolphin-emu.mo)

target_sources(dolphin-emu-qt2 PRIVATE ${mo})
source_group("Localization\\\\Generated" FILES ${mo})

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_source_files_properties(${mo} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${lang}.lproj")
else()
install(FILES ${mo} DESTINATION share/locale/${lang}/LC_MESSAGES)
endif()

add_custom_command(OUTPUT ${mo}
COMMAND mkdir -p ${mo_dir}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${po} ${pot_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo} ${po}
DEPENDS ${po}
)
endforeach()
endif()

if(APPLE)
# Note: This is copied from DolphinQt, based on the DolphinWX version.

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt2/DolphinQt2.vcxproj
Expand Up @@ -218,6 +218,7 @@
<ClCompile Include="Settings\InterfacePane.cpp" />
<ClCompile Include="Settings\PathPane.cpp" />
<ClCompile Include="ToolBar.cpp" />
<ClCompile Include="Translation.cpp" />
<ClCompile Include="WiiUpdate.cpp" />
</ItemGroup>
<!--Put standard C/C++ headers here-->
Expand All @@ -243,6 +244,7 @@
<ClInclude Include="QtUtils\ListTabWidget.h" />
<ClInclude Include="Resources.h" />
<ClInclude Include="Settings\PathPane.h" />
<ClInclude Include="Translation.h" />
<ClInclude Include="WiiUpdate.h" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DolphinQt2/Main.cpp
Expand Up @@ -18,6 +18,7 @@
#include "DolphinQt2/QtUtils/RunOnObject.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Translation.h"
#include "UICommon/CommandLineParse.h"
#include "UICommon/UICommon.h"

Expand Down Expand Up @@ -75,6 +76,9 @@ int main(int argc, char* argv[])
// Hook up alerts from core
RegisterMsgAlertHandler(QtMsgAlertHandler);

// Hook up translations
Translation::Initialize();

// Whenever the event loop is about to go to sleep, dispatch the jobs
// queued in the Core first.
QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,
Expand Down
70 changes: 65 additions & 5 deletions Source/Core/DolphinQt2/Settings/InterfacePane.cpp
Expand Up @@ -8,6 +8,7 @@
#include <QComboBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QWidget>

Expand All @@ -19,6 +20,56 @@

#include "DolphinQt2/Settings.h"

static QComboBox* MakeLanguageComboBox()
{
static const struct
{
const QString name;
const char* id;
} languages[] = {
{QStringLiteral("Bahasa Melayu"), "ms"}, // Malay
{QStringLiteral("Catal\u00E0"), "ca"}, // Catalan
{QStringLiteral("\u010Ce\u0161tina"), "cs"}, // Czech
{QStringLiteral("Dansk"), "da"}, // Danish
{QStringLiteral("Deutsch"), "de"}, // German
{QStringLiteral("English"), "en"}, // English
{QStringLiteral("Espa\u00F1ol"), "es"}, // Spanish
{QStringLiteral("Fran\u00E7ais"), "fr"}, // French
{QStringLiteral("Hrvatski"), "hr"}, // Croatian
{QStringLiteral("Italiano"), "it"}, // Italian
{QStringLiteral("Magyar"), "hu"}, // Hungarian
{QStringLiteral("Nederlands"), "nl"}, // Dutch
{QStringLiteral("Norsk bokm\u00E5l"), "nb"}, // Norwegian
{QStringLiteral("Polski"), "pl"}, // Polish
{QStringLiteral("Portugu\u00EAs"), "pt"}, // Portuguese
{QStringLiteral("Portugu\u00EAs (Brasil)"), "pt_BR"}, // Portuguese (Brazil)
{QStringLiteral("Rom\u00E2n\u0103"), "ro"}, // Romanian
{QStringLiteral("Srpski"), "sr"}, // Serbian
{QStringLiteral("Svenska"), "sv"}, // Swedish
{QStringLiteral("T\u00FCrk\u00E7e"), "tr"}, // Turkish
{QStringLiteral("\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"), "el"}, // Greek
{QStringLiteral("\u0420\u0443\u0441\u0441\u043A\u0438\u0439"), "ru"}, // Russian
{QStringLiteral("\u0627\u0644\u0639\u0631\u0628\u064A\u0629"), "ar"}, // Arabic
{QStringLiteral("\u0641\u0627\u0631\u0633\u06CC"), "fa"}, // Farsi
{QStringLiteral("\uD55C\uAD6D\uC5B4"), "ko"}, // Korean
{QStringLiteral("\u65E5\u672C\u8A9E"), "ja"}, // Japanese
{QStringLiteral("\u7B80\u4F53\u4E2D\u6587"), "zh_CN"}, // Simplified Chinese
{QStringLiteral("\u7E41\u9AD4\u4E2D\u6587"), "zh_TW"}, // Traditional Chinese
};

auto* combobox = new QComboBox();
combobox->addItem(QObject::tr("<System Language>"), QStringLiteral(""));
for (const auto& lang : languages)
combobox->addItem(lang.name, QString::fromLatin1(lang.id));

// The default, QComboBox::AdjustToContentsOnFirstShow, causes a noticeable pause when opening the
// SettingWindow for the first time. The culprit seems to be non-Latin graphemes in the above
// list. QComboBox::AdjustToContents still has some lag but it's much less noticeable.
combobox->setSizeAdjustPolicy(QComboBox::AdjustToContents);

return combobox;
}

InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent)
{
CreateLayout();
Expand Down Expand Up @@ -48,9 +99,7 @@ void InterfacePane::CreateUI()
auto* combobox_layout = new QFormLayout;
groupbox_layout->addLayout(combobox_layout);

m_combobox_language = new QComboBox;
// TODO: Support more languages other then English
m_combobox_language->addItem(tr("English"));
m_combobox_language = MakeLanguageComboBox();
combobox_layout->addRow(tr("&Language:"), m_combobox_language);

// Theme Combobox
Expand Down Expand Up @@ -111,8 +160,8 @@ void InterfacePane::ConnectLayout()
&InterfacePane::OnSaveConfig);
connect(m_combobox_theme, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
&Settings::Instance(), &Settings::SetThemeName);
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
[this](int index) { OnSaveConfig(); });
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
&InterfacePane::OnSaveConfig);
connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_use_panic_handlers, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
connect(m_checkbox_enable_osd, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
Expand All @@ -128,6 +177,8 @@ void InterfacePane::LoadConfig()
m_checkbox_top_window->setChecked(startup_params.bKeepWindowOnTop);
m_checkbox_render_to_window->setChecked(startup_params.bRenderToMain);
m_checkbox_use_builtin_title_database->setChecked(startup_params.m_use_builtin_title_database);
m_combobox_language->setCurrentIndex(m_combobox_language->findData(
QString::fromStdString(SConfig::GetInstance().m_InterfaceLanguage)));
m_combobox_theme->setCurrentIndex(
m_combobox_theme->findText(QString::fromStdString(SConfig::GetInstance().theme_name)));

Expand Down Expand Up @@ -155,5 +206,14 @@ void InterfacePane::OnSaveConfig()
settings.m_show_active_title = m_checkbox_show_active_title->isChecked();
settings.m_PauseOnFocusLost = m_checkbox_pause_on_focus_lost->isChecked();

auto new_language = m_combobox_language->currentData().toString().toStdString();
if (new_language != SConfig::GetInstance().m_InterfaceLanguage)
{
SConfig::GetInstance().m_InterfaceLanguage = new_language;
QMessageBox::information(
this, tr("Restart Required"),
tr("You must restart Dolphin in order for the change to take effect."));
}

settings.SaveSettings();
}

0 comments on commit 5576af0

Please sign in to comment.