From 35080bd1756379449afbb52d2c07c9396d1c2899 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 15 Jan 2020 23:34:50 +0900 Subject: [PATCH] Document folder structure to encourage translation in various languages (#1170) * Restructuring docs resource folder Signed-off-by: Hiroshi Miura * Correct variable name according to coding rule Signed-off-by: Hiroshi Miura --- .../markdown_guide.md} | 0 .../docs/{shortcuts_en.md => en/shortcuts.md} | 0 .../tips_add_style.md} | 0 .../tips_add_theme.md} | 0 .../tips_custom_shortcut.md} | 0 .../tips_external_program.md} | 0 .../docs/{welcome_en.md => en/welcome.md} | 0 .../markdown_guide.md} | 0 .../docs/{shortcuts_ja.md => ja/shortcuts.md} | 0 .../tips_add_style.md} | 0 .../tips_add_theme.md} | 0 .../tips_custom_shortcut.md} | 0 .../tips_external_program.md} | 0 .../docs/{welcome_ja.md => ja/welcome.md} | 0 .../markdown_guide.md} | 0 .../{shortcuts_zh.md => zh_CN/shortcuts.md} | 0 .../tips_add_style.md} | 0 .../tips_add_theme.md} | 0 .../tips_custom_shortcut.md} | 0 .../tips_external_program.md} | 0 .../docs/{welcome_zh.md => zh_CN/welcome.md} | 0 src/utils/vutils.cpp | 28 +++++-------- src/utils/vutils.h | 5 --- src/vnote.qrc | 42 +++++++++---------- 24 files changed, 31 insertions(+), 44 deletions(-) rename src/resources/docs/{markdown_guide_en.md => en/markdown_guide.md} (100%) rename src/resources/docs/{shortcuts_en.md => en/shortcuts.md} (100%) rename src/resources/docs/{tips_add_style_en.md => en/tips_add_style.md} (100%) rename src/resources/docs/{tips_add_theme_en.md => en/tips_add_theme.md} (100%) rename src/resources/docs/{tips_custom_shortcut_en.md => en/tips_custom_shortcut.md} (100%) rename src/resources/docs/{tips_external_program_en.md => en/tips_external_program.md} (100%) rename src/resources/docs/{welcome_en.md => en/welcome.md} (100%) rename src/resources/docs/{markdown_guide_ja.md => ja/markdown_guide.md} (100%) rename src/resources/docs/{shortcuts_ja.md => ja/shortcuts.md} (100%) rename src/resources/docs/{tips_add_style_ja.md => ja/tips_add_style.md} (100%) rename src/resources/docs/{tips_add_theme_ja.md => ja/tips_add_theme.md} (100%) rename src/resources/docs/{tips_custom_shortcut_ja.md => ja/tips_custom_shortcut.md} (100%) rename src/resources/docs/{tips_external_program_ja.md => ja/tips_external_program.md} (100%) rename src/resources/docs/{welcome_ja.md => ja/welcome.md} (100%) rename src/resources/docs/{markdown_guide_zh.md => zh_CN/markdown_guide.md} (100%) rename src/resources/docs/{shortcuts_zh.md => zh_CN/shortcuts.md} (100%) rename src/resources/docs/{tips_add_style_zh.md => zh_CN/tips_add_style.md} (100%) rename src/resources/docs/{tips_add_theme_zh.md => zh_CN/tips_add_theme.md} (100%) rename src/resources/docs/{tips_custom_shortcut_zh.md => zh_CN/tips_custom_shortcut.md} (100%) rename src/resources/docs/{tips_external_program_zh.md => zh_CN/tips_external_program.md} (100%) rename src/resources/docs/{welcome_zh.md => zh_CN/welcome.md} (100%) diff --git a/src/resources/docs/markdown_guide_en.md b/src/resources/docs/en/markdown_guide.md similarity index 100% rename from src/resources/docs/markdown_guide_en.md rename to src/resources/docs/en/markdown_guide.md diff --git a/src/resources/docs/shortcuts_en.md b/src/resources/docs/en/shortcuts.md similarity index 100% rename from src/resources/docs/shortcuts_en.md rename to src/resources/docs/en/shortcuts.md diff --git a/src/resources/docs/tips_add_style_en.md b/src/resources/docs/en/tips_add_style.md similarity index 100% rename from src/resources/docs/tips_add_style_en.md rename to src/resources/docs/en/tips_add_style.md diff --git a/src/resources/docs/tips_add_theme_en.md b/src/resources/docs/en/tips_add_theme.md similarity index 100% rename from src/resources/docs/tips_add_theme_en.md rename to src/resources/docs/en/tips_add_theme.md diff --git a/src/resources/docs/tips_custom_shortcut_en.md b/src/resources/docs/en/tips_custom_shortcut.md similarity index 100% rename from src/resources/docs/tips_custom_shortcut_en.md rename to src/resources/docs/en/tips_custom_shortcut.md diff --git a/src/resources/docs/tips_external_program_en.md b/src/resources/docs/en/tips_external_program.md similarity index 100% rename from src/resources/docs/tips_external_program_en.md rename to src/resources/docs/en/tips_external_program.md diff --git a/src/resources/docs/welcome_en.md b/src/resources/docs/en/welcome.md similarity index 100% rename from src/resources/docs/welcome_en.md rename to src/resources/docs/en/welcome.md diff --git a/src/resources/docs/markdown_guide_ja.md b/src/resources/docs/ja/markdown_guide.md similarity index 100% rename from src/resources/docs/markdown_guide_ja.md rename to src/resources/docs/ja/markdown_guide.md diff --git a/src/resources/docs/shortcuts_ja.md b/src/resources/docs/ja/shortcuts.md similarity index 100% rename from src/resources/docs/shortcuts_ja.md rename to src/resources/docs/ja/shortcuts.md diff --git a/src/resources/docs/tips_add_style_ja.md b/src/resources/docs/ja/tips_add_style.md similarity index 100% rename from src/resources/docs/tips_add_style_ja.md rename to src/resources/docs/ja/tips_add_style.md diff --git a/src/resources/docs/tips_add_theme_ja.md b/src/resources/docs/ja/tips_add_theme.md similarity index 100% rename from src/resources/docs/tips_add_theme_ja.md rename to src/resources/docs/ja/tips_add_theme.md diff --git a/src/resources/docs/tips_custom_shortcut_ja.md b/src/resources/docs/ja/tips_custom_shortcut.md similarity index 100% rename from src/resources/docs/tips_custom_shortcut_ja.md rename to src/resources/docs/ja/tips_custom_shortcut.md diff --git a/src/resources/docs/tips_external_program_ja.md b/src/resources/docs/ja/tips_external_program.md similarity index 100% rename from src/resources/docs/tips_external_program_ja.md rename to src/resources/docs/ja/tips_external_program.md diff --git a/src/resources/docs/welcome_ja.md b/src/resources/docs/ja/welcome.md similarity index 100% rename from src/resources/docs/welcome_ja.md rename to src/resources/docs/ja/welcome.md diff --git a/src/resources/docs/markdown_guide_zh.md b/src/resources/docs/zh_CN/markdown_guide.md similarity index 100% rename from src/resources/docs/markdown_guide_zh.md rename to src/resources/docs/zh_CN/markdown_guide.md diff --git a/src/resources/docs/shortcuts_zh.md b/src/resources/docs/zh_CN/shortcuts.md similarity index 100% rename from src/resources/docs/shortcuts_zh.md rename to src/resources/docs/zh_CN/shortcuts.md diff --git a/src/resources/docs/tips_add_style_zh.md b/src/resources/docs/zh_CN/tips_add_style.md similarity index 100% rename from src/resources/docs/tips_add_style_zh.md rename to src/resources/docs/zh_CN/tips_add_style.md diff --git a/src/resources/docs/tips_add_theme_zh.md b/src/resources/docs/zh_CN/tips_add_theme.md similarity index 100% rename from src/resources/docs/tips_add_theme_zh.md rename to src/resources/docs/zh_CN/tips_add_theme.md diff --git a/src/resources/docs/tips_custom_shortcut_zh.md b/src/resources/docs/zh_CN/tips_custom_shortcut.md similarity index 100% rename from src/resources/docs/tips_custom_shortcut_zh.md rename to src/resources/docs/zh_CN/tips_custom_shortcut.md diff --git a/src/resources/docs/tips_external_program_zh.md b/src/resources/docs/zh_CN/tips_external_program.md similarity index 100% rename from src/resources/docs/tips_external_program_zh.md rename to src/resources/docs/zh_CN/tips_external_program.md diff --git a/src/resources/docs/welcome_zh.md b/src/resources/docs/zh_CN/welcome.md similarity index 100% rename from src/resources/docs/welcome_zh.md rename to src/resources/docs/zh_CN/welcome.md diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index d7141096..cc69520a 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -1479,28 +1479,20 @@ QWebEngineView *VUtils::getWebEngineView(const QColor &p_background, QWidget *p_ return viewer; } -QString VUtils::getFileNameWithLocale(const QString &p_name, const QString &p_locale) -{ - QString locale = p_locale.isEmpty() ? getLocale() : p_locale; - locale = locale.split('_')[0]; - - QFileInfo fi(p_name); - QString baseName = fi.completeBaseName(); - QString suffix = fi.suffix(); - - if (suffix.isEmpty()) { - return QString("%1_%2").arg(baseName).arg(locale); - } else { - return QString("%1_%2.%3").arg(baseName).arg(locale).arg(suffix); - } -} - QString VUtils::getDocFile(const QString &p_name) { QDir dir(VNote::c_docFileFolder); - QString name(getFileNameWithLocale(p_name)); + QString fullLocale = getLocale(); + QString shortLocale = fullLocale.split('_')[0]; + // First looks full locale name folder (eg. zh_CN) + QString name = QString("%1/%2").arg(fullLocale).arg(p_name); if (!dir.exists(name)) { - name = getFileNameWithLocale(p_name, "en_US"); + // If not found, try 2-char locale name folder (eg. ja) + name = QString("%1/%2").arg(shortLocale).arg(p_name); + } + if (!dir.exists(name)) { + // even not found, fall back to default english folder. + name = QString("%1/%2").arg("en").arg(p_name); } return dir.filePath(name); diff --git a/src/utils/vutils.h b/src/utils/vutils.h index 3c457646..6150eb8a 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -318,11 +318,6 @@ public: static void setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_val = true); - // 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); diff --git a/src/vnote.qrc b/src/vnote.qrc index ba649e04..61d077e2 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -57,9 +57,6 @@ utils/markdown-it/markdown-it-headinganchor.js utils/markdown-it/markdown-it-task-lists.min.js resources/icons/close_red.svg - resources/docs/shortcuts_en.md - resources/docs/shortcuts_zh.md - resources/docs/shortcuts_ja.md utils/showdown/showdown.min.js resources/showdown.js utils/showdown/showdown-headinganchor.js @@ -76,9 +73,6 @@ resources/icons/inline_code.svg resources/icons/close_note_tb.svg resources/icons/editing_modified.svg - resources/docs/markdown_guide_en.md - resources/docs/markdown_guide_zh.md - resources/docs/markdown_guide_ja.md utils/highlightjs/highlightjs-line-numbers.min.js resources/icons/recycle_bin.svg resources/icons/empty_recycle_bin.svg @@ -157,20 +151,8 @@ resources/themes/v_moonlight/v_moonlight_codeblock.css resources/simple_template.html resources/typewriter.css - resources/docs/tips_custom_shortcut_en.md - resources/docs/tips_custom_shortcut_zh.md - resources/docs/tips_custom_shortcut_ja.md resources/icons/add_style.svg - resources/docs/tips_add_theme_en.md - resources/docs/tips_add_theme_zh.md - resources/docs/tips_add_theme_ja.md - resources/docs/tips_add_style_en.md - resources/docs/tips_add_style_zh.md - resources/docs/tips_add_style_ja.md resources/icons/add_program.svg - resources/docs/tips_external_program_en.md - resources/docs/tips_external_program_zh.md - resources/docs/tips_external_program_ja.md translations/widgets_zh_CN.qm translations/qdialogbuttonbox_zh_CN.qm translations/qwebengine_zh_CN.qm @@ -278,9 +260,6 @@ resources/export/outline.js resources/icons/add.svg resources/icons/delete.svg - resources/docs/welcome_en.md - resources/docs/welcome_zh.md - resources/docs/welcome_ja.md resources/icons/256x256/vnote.png utils/markdown-it/markdown-it-container.min.js resources/icons/table.svg @@ -358,5 +337,26 @@ resources/themes/v_next/v_next_codeblock.css resources/themes/v_next/v_next_mermaid.css utils/mermaid/mermaid.min.js + resources/docs/en/markdown_guide.md + resources/docs/en/shortcuts.md + resources/docs/en/tips_add_style.md + resources/docs/en/tips_add_theme.md + resources/docs/en/tips_custom_shortcut.md + resources/docs/en/tips_external_program.md + resources/docs/en/welcome.md + resources/docs/ja/markdown_guide.md + resources/docs/ja/shortcuts.md + resources/docs/ja/tips_add_style.md + resources/docs/ja/tips_add_theme.md + resources/docs/ja/tips_custom_shortcut.md + resources/docs/ja/tips_external_program.md + resources/docs/ja/welcome.md + resources/docs/zh_CN/markdown_guide.md + resources/docs/zh_CN/shortcuts.md + resources/docs/zh_CN/tips_add_style.md + resources/docs/zh_CN/tips_add_theme.md + resources/docs/zh_CN/tips_custom_shortcut.md + resources/docs/zh_CN/tips_external_program.md + resources/docs/zh_CN/welcome.md