Skip to content

Commit

Permalink
better handle Guide/Landmark xlate (BeckyEbook)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Dec 26, 2023
1 parent d3016cd commit e4ef578
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pre-2.x.x
Sigil-pre-2.x.x
New Features
- assign menu accelerators P - &Plugins, and K - Chec&kpoints (thank you BeckyEbook)
- add ability to change keyboard focus using keyboard shortcuts or menus
Expand All @@ -17,6 +17,7 @@ pre-2.x.x
- fix svg rendering in QtSvg by filtering out desc and title tags inside text tags pre-rendering
- fix Python plugin quickparser.py to better handle svg mixed case tag names
- better handle cancelling out of plugins prior to their completion
- better handle Guide/Landmark title translations (thank you BeckyEbook)


Sigil-2.0.2
Expand Down
18 changes: 15 additions & 3 deletions src/Misc/GuideItems.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/************************************************************************
**
** Copyright (C) 2016-2021 Kevin B. Hendricks, Stratford Ontario Canada
** Copyright (C) 2016-2023 Kevin B. Hendricks, Stratford Ontario Canada
**
** This file is part of Sigil.
**
Expand Down Expand Up @@ -66,7 +66,7 @@ QString GuideItems::GetTitle(const QString &code, const QString &lang)
// Note the book language may differ from the ui language
bool translation_loaded = false;
QTranslator bookTranslator;
const QString qm_name = QString("sigil_%1").arg(lang);
QString qm_name = QString("sigil_%1").arg(lang);
// Run though all locations and stop once we find and are able to load
// an appropriate translation.
foreach(QString path, UILanguage::GetPossibleTranslationPaths()) {
Expand All @@ -78,12 +78,24 @@ QString GuideItems::GetTitle(const QString &code, const QString &lang)
}
}
}
// try again with just the base part of the langcode before any "-"
if (!translation_loaded && lang.contains("-")) {
const QString langcut = lang.split("-").at(0);
qm_name = QString("sigil_%1").arg(langcut);
foreach(QString path, UILanguage::GetPossibleTranslationPaths()) {
if (QDir(path).exists()) {
if (bookTranslator.load(qm_name, path)) {
translation_loaded = true;
break;
}
}
}
}
// if no translator matched, use the user interface language so that
// the dev can fix them manually
if (!translation_loaded) {
return GetName(code);
}

QString title = bookTranslator.translate("GuideItems", m_CodeToRawTitle[code].toUtf8().constData());
if (title.isEmpty()) {
title = bookTranslator.translate("Landmarks", m_CodeToRawTitle[code].toUtf8().constData());
Expand Down
18 changes: 15 additions & 3 deletions src/Misc/Landmarks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/************************************************************************
**
** Copyright (C) 2016-2020 Kevin B. Hendricks, Stratford, Ontario, Canada
** Copyright (C) 2016-2023 Kevin B. Hendricks, Stratford, Ontario, Canada
**
** This file is part of Sigil.
**
Expand Down Expand Up @@ -63,7 +63,7 @@ QString Landmarks::GetTitle(const QString &code, const QString &lang)
// Note the book language may differ from the ui language
bool translation_loaded = false;
QTranslator bookTranslator;
const QString qm_name = QString("sigil_%1").arg(lang);
QString qm_name = QString("sigil_%1").arg(lang);
// Run though all locations and stop once we find and are able to load
// an appropriate translation.
foreach(QString path, UILanguage::GetPossibleTranslationPaths()) {
Expand All @@ -74,12 +74,24 @@ QString Landmarks::GetTitle(const QString &code, const QString &lang)
}
}
}
// try again with just the base part of the langcode before any "-"
if (!translation_loaded && lang.contains("-")) {
const QString langcut = lang.split("-").at(0);
qm_name = QString("sigil_%1").arg(langcut);
foreach(QString path, UILanguage::GetPossibleTranslationPaths()) {
if (QDir(path).exists()) {
if (bookTranslator.load(qm_name, path)) {
translation_loaded = true;
break;
}
}
}
}
// if no translator matched, use the user interface language so that
// the dev can fix them manually
if (!translation_loaded) {
return GetName(code);
}

QString title = bookTranslator.translate("Landmarks", m_CodeToRawTitle[code].toUtf8().constData());
return title;
}
Expand Down

0 comments on commit e4ef578

Please sign in to comment.