From c09563fe18c1f29affc3bae6a122824e2ffcb706 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 28 Aug 2020 18:59:44 +0200 Subject: Make abouttab read locale specific content if it exists. --- plugingui/abouttab.cc | 31 +++++++++++++++++++++++++++---- plugingui/abouttab.h | 5 ----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/plugingui/abouttab.cc b/plugingui/abouttab.cc index 7e330cb..8a8f737 100644 --- a/plugingui/abouttab.cc +++ b/plugingui/abouttab.cc @@ -27,9 +27,32 @@ #include "abouttab.h" #include +#include #include "utf8.h" +namespace +{ +std::string getLocalizedFile(const std::string& file) +{ + auto language = Translation::getISO639LanguageName(); + std::string file_localized = file + "." + language; + GUI::Resource resource_localized{file_localized}; + if(resource_localized.valid()) + { + return resource_localized.data(); + } + + GUI::Resource resource{file}; + if(resource.valid()) + { + return resource.data(); + } + + return ""; +} +} + namespace GUI { @@ -60,7 +83,7 @@ std::string AboutTab::getAboutText() " About\n" "=============\n" "\n"); - about_text.append(about.data()); + about_text.append(getLocalizedFile(":../ABOUT")); // Version about_text.append( @@ -78,7 +101,7 @@ std::string AboutTab::getAboutText() " Bugs\n" "=============\n" "\n"); - about_text.append(bugs.data()); + about_text.append(getLocalizedFile(":../BUGS")); // Authors about_text.append( @@ -87,7 +110,7 @@ std::string AboutTab::getAboutText() " Authors\n" "=============\n" "\n"); - about_text.append(UTF8().toLatin1(authors.data())); + about_text.append(UTF8().toLatin1(getLocalizedFile(":../AUTHORS"))); // GPL about_text.append( @@ -96,7 +119,7 @@ std::string AboutTab::getAboutText() " License\n" "=============\n" "\n"); - about_text.append(gpl.data()); + about_text.append(getLocalizedFile(":../COPYING")); return about_text; } diff --git a/plugingui/abouttab.h b/plugingui/abouttab.h index eda23da..ed06b1d 100644 --- a/plugingui/abouttab.h +++ b/plugingui/abouttab.h @@ -49,11 +49,6 @@ private: TextEdit text_edit{this}; int margin{10}; - - Resource about{":../ABOUT"}; - Resource bugs{":../BUGS"}; - Resource authors{":../AUTHORS"}; - Resource gpl{":../COPYING"}; }; } // GUI:: -- cgit v1.2.3