2010-01-28 16:39:01 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2010-01-28 16:39:01 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-12 03:24:08 +01:00
|
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
2010-01-28 16:39:01 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_templates_locale
|
|
|
|
#define headerfile_winix_templates_locale
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-01-12 03:24:08 +01:00
|
|
|
#include "confparser/confparser.h"
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Locale
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Locale();
|
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
// 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);
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsKey(const std::wstring & key) const;
|
2011-02-24 18:06:12 +01:00
|
|
|
bool IsKey(const std::wstring & key, size_t lang) const;
|
|
|
|
|
2011-04-16 10:42:22 +02:00
|
|
|
// 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;
|
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// returning specific 'key'
|
|
|
|
const std::wstring & Get(const wchar_t * key);
|
|
|
|
const std::wstring & Get(const wchar_t * key, size_t lang);
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & Get(const std::wstring & key) const;
|
2011-02-24 18:06:12 +01:00
|
|
|
const std::wstring & Get(const std::wstring & key, size_t lang) const;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2011-04-16 10:42:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// setting/getting current language
|
|
|
|
// default: 0
|
|
|
|
void SetLang(size_t lang);
|
|
|
|
size_t GetLang() const;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
// which language is used instead if there is no a key in an other language
|
2011-02-24 18:06:12 +01:00
|
|
|
// default: 0
|
|
|
|
void SetLangDef(size_t lang);
|
|
|
|
size_t GetLangDef() const;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// 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;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// return a file name for the 'lang'
|
|
|
|
const std::wstring & LangToFileName(size_t lang) const;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// returning how many locale files (languages) there are
|
2011-04-16 10:42:22 +02:00
|
|
|
size_t Size() const;
|
2011-02-24 18:06:12 +01:00
|
|
|
|
|
|
|
// it sets whether we should parse locale files as utf-8 files
|
|
|
|
// default: false
|
2010-11-21 01:19:17 +01:00
|
|
|
void UTF8(bool utf);
|
|
|
|
|
2011-08-30 00:23:54 +02:00
|
|
|
// url substitution characters
|
|
|
|
wchar_t UrlSubst(wchar_t c);
|
|
|
|
void UrlSubst(std::wstring & str);
|
|
|
|
|
|
|
|
// changing to small/capital letters
|
|
|
|
wchar_t ToSmall(wchar_t c);
|
|
|
|
void ToSmall(std::wstring & str);
|
|
|
|
wchar_t ToCapital(wchar_t c);
|
|
|
|
void ToCapital(std::wstring & str);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2012-01-21 21:51:13 +01:00
|
|
|
// comparing two characters/strings
|
|
|
|
// return a value less than zero if c1<c2, zero if c1==c2, value greater than 0 if c1>c2
|
|
|
|
int Compare(wchar_t c1, wchar_t c2);
|
|
|
|
int Compare(const std::wstring & str1, const std::wstring & str2);
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
private:
|
|
|
|
|
2011-08-30 00:23:54 +02:00
|
|
|
// struct to used for substitution
|
|
|
|
struct SubstItem
|
|
|
|
{
|
|
|
|
wchar_t from, to;
|
2012-01-21 21:51:13 +01:00
|
|
|
int index;
|
|
|
|
|
|
|
|
SubstItem() { from = to = 0; index = 0; }
|
2011-08-30 00:23:54 +02:00
|
|
|
bool operator<(const SubstItem & arg) const { return from < arg.from; }
|
|
|
|
};
|
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
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);
|
2010-11-21 01:19:17 +01:00
|
|
|
void ReadSubstTable(const char * dir, const char * dir_def);
|
|
|
|
bool ReadSubstTable(const char * dir);
|
2011-08-30 00:23:54 +02:00
|
|
|
void CreateSubstVector(std::vector<SubstItem> & vect, const std::wstring & tab1, const std::wstring & tab2);
|
2012-01-21 21:51:13 +01:00
|
|
|
void CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<std::wstring> & tab);
|
|
|
|
size_t SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val);
|
2011-08-30 00:23:54 +02:00
|
|
|
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2011-02-24 18:06:12 +01:00
|
|
|
// 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)
|
2012-01-12 03:24:08 +01:00
|
|
|
std::vector<PT::Space::TableSingle> loc_tab;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2011-04-16 10:42:22 +02:00
|
|
|
// messages vector<via language>
|
|
|
|
// this table has the same size as locale_files (at least one item)
|
2012-01-12 03:24:08 +01:00
|
|
|
std::vector<PT::Space::Table> loc_tab_multi;
|
2011-04-16 10:42:22 +02:00
|
|
|
|
2011-08-30 00:23:54 +02:00
|
|
|
// vectors of characters substitution (sort by 'from')
|
|
|
|
std::vector<SubstItem> subst_url;
|
|
|
|
std::vector<SubstItem> subst_smalllet; // changing from small to capital
|
|
|
|
std::vector<SubstItem> subst_capitallet; // changing from capital to small
|
2012-01-21 21:51:13 +01:00
|
|
|
std::vector<SubstItem> subst_sort; // local characters for comparison
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
|
2012-01-12 03:24:08 +01:00
|
|
|
PT::Space space;
|
|
|
|
PT::ConfParser loc_parser;
|
2011-02-24 18:06:12 +01:00
|
|
|
std::string locale_filea;
|
2010-01-28 16:39:01 +01:00
|
|
|
std::string file_name;
|
2011-02-24 18:06:12 +01:00
|
|
|
std::wstring key_str;
|
|
|
|
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
|
2011-04-16 10:42:22 +02:00
|
|
|
const std::vector<std::wstring> empty_list; // the same as above
|
2010-11-21 01:19:17 +01:00
|
|
|
std::string adir1, adir2;
|
2011-02-24 18:06:12 +01:00
|
|
|
size_t default_lang; // index to loc_tab
|
|
|
|
size_t current_lang; // index to loc_tab
|
2010-11-21 01:19:17 +01:00
|
|
|
bool input_as_utf8;
|
2010-01-28 16:39:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|