Translations looked up correctly
Tweak both the launcher and main locale lookups, to tolerate the different region suffixes encountered in reality.
This commit is contained in:
parent
2329654e3b
commit
41687767b9
3 changed files with 18 additions and 6 deletions
|
@ -20,23 +20,28 @@ if (${do_translate})
|
|||
|
||||
add_custom_target(fgfs_qm_files ALL)
|
||||
|
||||
file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">")
|
||||
file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">\n")
|
||||
|
||||
# qm generation and installation
|
||||
foreach(LANG ${LANGUAGES})
|
||||
set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${LANG}.qm")
|
||||
# trim down to a two-letter code for output. This will need to get
|
||||
# smarter if we ever have different translations for a dialect,
|
||||
# eg en_GB, fr_CA or pt_BR.
|
||||
string(SUBSTRING ${LANG} 0 2 simple_lang)
|
||||
|
||||
set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${simple_lang}.qm")
|
||||
add_custom_command(
|
||||
OUTPUT ${out_file}
|
||||
COMMAND Qt5::lrelease ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
||||
-qm ${out_file}
|
||||
DEPENDS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
||||
)
|
||||
add_custom_target(fgfs_${LANG}_qm ALL DEPENDS ${out_file})
|
||||
add_custom_target(fgfs_${simple_lang}_qm ALL DEPENDS ${out_file})
|
||||
|
||||
add_dependencies(fgfs_qm_files fgfs_${LANG}_qm)
|
||||
add_dependencies(fgfs_qm_files fgfs_${simple_lang}_qm)
|
||||
|
||||
# local path needed here, not absolute
|
||||
file(APPEND ${translation_res} "<file>FlightGear_${LANG}.qm</file>\n")
|
||||
file(APPEND ${translation_res} "<file>FlightGear_${simple_lang}.qm</file>\n")
|
||||
endforeach()
|
||||
|
||||
file(APPEND ${translation_res} "</qresource>\n</RCC>")
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "QtLauncher.hxx"
|
||||
|
||||
#include <locale.h>
|
||||
|
@ -296,7 +298,6 @@ void initApp(int& argc, char** argv, bool doInitQSettings)
|
|||
}
|
||||
|
||||
QTranslator* translator = new QTranslator(static_qApp.get());
|
||||
// look up e.g. :/FlightGear_de.qm
|
||||
if (translator->load(QLocale(), QLatin1String("FlightGear"), QLatin1String("_"), QLatin1String(":/"))) {
|
||||
qInfo() << "Loaded translations";
|
||||
static_qApp->installTranslator(translator);
|
||||
|
|
|
@ -142,6 +142,12 @@ FGLocale::findLocaleNode(const string& localeSpec)
|
|||
|
||||
// try country's default resource, i.e. "de_DE" => "de"
|
||||
std::size_t pos = language.find('_');
|
||||
if (pos == string::npos) {
|
||||
// at least OS-X encodes these as en-GB and so on, so try hypens
|
||||
// as well as underscores
|
||||
pos = language.find('-');
|
||||
}
|
||||
|
||||
if ((pos != string::npos) && (pos > 0))
|
||||
{
|
||||
node = findLocaleNode(language.substr(0, pos));
|
||||
|
|
Loading…
Add table
Reference in a new issue