Display actual language names in preferences

Add ability to set metadata variables in the language files.
Use the LANGUAGE_DISPLAY_NAME metadata variable value in preferences to
show the languages.

Metadata variables are defined in the first section of a language file,
i.e. the comments at the beginning of the file. At most one variable can
be defined per line. The definition takes the following format:
    #<header><whitespace>@<key>=<value>
where:
    <header> is any sequence of non-whitespace characters
    <whitespace> is any non-empty sequence of whitespace characters
    <key> is the metadata key name
    <value> is the metadata value
For example,
    #101 @LANGUAGE_DISPLAY_NAME=English (US)
defines a metadata key "LANGUAGE_DISPLAY_NAME" with value
"English (US)". Lines that do not match the format are ignored.
This commit is contained in:
Lawrence Lee
2023-07-04 17:40:33 -07:00
parent 1d9225dfc3
commit 6bd822352e
22 changed files with 446 additions and 282 deletions

View File

@@ -16,21 +16,27 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <glibmm/miscutils.h>
#include <glibmm/ustring.h>
#include <sigc++/slot.h>
#include "externaleditorpreferences.h"
#include "preferences.h"
#include "multilangmgr.h"
#include "splash.h"
#include "cachemanager.h"
#include "addsetids.h"
#include "cachemanager.h"
#include "externaleditorpreferences.h"
#include "multilangmgr.h"
#include "preferences.h"
#include "rtimage.h"
#include "rtwindow.h"
#include "splash.h"
#include "toollocationpref.h"
#include "../rtengine/dfmanager.h"
#include "../rtengine/ffmanager.h"
#include "../rtengine/iccstore.h"
#include "../rtengine/procparams.h"
#include <sstream>
#include "rtimage.h"
#include "rtwindow.h"
#include "toollocationpref.h"
#ifdef _OPENMP
#include <omp.h>
#endif
@@ -1095,9 +1101,14 @@ Gtk::Widget* Preferences::getGeneralPanel()
std::vector<Glib::ustring> langs;
parseDir(argv0 + "/languages", langs, "");
for (size_t i = 0; i < langs.size(); i++) {
if ("default" != langs[i] && "README" != langs[i] && "LICENSE" != langs[i]) {
languages->append(langs[i]);
for (const auto &lang : langs) {
if ("default" != lang && "README" != lang && "LICENSE" != lang) {
auto lang_metadata = langMgr.getMetadata(Glib::build_filename(argv0 + "/languages", lang));
const auto &display_name =
lang_metadata != nullptr
? Glib::ustring(lang_metadata->getLanguageName(lang))
: lang;
languages->append(lang, display_name);
}
}
@@ -1721,7 +1732,7 @@ void Preferences::storePreferences()
moptions.menuGroupExtProg = ckbmenuGroupExtProg->get_active();
moptions.highlightThreshold = (int)hlThresh->get_value();
moptions.shadowThreshold = (int)shThresh->get_value();
moptions.language = languages->get_active_text();
moptions.language = languages->get_active_id();
moptions.languageAutoDetect = ckbLangAutoDetect->get_active();
moptions.theme = themeFNames.at (themeCBT->get_active_row_number ()).longFName;
@@ -1997,7 +2008,7 @@ void Preferences::fillPreferences()
}
cprevdemo->set_active (moptions.prevdemo);
languages->set_active_text(moptions.language);
languages->set_active_id(moptions.language);
ckbLangAutoDetect->set_active(moptions.languageAutoDetect);
int themeNbr = getThemeRowNumber(moptions.theme);
themeCBT->set_active (themeNbr == -1 ? 0 : themeNbr);