152 lines
4.6 KiB
C++
Executable File
152 lines
4.6 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_winix_templates_locale
|
|
#define headerfile_winix_templates_locale
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include "core/confparser.h"
|
|
|
|
|
|
|
|
class Locale
|
|
{
|
|
public:
|
|
|
|
Locale();
|
|
|
|
// 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);
|
|
bool IsKey(const std::wstring & key) const;
|
|
bool IsKey(const std::wstring & key, size_t lang) 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;
|
|
|
|
// 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;
|
|
|
|
|
|
/*
|
|
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;
|
|
|
|
|
|
|
|
// 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: 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;
|
|
|
|
// 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() const;
|
|
|
|
// it sets whether we should parse locale files as utf-8 files
|
|
// default: false
|
|
void UTF8(bool utf);
|
|
|
|
// 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);
|
|
|
|
private:
|
|
|
|
// struct to used for substitution
|
|
struct SubstItem
|
|
{
|
|
wchar_t from, to;
|
|
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 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);
|
|
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
|
|
|
|
// 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<Space::TableSingle> loc_tab;
|
|
|
|
// messages vector<via language>
|
|
// this table has the same size as locale_files (at least one item)
|
|
std::vector<Space::Table> loc_tab_multi;
|
|
|
|
// 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
|
|
|
|
|
|
Space space;
|
|
ConfParser 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)
|
|
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;
|
|
};
|
|
|
|
|
|
#endif
|