140 lines
4.1 KiB
C++
Executable File
140 lines
4.1 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;
|
|
|
|
|
|
|
|
// how many languages we have
|
|
size_t Size();
|
|
|
|
// 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);
|
|
|
|
// 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(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);
|
|
|
|
// 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;
|
|
|
|
// messages vector<via language>
|
|
// this table has the same size as locale_files (at least one item)
|
|
std::vector<ConfParser::Table> loc_tab_multi;
|
|
|
|
// these tables are used to change url characters
|
|
std::wstring subst_original;
|
|
std::wstring subst_changeto;
|
|
|
|
|
|
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
|