added: winix functions: locale, timezone

changed: time zones -- now we have the daylight saving time
       different for each year (start, end)
added: config option: time_zone_id (size_t)
       time zone identifier for not logged users
       or for newly created accounts
       those identifiers you can see in etc/time_zones.conf file
       or by using timezone winix function with 'a' parameter (timezone/a) (!!IMPROVE ME NOT IMPLEMENTED YET)
       default: 34 (Coordinated Universal Time UTC+00:00)
added: config option: locale_default_id (size_t)
       locale for not logged users
       or for newly created accounts
added: config option: locale_max_id (size_t)
       a maximum value of a locale identifier
       default: 100 (maximum: 1000)
       each locale files should have its own identifier (in "winix_locale_id" field)
       from zero to this value
added: config option: time_zone_max_id (size_t)
       maximum value of a time zone identifier
       time zones with an id greater than this will be skipped
       default: 130 (maximum: 1000)
removed: config option: locale_default



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@852 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-06-26 23:19:19 +00:00
parent 54e6c07efc
commit b8ff5d4cfc
53 changed files with 4618 additions and 3053 deletions

View File

@@ -27,6 +27,11 @@ public:
// default one item: en
void SetLocaleFiles(const std::vector<std::wstring> & files);
// preparing locale_indices table
// if you change this values you should reload all locale files
void SetLocaleMaxId(size_t max_id);
// reading locales
// you should call SetLocaleFiles() beforehand
void Read(const char * dir, const char * dir_def = 0);
@@ -34,57 +39,67 @@ public:
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
void Read(const std::wstring & dir, const std::wstring & dir_def);
// returns true if a language with lang_id exists
bool HasLanguage(size_t lang_id);
// 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 wchar_t * key, size_t lang_id);
bool IsKey(const std::wstring & key) const;
bool IsKey(const std::wstring & key, size_t lang) const;
bool IsKey(const std::wstring & key, size_t lang_id) const;
// checking whether there is a 'key' in the lang language
// (default language is not checked)
bool IsKeyLang(const wchar_t * key, size_t lang);
bool IsKeyLang(const std::wstring & key, size_t lang) const;
bool IsKeyLang(const wchar_t * key, size_t lang_id);
bool IsKeyLang(const std::wstring & key, size_t lang_id) const;
// 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 wchar_t * key, size_t lang_id);
const std::wstring & Get(const std::wstring & key) const;
const std::wstring & Get(const std::wstring & key, size_t lang) const;
const std::wstring & Get(const std::wstring & key, size_t lang_id) const;
/*
lists
*/
// checking whether there is a 'key' in the lang language
// (default language is not checked)
bool IsKeyLangList(const wchar_t * key, size_t lang);
bool IsKeyLangList(const std::wstring & key, size_t lang) const;
// lists
bool IsKeyLangList(const wchar_t * key, size_t lang_id);
bool IsKeyLangList(const std::wstring & key, size_t lang_id) const;
const std::vector<std::wstring> & GetList(const std::wstring & key) const;
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang) const;
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang_id) const;
// setting/getting current language
// default: 0
void SetLang(size_t lang);
size_t GetLang() const;
void SetCurLang(size_t lang_id);
size_t GetCurLang() const;
// which language is used instead if there is no a key in an other language
// which language is used instead of if there is no a key in an other language
// default: 0
void SetLangDef(size_t lang);
size_t GetLangDef() const;
void SetDefLang(size_t lang_id);
size_t GetDefLang() 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;
// return a file name for the 'lang'
const std::wstring & LangToFileName(size_t lang) const;
// converting lang_id to an internal index
// returns an index from <0, Size()-1> or size_t(-1) if lang_id is incorrect
// it does it in O(1) time
size_t IdToIndex(size_t lang_id);
// returning how many locale files (languages) there are
// this is how many files were correctly parsed
// this is size of locale_tab table
size_t Size() const;
// accessing by an internal index
// internal index is from zero to Size()-1
const std::wstring & GetByIndex(const wchar_t * key, size_t index);
const std::wstring & GetByIndex(const std::wstring & key, size_t index) const;
// it sets whether we should parse locale files as utf-8 files
// default: false
void UTF8(bool utf);
@@ -104,8 +119,11 @@ public:
int Compare(wchar_t c1, wchar_t c2);
int Compare(const std::wstring & str1, const std::wstring & str2);
private:
// struct to used for substitution
struct SubstItem
{
@@ -116,36 +134,45 @@ private:
bool operator<(const SubstItem & arg) const { return from < arg.from; }
};
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 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 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);
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
const std::wstring * GetKeyInLanguage(const std::wstring & key, size_t lang_id) const;
const std::vector<std::wstring> * GetListInLanguage(const std::wstring & key, size_t lang_id) const;
// 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<PT::Space::TableSingle> loc_tab;
// a map from <0, config->locale_max_id> returning an index to
// locale_tab table (you should check whether the index is correct)
// with this we have O(1) time to find the specified locale
// and locale_tab doesn't have to be so large
std::vector<size_t> locale_indices;
// messages vector<via language>
// this table has the same size as locale_files (at least one item)
std::vector<PT::Space::Table> loc_tab_multi;
std::vector<PT::Space> locale_tab;
// default locale index (index to locale_indexes)
size_t default_lang;
// current locale index (index to locale_indexes)
size_t current_lang;
// vectors of characters substitution (sort by 'from')
std::vector<SubstItem> subst_url;
std::vector<SubstItem> subst_url; // for url substitution
std::vector<SubstItem> subst_smalllet; // changing from small to capital
std::vector<SubstItem> subst_capitallet; // changing from capital to small
std::vector<SubstItem> subst_sort; // local characters for comparison
PT::Space space;
PT::Space temp_space;
PT::SpaceParser loc_parser;
std::string locale_filea;
std::string file_name;
@@ -153,8 +180,6 @@ private:
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
const std::vector<std::wstring> empty_list; // the same as above
std::string adir1, adir2;
size_t default_lang; // index to loc_tab
size_t current_lang; // index to loc_tab
bool input_as_utf8;
};