mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-22 04:11:16 -05:00
Add some polish to i18n
package Qt translations so that standard buttons etc. get l10n.
This commit is contained in:
parent
7104c4996e
commit
7425f13abc
@ -1045,6 +1045,7 @@ endif ()
|
|||||||
# stuff only qmake can tell us
|
# stuff only qmake can tell us
|
||||||
#
|
#
|
||||||
get_target_property (QMAKE_EXECUTABLE Qt5::qmake LOCATION)
|
get_target_property (QMAKE_EXECUTABLE Qt5::qmake LOCATION)
|
||||||
|
get_target_property (LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
|
||||||
function (QUERY_QMAKE VAR RESULT)
|
function (QUERY_QMAKE VAR RESULT)
|
||||||
exec_program (${QMAKE_EXECUTABLE} ARGS "-query ${VAR}" RETURN_VALUE return_code OUTPUT_VARIABLE output)
|
exec_program (${QMAKE_EXECUTABLE} ARGS "-query ${VAR}" RETURN_VALUE return_code OUTPUT_VARIABLE output)
|
||||||
if (NOT return_code)
|
if (NOT return_code)
|
||||||
@ -1055,6 +1056,7 @@ function (QUERY_QMAKE VAR RESULT)
|
|||||||
endfunction (QUERY_QMAKE)
|
endfunction (QUERY_QMAKE)
|
||||||
|
|
||||||
query_qmake (QT_INSTALL_PLUGINS QT_PLUGINS_DIR)
|
query_qmake (QT_INSTALL_PLUGINS QT_PLUGINS_DIR)
|
||||||
|
query_qmake (QT_INSTALL_TRANSLATIONS QT_TRANSLATIONS_DIR)
|
||||||
query_qmake (QT_INSTALL_IMPORTS QT_IMPORTS_DIR)
|
query_qmake (QT_INSTALL_IMPORTS QT_IMPORTS_DIR)
|
||||||
query_qmake (QT_HOST_DATA QT_DATA_DIR)
|
query_qmake (QT_HOST_DATA QT_DATA_DIR)
|
||||||
set (QT_MKSPECS_DIR ${QT_DATA_DIR}/mkspecs)
|
set (QT_MKSPECS_DIR ${QT_DATA_DIR}/mkspecs)
|
||||||
@ -1102,6 +1104,19 @@ set (LANGUAGES
|
|||||||
foreach (lang_ ${LANGUAGES})
|
foreach (lang_ ${LANGUAGES})
|
||||||
file (TO_NATIVE_PATH translations/wsjtx_${lang_}.ts ts_)
|
file (TO_NATIVE_PATH translations/wsjtx_${lang_}.ts ts_)
|
||||||
list (APPEND TS_FILES ${ts_})
|
list (APPEND TS_FILES ${ts_})
|
||||||
|
set (qt_translations_ "${QT_TRANSLATIONS_DIR}/qtbase_${lang_}.qm")
|
||||||
|
if (NOT EXISTS "${qt_translations_}")
|
||||||
|
string (REGEX REPLACE "([a-z][a-z])_[A-Z][A-Z]" "\\1" lang_ ${lang_})
|
||||||
|
set (qt_translations_ "${QT_TRANSLATIONS_DIR}/qtbase_${lang_}.qm")
|
||||||
|
endif ()
|
||||||
|
if (EXISTS "${qt_translations_}")
|
||||||
|
add_custom_command (
|
||||||
|
OUTPUT "${CMAKE_BINARY_DIR}/qt_${lang_}.qm"
|
||||||
|
COMMAND ${LCONVERT_EXECUTABLE} -o "${CMAKE_BINARY_DIR}/qt_${lang_}.qm" ${qt_translations_}
|
||||||
|
COMMENT "Building required Qt translations for language ${lang_}"
|
||||||
|
)
|
||||||
|
list (APPEND QM_FILES "${CMAKE_BINARY_DIR}/qt_${lang_}.qm")
|
||||||
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
if (UPDATE_TRANSLATIONS)
|
if (UPDATE_TRANSLATIONS)
|
||||||
message (STATUS "UPDATE_TRANSLATIONS option is set.")
|
message (STATUS "UPDATE_TRANSLATIONS option is set.")
|
||||||
@ -1712,7 +1727,7 @@ if (NOT is_debug_build)
|
|||||||
# PATTERN "*quick*${CMAKE_SHARED_LIBRARY_SUFFIX}" EXCLUDE
|
# PATTERN "*quick*${CMAKE_SHARED_LIBRARY_SUFFIX}" EXCLUDE
|
||||||
# )
|
# )
|
||||||
|
|
||||||
# add plugins path for WIN32
|
# add paths for WIN32
|
||||||
file (RELATIVE_PATH _plugins_path "${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION}" "${CMAKE_INSTALL_PREFIX}/${WSJT_PLUGIN_DESTINATION}")
|
file (RELATIVE_PATH _plugins_path "${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION}" "${CMAKE_INSTALL_PREFIX}/${WSJT_PLUGIN_DESTINATION}")
|
||||||
install (CODE "
|
install (CODE "
|
||||||
get_filename_component (the_qt_conf \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION}/qt.conf\" REALPATH)
|
get_filename_component (the_qt_conf \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION}/qt.conf\" REALPATH)
|
||||||
|
54
main.cpp
54
main.cpp
@ -18,6 +18,7 @@
|
|||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QLockFile>
|
#include <QLockFile>
|
||||||
@ -116,6 +117,15 @@ int main(int argc, char *argv[])
|
|||||||
.arg (QLocale::scriptToString (locale.script ()))
|
.arg (QLocale::scriptToString (locale.script ()))
|
||||||
.arg (QLocale::countryToString (locale.country ()))
|
.arg (QLocale::countryToString (locale.country ()))
|
||||||
.arg (locale.uiLanguages ().join (", "));
|
.arg (locale.uiLanguages ().join (", "));
|
||||||
|
// qDebug () << "+++++++++++++++++++++++++++ Resources ++++++++++++++++++++++++++++";
|
||||||
|
// {
|
||||||
|
// QDirIterator resources_iter {":/", QDirIterator::Subdirectories};
|
||||||
|
// while (resources_iter.hasNext ())
|
||||||
|
// {
|
||||||
|
// qDebug () << resources_iter.next ();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// qDebug () << "--------------------------- Resources ----------------------------";
|
||||||
setlocale (LC_NUMERIC, "C"); // ensure number forms are in
|
setlocale (LC_NUMERIC, "C"); // ensure number forms are in
|
||||||
// consistent format, do this after
|
// consistent format, do this after
|
||||||
// instantiating QApplication so
|
// instantiating QApplication so
|
||||||
@ -128,8 +138,14 @@ int main(int argc, char *argv[])
|
|||||||
//
|
//
|
||||||
// Enable base i18n
|
// Enable base i18n
|
||||||
//
|
//
|
||||||
QTranslator translator_from_resources;
|
QString translations_dir {":/Translations"};
|
||||||
QTranslator base_translator_from_resources;
|
QTranslator qt_translator;
|
||||||
|
if (qt_translator.load (locale, "qt", "_", translations_dir))
|
||||||
|
{
|
||||||
|
*early_messages << "Loaded Qt translations for current locale from resources";
|
||||||
|
a.installTranslator (&qt_translator);
|
||||||
|
}
|
||||||
|
|
||||||
// Default translations for releases use translations stored in
|
// Default translations for releases use translations stored in
|
||||||
// the resources file system under the Translations
|
// the resources file system under the Translations
|
||||||
// directory. These are built by the CMake build system from .ts
|
// directory. These are built by the CMake build system from .ts
|
||||||
@ -142,15 +158,18 @@ int main(int argc, char *argv[])
|
|||||||
// source control for translators to access and update.
|
// source control for translators to access and update.
|
||||||
|
|
||||||
// try and load the base translation
|
// try and load the base translation
|
||||||
|
QTranslator base_translator_from_resources;
|
||||||
for (QString locale_name : locale.uiLanguages ())
|
for (QString locale_name : locale.uiLanguages ())
|
||||||
{
|
{
|
||||||
auto language = locale_name.left (2);
|
auto language = locale_name.left (2);
|
||||||
if (locale.uiLanguages ().front ().left (2) == language)
|
if (locale.uiLanguages ().front ().left (2) == language)
|
||||||
{
|
{
|
||||||
*early_messages << QString {"Trying %1"}.arg (language);
|
*early_messages << QString {"Trying %1"}.arg (language);
|
||||||
if (base_translator_from_resources.load ("wsjtx_" + language, ":/Translations"))
|
if (base_translator_from_resources.load ("wsjtx_" + language, translations_dir))
|
||||||
{
|
{
|
||||||
*early_messages << QString {"Loaded base translation file from :/Translations based on language %1"}.arg (language);
|
*early_messages << QString {"Loaded base translation file from %1 based on language %2"}
|
||||||
|
.arg (translations_dir)
|
||||||
|
.arg (language);
|
||||||
a.installTranslator (&base_translator_from_resources);
|
a.installTranslator (&base_translator_from_resources);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -158,7 +177,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
// now try and load the most specific translations (may be a
|
// now try and load the most specific translations (may be a
|
||||||
// duplicate but we shouldn't care)
|
// duplicate but we shouldn't care)
|
||||||
if (translator_from_resources.load (locale, "wsjtx", "_", ":/Translations"))
|
QTranslator translator_from_resources;
|
||||||
|
if (translator_from_resources.load (locale, "wsjtx", "_", translations_dir))
|
||||||
{
|
{
|
||||||
*early_messages << "Loaded translations for current locale from resources";
|
*early_messages << "Loaded translations for current locale from resources";
|
||||||
a.installTranslator (&translator_from_resources);
|
a.installTranslator (&translator_from_resources);
|
||||||
@ -214,35 +234,37 @@ int main(int argc, char *argv[])
|
|||||||
// Complete i18n
|
// Complete i18n
|
||||||
//
|
//
|
||||||
|
|
||||||
QTranslator translation_override_from_resources;
|
|
||||||
QTranslator base_translation_override_from_resources;
|
|
||||||
// Load any matching translation from the current directory
|
// Load any matching translation from the current directory
|
||||||
// using the command line option language override. This allows
|
// using the command line option language override. This allows
|
||||||
// translators to easily test their translations by releasing
|
// translators to easily test their translations by releasing
|
||||||
// (lrelease) a .qm file into the current directory with a
|
// (lrelease) a .qm file into the current directory with a
|
||||||
// suitable name (e.g. wsjtx_en_GB.qm), then running wsjtx to
|
// suitable name (e.g. wsjtx_en_GB.qm), then running wsjtx to
|
||||||
// view the results.
|
// view the results.
|
||||||
|
QTranslator base_translation_override_from_resources;
|
||||||
|
QTranslator translation_override_from_resources;
|
||||||
if (parser.isSet (lang_option))
|
if (parser.isSet (lang_option))
|
||||||
{
|
{
|
||||||
auto language = parser.value (lang_option).replace ('-', '_');
|
auto language = parser.value (lang_option).replace ('-', '_');
|
||||||
// try and load the base translation
|
// try and load the base translation
|
||||||
auto base_language = language.left (2);
|
auto base_language = language.left (2);
|
||||||
if (base_translation_override_from_resources.load ("wsjtx_" + base_language, ":/Translations"))
|
if (base_translation_override_from_resources.load ("wsjtx_" + base_language, translations_dir))
|
||||||
{
|
{
|
||||||
*early_messages << QString {"Loaded base translation file from :/Translations based on language %1"}.arg (base_language);
|
*early_messages << QString {"Loaded base translation file from %1 based on language %2"}
|
||||||
|
.arg (translations_dir)
|
||||||
|
.arg (base_language);
|
||||||
a.installTranslator (&base_translation_override_from_resources);
|
a.installTranslator (&base_translation_override_from_resources);
|
||||||
}
|
}
|
||||||
// now load the requested translations (may be a duplicate
|
// now load the requested translations (may be a duplicate
|
||||||
// but we shouldn't care)
|
// but we shouldn't care)
|
||||||
if (translation_override_from_resources.load ("wsjtx_" + language , ":/Translations"))
|
if (translation_override_from_resources.load ("wsjtx_" + language, translations_dir))
|
||||||
{
|
{
|
||||||
*early_messages << QString {"Loaded translation file from :/Translations based on language %1"}.arg (language);
|
*early_messages << QString {"Loaded translation file from %1 based on language %2"}
|
||||||
|
.arg (translations_dir)
|
||||||
|
.arg (language);
|
||||||
a.installTranslator (&translation_override_from_resources);
|
a.installTranslator (&translation_override_from_resources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTranslator translator_from_cwd;
|
|
||||||
QTranslator base_translator_from_cwd;
|
|
||||||
// Load any matching translation from the current directory
|
// Load any matching translation from the current directory
|
||||||
// using the current locale. This allows translators to easily
|
// using the current locale. This allows translators to easily
|
||||||
// test their translations by releasing (lrelease) a .qm file
|
// test their translations by releasing (lrelease) a .qm file
|
||||||
@ -253,6 +275,7 @@ int main(int argc, char *argv[])
|
|||||||
// on non-Windows system.
|
// on non-Windows system.
|
||||||
|
|
||||||
// try and load the base translation
|
// try and load the base translation
|
||||||
|
QTranslator base_translator_from_cwd;
|
||||||
for (QString locale_name : locale.uiLanguages ())
|
for (QString locale_name : locale.uiLanguages ())
|
||||||
{
|
{
|
||||||
auto language = locale_name.left (2);
|
auto language = locale_name.left (2);
|
||||||
@ -269,20 +292,21 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
// now try and load the most specific translations (may be a
|
// now try and load the most specific translations (may be a
|
||||||
// duplicate but we shouldn't care)
|
// duplicate but we shouldn't care)
|
||||||
|
QTranslator translator_from_cwd;
|
||||||
if (translator_from_cwd.load (locale, "wsjtx", "_"))
|
if (translator_from_cwd.load (locale, "wsjtx", "_"))
|
||||||
{
|
{
|
||||||
*early_messages << "loaded translations for current locale from a file";
|
*early_messages << "loaded translations for current locale from a file";
|
||||||
a.installTranslator (&translator_from_cwd);
|
a.installTranslator (&translator_from_cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTranslator translation_override_from_cwd;
|
|
||||||
QTranslator base_translation_override_from_cwd;
|
|
||||||
// Load any matching translation from the current directory
|
// Load any matching translation from the current directory
|
||||||
// using the command line option language override. This allows
|
// using the command line option language override. This allows
|
||||||
// translators to easily test their translations on Windows by
|
// translators to easily test their translations on Windows by
|
||||||
// releasing (lrelease) a .qm file into the current directory
|
// releasing (lrelease) a .qm file into the current directory
|
||||||
// with a suitable name (e.g. wsjtx_en_GB.qm), then running
|
// with a suitable name (e.g. wsjtx_en_GB.qm), then running
|
||||||
// wsjtx to view the results.
|
// wsjtx to view the results.
|
||||||
|
QTranslator base_translation_override_from_cwd;
|
||||||
|
QTranslator translation_override_from_cwd;
|
||||||
if (parser.isSet (lang_option))
|
if (parser.isSet (lang_option))
|
||||||
{
|
{
|
||||||
auto language = parser.value (lang_option).replace ('-', '_');
|
auto language = parser.value (lang_option).replace ('-', '_');
|
||||||
|
Loading…
Reference in New Issue
Block a user