/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2010-2012, Tomasz Sowa * All rights reserved. * */ #ifndef headerfile_winix_templates_locale #define headerfile_winix_templates_locale #include #include #include "space/spaceparser.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 & 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 & GetList(const std::wstring & key) const; const std::vector & 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); // comparing two characters/strings // return a value less than zero if c1c2 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 { wchar_t from, to; int index; SubstItem() { from = to = 0; index = 0; } 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 & vect, const std::wstring & tab1, const std::wstring & tab2); void CreateSubstSortVector(std::vector & vect, std::vector & tab); size_t SubstFindIndex(const std::vector & vect, wchar_t val); wchar_t SubstFind(const std::vector & vect, wchar_t val); // locale files // we have at least one item "en" std::vector locale_files; // messages vector // this table has the same size as locale_files (at least one item) std::vector loc_tab; // messages vector // this table has the same size as locale_files (at least one item) std::vector loc_tab_multi; // vectors of characters substitution (sort by 'from') std::vector subst_url; std::vector subst_smalllet; // changing from small to capital std::vector subst_capitallet; // changing from capital to small std::vector subst_sort; // local characters for comparison PT::Space space; PT::SpaceParser 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 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