bug-fix: use en locale for help docs if user's locale is missing

This commit is contained in:
Le Tan 2018-01-25 21:13:21 +08:00
parent ec0b98f050
commit 97721f3e92
2 changed files with 12 additions and 5 deletions

View File

@ -1143,9 +1143,9 @@ QWebEngineView *VUtils::getWebEngineView(QWidget *p_parent)
return viewer;
}
QString VUtils::getFileNameWithLocale(const QString &p_name)
QString VUtils::getFileNameWithLocale(const QString &p_name, const QString &p_locale)
{
QString locale = getLocale();
QString locale = p_locale.isEmpty() ? getLocale() : p_locale;
locale = locale.split('_')[0];
QFileInfo fi(p_name);
@ -1162,7 +1162,12 @@ QString VUtils::getFileNameWithLocale(const QString &p_name)
QString VUtils::getDocFile(const QString &p_name)
{
QDir dir(VNote::c_docFileFolder);
return dir.filePath(getFileNameWithLocale(p_name));
QString name(getFileNameWithLocale(p_name));
if (!dir.exists(name)) {
name = getFileNameWithLocale(p_name, "en_US");
}
return dir.filePath(name);
}
QString VUtils::getCaptainShortcutSequenceText(const QString &p_operation)

View File

@ -279,8 +279,10 @@ public:
static void setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_val = true);
// Return a file name with locale.
static QString getFileNameWithLocale(const QString &p_name);
// Return a file name with locale @p_locale.
// If @p_locale is empty, use system's locale instead.
static QString getFileNameWithLocale(const QString &p_name,
const QString &p_locale = QString());
// Return a doc file path.
static QString getDocFile(const QString &p_name);