basic translation support

This commit is contained in:
noah the goodra 2017-04-06 18:35:01 -05:00
parent 26979cd6ef
commit 4218703d55
5 changed files with 1715 additions and 3 deletions

View File

@ -80,8 +80,21 @@ set(UIS
hotkeys.ui
main.ui
)
set(LANGS
translation/language_en.ts
)
find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT})
create_directory_groups(${SRCS} ${HEADERS} ${UIS})
# Some packages might be in the system include path, qt5_create_translation is poorly written
# and will explicitly list all INCLUDE_DIRECTORIES for translation search which would take hours.
# To avoid this we first clear the list, and then restore it afterwards..
get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "")
qt5_create_translation(translations ${SRCS} ${HEADERS} ${UIS} ${LANGS})
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${_inc_DIRS}")
qt5_add_translation(TRANSLATIONS ${LANGS})
create_directory_groups(${SRCS} ${HEADERS} ${UIS} ${LANGS})
if (Qt5_FOUND)
qt5_wrap_ui(UI_HDRS ${UIS})
@ -90,12 +103,13 @@ else()
endif()
if (APPLE)
SET_SOURCE_FILES_PROPERTIES("${TRANSLATIONS}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/languages)
set(MACOSX_ICON "../../dist/citra.icns")
set_source_files_properties(${MACOSX_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(citra-qt MACOSX_BUNDLE ${SRCS} ${HEADERS} ${UI_HDRS} ${MACOSX_ICON})
add_executable(citra-qt MACOSX_BUNDLE ${SRCS} ${HEADERS} ${UI_HDRS} ${TRANSLATIONS} ${MACOSX_ICON})
set_target_properties(citra-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
else()
add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS})
add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS} ${TRANSLATIONS})
endif()
target_link_libraries(citra-qt core video_core audio_core common input_common)
target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS})

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QDir>
#include <QLocale>
#include "citra_qt/configuration/configure_general.h"
#include "citra_qt/ui_settings.h"
#include "core/core.h"
@ -15,6 +17,21 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent)
this->setConfiguration();
ui->toggle_cpu_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn());
// locale stuff
QString m_langPath = QApplication::applicationDirPath();
m_langPath.append("/languages");
QDir dir(m_langPath);
QStringList fileNames = dir.entryList(QStringList("*.qm"));
for (int i = 0; i < fileNames.size(); ++i) {
// get locale extracted by filename
QString locale;
locale = fileNames[i]; // "de.qm"
locale.truncate(locale.lastIndexOf('.')); // "de"
QString lang = locale.right(2);
ui->language_combobox->addItem(lang, locale);
}
}
ConfigureGeneral::~ConfigureGeneral() {}
@ -29,6 +46,10 @@ void ConfigureGeneral::setConfiguration() {
}
void ConfigureGeneral::applyConfiguration() {
QString m_langPath = QApplication::applicationDirPath() + "/languages/" +
ui->language_combobox->currentData().toString() + ".qm";
translator.load(m_langPath);
UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked();
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
Settings::values.region_value = ui->region_combobox->currentIndex() - 1;

View File

@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <QTranslator>
#include <QWidget>
namespace Ui {
@ -25,4 +26,5 @@ private:
private:
std::unique_ptr<Ui::ConfigureGeneral> ui;
QTranslator translator;
};

View File

@ -24,6 +24,21 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label2">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="language_combobox">
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="toggle_deepscan">
<property name="text">

File diff suppressed because it is too large Load Diff