allow to use multiple locale directories

remove config options:
- locale_dir
- locale_dir_default

add a config option:
- locale_dirs - a list of directories with locale files (translations)

We start reading locale from the first directory and files with the same name
in each directory are concatenated.
This commit is contained in:
2026-06-21 23:36:29 +02:00
parent d35854691c
commit b82a36142c
5 changed files with 101 additions and 107 deletions
+18 -15
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
/*
* Copyright (c) 2010-2026, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,8 +53,11 @@ public:
Locale();
// locale directories
void SetDirectories(const std::vector<std::wstring> & dirs);
// locale files
// those files will be reading from directories specified in Read() method
// those files will be reading from directories specified above
// default one item: en
void SetLocaleFiles(const std::vector<std::wstring> & files);
@@ -73,11 +76,11 @@ public:
size_t GetDefLang() const;
// reading locales
// you should call SetLocaleFiles() beforehand
void Read(const char * dir, const char * dir_def = 0);
void Read(const std::string & dir, const std::string & dir_def);
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
void Read(const std::wstring & dir, const std::wstring & dir_def);
// you should call SetDirectories(), SetLocaleFiles() and SetLocaleMaxId() beforehand
void ReadLocales();
// clear directories, files and read translations
void Clear();
// returns true if a language with lang_id exists
bool HasLanguage(size_t lang_id);
@@ -208,11 +211,11 @@ private:
bool operator<(const SubstItem & arg) const { return from < arg.from; }
};
void AddLocale(const char * file);
void ReadFile(const char * dir, const char * dir_def, const char * file);
bool ReadFile(const char * dir, const char * file);
void ReadSubstTable(const char * dir, const char * dir_def);
bool ReadSubstTable(const char * dir);
void AddLocale(const std::wstring & file);
void ReadFile(const std::wstring & file);
bool ReadFile(const std::wstring & dir, const std::wstring & file);
void ReadSubstTable();
bool ReadSubstTable(const std::wstring & dir);
void CreateSubstVector(std::vector<SubstItem> & vect, const std::wstring & tab1, const std::wstring & tab2);
void CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<std::wstring> & tab);
size_t SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val);
@@ -221,6 +224,8 @@ private:
bool GetListInLanguage(const std::wstring & key, size_t lang_id, std::vector<std::wstring> & list) const;
bool IsListInLanguage(const std::wstring & key, size_t lang_id) const;
// directories
std::vector<std::wstring> directories;
// locale files
std::vector<std::wstring> locale_files;
@@ -252,11 +257,9 @@ private:
pt::Space temp_space;
pt::SpaceParser loc_parser;
std::string locale_filea;
std::string file_name;
std::wstring key_str;
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
std::string adir1, adir2;
std::wstring pattern_value;
};