Browse Source

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

Le Tan 7 years ago
parent
commit
97721f3e92
2 changed files with 12 additions and 5 deletions
  1. 8 3
      src/utils/vutils.cpp
  2. 4 2
      src/utils/vutils.h

+ 8 - 3
src/utils/vutils.cpp

@@ -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)

+ 4 - 2
src/utils/vutils.h

@@ -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);