From 2c08dd3a145da904c6ceb5993435277a401b0408 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 6 Apr 2011 23:16:34 +0300 Subject: Add support for help pages translations. --- src/gui/helpwindow.cpp | 16 ++++++++++++++-- src/utils/stringutils.cpp | 14 ++++++++++++++ src/utils/stringutils.h | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index c67fa8424..a4370d516 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -22,6 +22,8 @@ #include "gui/helpwindow.h" +#include "log.h" + #include "gui/gui.h" #include "gui/setup.h" @@ -95,12 +97,22 @@ void HelpWindow::loadHelp(const std::string &helpFile) void HelpWindow::loadFile(const std::string &file) { + const std::string lang = getLang(); ResourceManager *resman = ResourceManager::getInstance(); std::string helpPath = branding.getStringValue("helpPath"); if (helpPath.empty()) helpPath = paths.getStringValue("help"); - std::vector lines = - resman->loadTextFile(helpPath + file + ".txt"); + + std::vector lines; + if (!lang.empty()) + { + const std::string name = helpPath + lang + "/" + file + ".txt"; + if (resman->exists(name)) + lines = resman->loadTextFile(name); + } + + if (lines.empty()) + lines = resman->loadTextFile(helpPath + file + ".txt"); for (unsigned int i = 0; i < lines.size(); ++i) mBrowserBox->addRow(lines[i]); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 02bba8599..a7e1b6c7d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -439,3 +439,17 @@ std::string combineDye2(std::string file, std::string dye) return file; } } + +std::string getLang() +{ + char *lng = getenv("LANG"); + if (!lng) + return ""; + + std::string lang(lng); + int dot = lang.find("."); + if (dot == std::string::npos && dot > 0) + return lang; + + return lang.substr(0, dot); +} \ No newline at end of file diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 02c25eddb..83773bd72 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -177,4 +177,6 @@ std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); +std::string getLang(); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-60-g2f50