changed: removed Languages::Land enum

now we set the languages in the config file: option locale_files, sample:
  locale_files = ( en, pl )
it represents the name of locale files (those from locale_dir directory)
renamed config option: locale to locale_default


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@722 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-02-24 17:06:12 +00:00
parent 15487b347f
commit ba63c8c661
18 changed files with 268 additions and 179 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* Copyright (c) 2010-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -20,56 +20,77 @@ class Locale
{
public:
// !! pozbyc sie tego enuma
// niech wybieranie ilosci locali (ile jezykow) bedzie w pliku konfiguracyjnym
enum Lang
{
lang_en = 0,
lang_pl,
lang_unknown // should be last
};
Locale();
void Read(const char * dir, const char * dir_def = 0);
void Read(const std::string & dir, const std::string & dir_def);
// locale files
// those files will be reading from directories specified in Read() method
// default one item: en
void SetLocaleFiles(const std::vector<std::wstring> & files);
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
void Read(const std::wstring & dir, const std::wstring & dir_def);
// 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);
// checking whether there is a 'key' in the current language (or in 'lang' language)
bool IsKey(const wchar_t * key);
bool IsKey(const wchar_t * key, size_t lang);
bool IsKey(const std::wstring & key) const;
bool IsKey(const std::wstring & key, Lang lang) const;
const std::wstring & Get(const std::wstring & key) const;
const std::wstring & Get(const std::wstring & key, Lang lang) const;
bool IsKey(const std::wstring & key, size_t lang) const;
// default is english
void SetLang(Lang lang);
Lang GetLang();
// returning specific 'key'
const std::wstring & Get(const wchar_t * key);
const std::wstring & Get(const wchar_t * key, size_t lang);
const std::wstring & Get(const std::wstring & key) const;
const std::wstring & Get(const std::wstring & key, size_t lang) const;
// setting/getting current language
// default: 0
void SetLang(size_t lang);
size_t GetLang() const;
// which language is used instead if there is no a key in an other language
// default: lang_en
void SetLangDef(Lang lang);
// default: 0
void SetLangDef(size_t lang);
size_t GetLangDef() const;
// return an index of a language file's name
// those set by SetLocaleFiles()
// or 0 if there is no such a file name
size_t FileNameToLang(const std::wstring & str) const;
static Lang StrToLang(const std::wstring & str);
static const wchar_t * LangToStr(Lang lang);
// return a file name for the 'lang'
const std::wstring & LangToFileName(size_t lang) const;
// returning how many locale files (languages) there are
size_t Size();
// it sets whether we should parse locale files as utf-8 files
// default: false
void UTF8(bool utf);
// substitution characters
// !! w przyszlosci bedzie zmiana nazw tych metod i bedzie ich wiecej
// !! bedzie zmiana do url, do wielkosci liter (male/duze) i moze inne
wchar_t Subst(wchar_t c);
void Subst(std::wstring & str);
private:
void AddLocale(Lang lang);
void ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file);
bool ReadFile(const char * dir, Lang lang, const char * file);
void AddLocale(size_t lang);
void ReadFile(const char * dir, const char * dir_def, size_t lang, const char * file);
bool ReadFile(const char * dir, size_t lang, const char * file);
void ReadSubstTable(const char * dir, const char * dir_def);
bool ReadSubstTable(const char * dir);
// messages vector<via Lang>
// locale files
// we have at least one item "en"
std::vector<std::wstring> locale_files;
// messages vector<via language>
// this table has the same size as locale_files (at least one item)
std::vector<ConfParser::TableSingle> loc_tab;
// these tables are used to change url characters
@@ -78,11 +99,13 @@ private:
ConfParser loc_parser;
std::string locale_filea;
std::string file_name;
std::wstring empty;
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;
Lang default_lang;
Lang current_lang;
size_t default_lang; // index to loc_tab
size_t current_lang; // index to loc_tab
bool input_as_utf8;
};