changed: removed Languages::Land enum
now we set the languages in the config file: option locale_files, sample: locale_files = ( en, pl ) it represents the name of locale files (those from locale_dir directory) renamed config option: locale to locale_default git-svn-id: svn://ttmath.org/publicrep/winix/trunk@722 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
15487b347f
commit
ba63c8c661
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -164,9 +164,10 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||
html_filter_orphans_lang_str = AText(L"html_filter_orphans_lang", L"pl");
|
||||
html_filter_orphans_mode_str = AText(L"html_filter_orphans_mode_str", L"nbsp");
|
||||
|
||||
locale_str = Text(L"locale", L"en");
|
||||
locale_dir = Text(L"locale_dir");
|
||||
locale_dir_default = Text(L"locale_dir_default");
|
||||
locale_default = Text(L"locale_default");
|
||||
ListText(L"locale_files", locale_files);
|
||||
|
||||
title_separator = Text(L"title_separator", L" / ");
|
||||
|
||||
|
@ -179,7 +180,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||
|
||||
plugins_dir = Text(L"plugins_dir", L"/usr/local/winix/plugins");
|
||||
NoLastSlash(plugins_dir);
|
||||
parser.ListText(L"plugins", plugin_file);
|
||||
ListText(L"plugins", plugin_file);
|
||||
|
||||
time_zone_offset = Int(L"time_zone_offset", 0);
|
||||
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
|
||||
|
@ -191,6 +192,9 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::SetAdditionalVariables()
|
||||
{
|
||||
SetHttpHost(base_url, base_url_http_host);
|
||||
|
@ -210,10 +214,40 @@ void Config::SetAdditionalVariables()
|
|||
html_filter_orphans_mode = HTMLFilter::orphan_160space;
|
||||
else
|
||||
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
|
||||
|
||||
CheckLocale();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Config::CheckLocale()
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if( locale_files.empty() )
|
||||
locale_files.push_back(L"en");
|
||||
|
||||
if( locale_default.empty() )
|
||||
locale_default = locale_files[0];
|
||||
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
{
|
||||
if( locale_files[i] == locale_default )
|
||||
{
|
||||
locale_default_index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
// we have at least one item
|
||||
locale_default = locale_files[0];
|
||||
locale_default_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Config::SetHttpHost(const std::wstring & in, std::wstring & out)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -229,16 +229,24 @@ public:
|
|||
// default: /usr/local/bin/convert
|
||||
std::wstring convert_cmd;
|
||||
|
||||
// locale: en, pl
|
||||
// default: en
|
||||
std::wstring locale_str;
|
||||
|
||||
// directory with locale files
|
||||
std::wstring locale_dir;
|
||||
|
||||
// directory with default locale files (those from winix)
|
||||
std::wstring locale_dir_default;
|
||||
|
||||
// locale files (e.g. "en", "pl")
|
||||
// default: only one item: en
|
||||
std::vector<std::wstring> locale_files;
|
||||
|
||||
// default locale
|
||||
// default: the first item from locale_files
|
||||
std::wstring locale_default;
|
||||
|
||||
// default locale - index to locale_files
|
||||
// not available in config -- set automatically based on locale_default
|
||||
size_t locale_default_index;
|
||||
|
||||
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
|
||||
std::wstring base_server;
|
||||
|
||||
|
@ -337,6 +345,7 @@ private:
|
|||
void AssignValues(bool stdout_is_closed);
|
||||
void SetHttpHost(const std::wstring & in, std::wstring & out);
|
||||
void SetAdditionalVariables();
|
||||
void CheckLocale();
|
||||
|
||||
ConfParser parser;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void Notify::ReadTemplates()
|
|||
return;
|
||||
}
|
||||
|
||||
patterns.resize(static_cast<size_t>(Locale::lang_unknown));
|
||||
patterns.resize(TemplatesFunctions::locale.Size());
|
||||
|
||||
for(size_t i=0 ; i<patterns.size() ; ++i)
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ void Notify::ReadTemplates()
|
|||
patterns[i][a].Directory(config->txt_templates_dir, config->txt_templates_dir_default);
|
||||
patterns[i][a].ParseFile(templates_names[a]);
|
||||
|
||||
TemplatesFunctions::locale_filter.Filter(patterns[i][a], TemplatesFunctions::locale, static_cast<Locale::Lang>(i));
|
||||
TemplatesFunctions::locale_filter.Filter(patterns[i][a], TemplatesFunctions::locale, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ struct NotifyUserMsg
|
|||
{
|
||||
std::wstring name;
|
||||
std::wstring email;
|
||||
Locale::Lang lang;
|
||||
size_t lang;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -100,10 +100,7 @@ bool res = false;
|
|||
{
|
||||
msg.name = i->name;
|
||||
msg.email = i->email;
|
||||
msg.lang = Locale::StrToLang(config->locale_str); // !! bedzie osobno dla kazdego uzytkownika
|
||||
|
||||
if( msg.lang == Locale::lang_unknown )
|
||||
msg.lang = Locale::lang_en;
|
||||
msg.lang = config->locale_default_index; // !! bedzie osobno dla kazdego uzytkownika
|
||||
|
||||
notify_user.insert(notify_user.end(), msg);
|
||||
res = true;
|
||||
|
@ -163,7 +160,7 @@ void NotifyThread::SendMail()
|
|||
{
|
||||
notify_stream.Clear();
|
||||
|
||||
size_t lang_index = static_cast<size_t>(TemplatesNotifyFunctions::notify_user_msg.lang);
|
||||
size_t lang_index = TemplatesNotifyFunctions::notify_user_msg.lang;
|
||||
size_t template_index = TemplatesNotifyFunctions::notify_msg.template_index;
|
||||
|
||||
if( lang_index >= patterns.size() )
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -175,6 +175,7 @@ last.o: ../core/basethread.h ../core/sessionmanager.h
|
|||
last.o: ../core/sessioncontainer.h ../core/system.h ../core/lastcontainer.h
|
||||
last.o: ../core/request.h ../core/misc.h
|
||||
locale.o: locale.h ../core/confparser.h ../core/log.h ../core/textstream.h
|
||||
locale.o: ../../ezc/src/utf8.h
|
||||
localefilter.o: localefilter.h locale.h ../core/confparser.h
|
||||
localefilter.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h
|
||||
localefilter.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
|
|
|
@ -23,27 +23,27 @@ void IndexPatterns::SetConfig(Config * pconfig)
|
|||
config = pconfig;
|
||||
}
|
||||
|
||||
|
||||
void IndexPatterns::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
|
||||
{
|
||||
ezc_fun = fun;
|
||||
}
|
||||
|
||||
Ezc::Pattern * IndexPatterns::GetPattern(const std::wstring & file, Locale::Lang lang)
|
||||
|
||||
Ezc::Pattern * IndexPatterns::GetPattern(const std::wstring & file, size_t lang)
|
||||
{
|
||||
Tab::iterator i = tab.find(file);
|
||||
|
||||
if( i == tab.end() )
|
||||
return 0;
|
||||
|
||||
size_t index = static_cast<size_t>(lang);
|
||||
|
||||
if( index >= i->second.patterns.size() )
|
||||
if( lang >= i->second.patterns.size() )
|
||||
{
|
||||
log << log1 << "IndexPatterns: there is no a pattern: " << file << ", for lang: " << index << logend;
|
||||
log << log1 << "IndexPatterns: there is no a pattern: " << file << ", for lang: " << lang << logend;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return &i->second.patterns[index];
|
||||
return &i->second.patterns[lang];
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ void IndexPatterns::AddFileName(const std::wstring & file)
|
|||
void IndexPatterns::ReadPattern(Tab::iterator & iter, Locale & locale, LocaleFilter & locale_filter, bool delete_white)
|
||||
{
|
||||
size_t i;
|
||||
size_t len = Locale::lang_unknown;
|
||||
size_t len = locale.Size();
|
||||
Template & templ = iter->second;
|
||||
|
||||
templ.patterns.resize(len);
|
||||
|
@ -96,7 +96,7 @@ void IndexPatterns::ReadPattern(Tab::iterator & iter, Locale & locale, LocaleFil
|
|||
if( ezc_fun )
|
||||
templ.patterns[i].CacheFunctions(*ezc_fun);
|
||||
|
||||
locale_filter.Filter(templ.patterns[i], locale, static_cast<Locale::Lang>(i));
|
||||
locale_filter.Filter(templ.patterns[i], locale, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
void SetEzcFunctions(TemplatesFunctions::EzcFun * fun);
|
||||
|
||||
// can return null pointer if there is not such a pattern
|
||||
Ezc::Pattern * GetPattern(const std::wstring & file, Locale::Lang lang);
|
||||
Ezc::Pattern * GetPattern(const std::wstring & file, size_t lang);
|
||||
void AddPattern(const std::wstring & file, Locale & locale, LocaleFilter & locale_filter, bool delete_white);
|
||||
void AddPatternIfNotExists(const std::wstring & file, Locale & locale, LocaleFilter & locale_filter, bool delete_white);
|
||||
|
||||
|
|
|
@ -2,42 +2,46 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "locale.h"
|
||||
#include "core/log.h"
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
|
||||
Locale::Locale()
|
||||
{
|
||||
loc_tab.resize(lang_unknown);
|
||||
default_lang = lang_en;
|
||||
current_lang = lang_en;
|
||||
locale_files.push_back(L"en");
|
||||
loc_tab.resize(locale_files.size());
|
||||
|
||||
default_lang = 0;
|
||||
current_lang = 0;
|
||||
input_as_utf8 = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::AddLocale(Lang lang)
|
||||
void Locale::SetLocaleFiles(const std::vector<std::wstring> & files)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = loc_parser.table_single.begin();
|
||||
locale_files = files;
|
||||
|
||||
for( ; i != loc_parser.table_single.end() ; ++i)
|
||||
loc_tab[lang][i->first] = i->second;
|
||||
if( locale_files.empty() )
|
||||
locale_files.push_back(L"en");
|
||||
|
||||
loc_tab.resize(locale_files.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file)
|
||||
|
||||
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, size_t lang, const char * file)
|
||||
{
|
||||
if( static_cast<size_t>(lang) >= loc_tab.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
if( lang >= loc_tab.size() )
|
||||
return;
|
||||
}
|
||||
|
||||
loc_tab[lang].clear();
|
||||
bool read = false;
|
||||
|
@ -53,13 +57,13 @@ void Locale::ReadFile(const char * dir, const char * dir_def, Lang lang, const c
|
|||
}
|
||||
|
||||
|
||||
bool Locale::ReadFile(const char * dir, Lang lang, const char * file)
|
||||
bool Locale::ReadFile(const char * dir, size_t lang, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
file_name = dir;
|
||||
file_name += '/';
|
||||
file_name += file;
|
||||
file_name += file; // !! dodac sprawdzenie poprawnosci nazwy pliku (czy nie zawiera specjalnych znakow)
|
||||
|
||||
loc_parser.SplitSingle(true);
|
||||
loc_parser.UTF8(input_as_utf8);
|
||||
|
@ -75,6 +79,16 @@ return read;
|
|||
}
|
||||
|
||||
|
||||
|
||||
void Locale::AddLocale(size_t lang)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = loc_parser.table_single.begin();
|
||||
|
||||
for( ; i != loc_parser.table_single.end() ; ++i)
|
||||
loc_tab[lang][i->first] = i->second;
|
||||
}
|
||||
|
||||
|
||||
void Locale::ReadSubstTable(const char * dir, const char * dir_def)
|
||||
{
|
||||
bool read = false;
|
||||
|
@ -119,8 +133,11 @@ return read;
|
|||
|
||||
void Locale::Read(const char * dir, const char * dir_def)
|
||||
{
|
||||
ReadFile(dir, dir_def, lang_pl, "pl");
|
||||
ReadFile(dir, dir_def, lang_en, "en");
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
{
|
||||
Ezc::WideToUTF8(locale_files[i], locale_filea);
|
||||
ReadFile(dir, dir_def, i, locale_filea.c_str());
|
||||
}
|
||||
|
||||
ReadSubstTable(dir, dir_def);
|
||||
|
||||
|
@ -140,7 +157,7 @@ void Locale::Read(const std::string & dir, const std::string & dir_def)
|
|||
|
||||
void Locale::Read(const wchar_t * dir, const wchar_t * dir_def)
|
||||
{
|
||||
AssignString(dir, adir1);
|
||||
Ezc::WideToUTF8(dir, adir1);
|
||||
|
||||
if( !dir_def )
|
||||
{
|
||||
|
@ -148,7 +165,7 @@ void Locale::Read(const wchar_t * dir, const wchar_t * dir_def)
|
|||
}
|
||||
else
|
||||
{
|
||||
AssignString(dir_def, adir2);
|
||||
Ezc::WideToUTF8(dir_def, adir2);
|
||||
Read(adir1.c_str(), adir2.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -156,28 +173,57 @@ void Locale::Read(const wchar_t * dir, const wchar_t * dir_def)
|
|||
|
||||
void Locale::Read(const std::wstring & dir, const std::wstring & dir_def)
|
||||
{
|
||||
Read(dir.c_str(), dir_def.c_str());
|
||||
if( dir_def.empty() )
|
||||
Read(dir.c_str());
|
||||
else
|
||||
Read(dir.c_str(), dir_def.c_str());
|
||||
}
|
||||
|
||||
|
||||
void Locale::SetLang(Lang lang)
|
||||
void Locale::SetLang(size_t lang)
|
||||
{
|
||||
current_lang = lang;
|
||||
|
||||
if( current_lang >= loc_tab.size() )
|
||||
current_lang = loc_tab.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
Locale::Lang Locale::GetLang()
|
||||
size_t Locale::GetLang() const
|
||||
{
|
||||
return current_lang;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::SetLangDef(Lang lang)
|
||||
void Locale::SetLangDef(size_t lang)
|
||||
{
|
||||
default_lang = lang_en;
|
||||
default_lang = lang;
|
||||
|
||||
if( default_lang >= loc_tab.size() )
|
||||
default_lang = loc_tab.size() - 1;
|
||||
}
|
||||
|
||||
size_t Locale::GetLangDef() const
|
||||
{
|
||||
return default_lang;
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const wchar_t * key)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKey(key_str);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const wchar_t * key, size_t lang)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKey(key_str, lang);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key) const
|
||||
{
|
||||
|
@ -185,15 +231,12 @@ bool Locale::IsKey(const std::wstring & key) const
|
|||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key, Lang lang) const
|
||||
bool Locale::IsKey(const std::wstring & key, size_t lang) const
|
||||
{
|
||||
if( static_cast<size_t>(lang) >= loc_tab.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
if( lang >= loc_tab.size() )
|
||||
return false;
|
||||
}
|
||||
|
||||
// looking in the lang language
|
||||
// looking in the 'lang' language
|
||||
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
|
||||
|
||||
if( i != loc_tab[lang].end() )
|
||||
|
@ -203,11 +246,8 @@ bool Locale::IsKey(const std::wstring & key, Lang lang) const
|
|||
return false;
|
||||
|
||||
|
||||
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
if( default_lang >= loc_tab.size() )
|
||||
return false;
|
||||
}
|
||||
|
||||
// looking in a default language
|
||||
i = loc_tab[default_lang].find(key);
|
||||
|
@ -220,6 +260,21 @@ bool Locale::IsKey(const std::wstring & key, Lang lang) const
|
|||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key)
|
||||
{
|
||||
key_str = key;
|
||||
return Get(key_str);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key, size_t lang)
|
||||
{
|
||||
key_str = key;
|
||||
return Get(key_str, lang);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const std::wstring & key) const
|
||||
{
|
||||
return Get(key, current_lang);
|
||||
|
@ -227,15 +282,12 @@ const std::wstring & Locale::Get(const std::wstring & key) const
|
|||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const std::wstring & key, Lang lang) const
|
||||
const std::wstring & Locale::Get(const std::wstring & key, size_t lang) const
|
||||
{
|
||||
if( static_cast<size_t>(lang) >= loc_tab.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
if( lang >= loc_tab.size() )
|
||||
return empty;
|
||||
}
|
||||
|
||||
// looking in the lang language
|
||||
// looking in the 'lang' language
|
||||
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
|
||||
|
||||
if( i != loc_tab[lang].end() )
|
||||
|
@ -245,11 +297,8 @@ const std::wstring & Locale::Get(const std::wstring & key, Lang lang) const
|
|||
return empty;
|
||||
|
||||
|
||||
if( static_cast<size_t>(default_lang) >= loc_tab.size() )
|
||||
{
|
||||
// ops, something wrong
|
||||
if( default_lang >= loc_tab.size() )
|
||||
return empty;
|
||||
}
|
||||
|
||||
// looking in a default language
|
||||
i = loc_tab[default_lang].find(key);
|
||||
|
@ -262,44 +311,29 @@ const std::wstring & Locale::Get(const std::wstring & key, Lang lang) const
|
|||
}
|
||||
|
||||
|
||||
Locale::Lang Locale::StrToLang(const std::wstring & str)
|
||||
size_t Locale::FileNameToLang(const std::wstring & str) const
|
||||
{
|
||||
if( str == L"en" )
|
||||
return lang_en;
|
||||
else
|
||||
if( str == L"pl" )
|
||||
return lang_pl;
|
||||
|
||||
return lang_unknown;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const wchar_t * Locale::LangToStr(Lang lang)
|
||||
{
|
||||
static wchar_t buffer[30];
|
||||
size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
|
||||
|
||||
switch(lang)
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
{
|
||||
case lang_en:
|
||||
swprintf(buffer, buffer_len, L"en");
|
||||
break;
|
||||
|
||||
case lang_pl:
|
||||
swprintf(buffer, buffer_len, L"pl");
|
||||
break;
|
||||
|
||||
default:
|
||||
swprintf(buffer, buffer_len, L"unknown");
|
||||
if( locale_files[i] == str )
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
return buffer;
|
||||
// we have at least one item "en"
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::LangToFileName(size_t lang) const
|
||||
{
|
||||
if( lang >=locale_files.size() )
|
||||
return empty;
|
||||
|
||||
return locale_files[lang];
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::Size()
|
||||
{
|
||||
return loc_tab.size();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -20,56 +20,77 @@ class Locale
|
|||
{
|
||||
public:
|
||||
|
||||
// !! pozbyc sie tego enuma
|
||||
// niech wybieranie ilosci locali (ile jezykow) bedzie w pliku konfiguracyjnym
|
||||
enum Lang
|
||||
{
|
||||
lang_en = 0,
|
||||
lang_pl,
|
||||
|
||||
lang_unknown // should be last
|
||||
};
|
||||
|
||||
Locale();
|
||||
|
||||
void Read(const char * dir, const char * dir_def = 0);
|
||||
void Read(const std::string & dir, const std::string & dir_def);
|
||||
// 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);
|
||||
|
||||
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
|
||||
void Read(const std::wstring & dir, const std::wstring & dir_def);
|
||||
// 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, Lang lang) const;
|
||||
const std::wstring & Get(const std::wstring & key) const;
|
||||
const std::wstring & Get(const std::wstring & key, Lang lang) const;
|
||||
bool IsKey(const std::wstring & key, size_t lang) const;
|
||||
|
||||
// default is english
|
||||
void SetLang(Lang lang);
|
||||
Lang GetLang();
|
||||
// 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;
|
||||
|
||||
// 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: lang_en
|
||||
void SetLangDef(Lang lang);
|
||||
// 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;
|
||||
|
||||
static Lang StrToLang(const std::wstring & str);
|
||||
static const wchar_t * LangToStr(Lang lang);
|
||||
// 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();
|
||||
|
||||
// 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(Lang lang);
|
||||
void ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file);
|
||||
bool ReadFile(const char * dir, Lang lang, const char * file);
|
||||
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);
|
||||
|
||||
// messages vector<via Lang>
|
||||
// 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;
|
||||
|
||||
// these tables are used to change url characters
|
||||
|
@ -78,11 +99,13 @@ private:
|
|||
|
||||
|
||||
ConfParser loc_parser;
|
||||
std::string locale_filea;
|
||||
std::string file_name;
|
||||
std::wstring empty;
|
||||
std::wstring key_str;
|
||||
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
|
||||
std::string adir1, adir2;
|
||||
Lang default_lang;
|
||||
Lang current_lang;
|
||||
size_t default_lang; // index to loc_tab
|
||||
size_t current_lang; // index to loc_tab
|
||||
bool input_as_utf8;
|
||||
};
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ void LocaleFilter::FilterText(Ezc::Item & item)
|
|||
|
||||
|
||||
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, Locale::Lang lang_)
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_)
|
||||
{
|
||||
plocale = &locale;
|
||||
lang = lang_;
|
||||
|
|
|
@ -21,7 +21,7 @@ class LocaleFilter
|
|||
public:
|
||||
|
||||
LocaleFilter();
|
||||
void Filter(Ezc::Pattern & pattern, const Locale & locale, Locale::Lang lang_);
|
||||
void Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_);
|
||||
|
||||
private:
|
||||
void ReadKey();
|
||||
|
@ -33,7 +33,7 @@ private:
|
|||
wchar_t closing_mark; // default '}'
|
||||
|
||||
const Locale * plocale;
|
||||
Locale::Lang lang;
|
||||
size_t lang;
|
||||
std::wstring res;
|
||||
std::wstring key;
|
||||
std::wstring value;
|
||||
|
|
|
@ -172,24 +172,6 @@ return ckeditor_getparser.fun_num;
|
|||
|
||||
|
||||
|
||||
// those functions from here are used in the second thread too
|
||||
|
||||
|
||||
void ClearPatterns(Patterns & patterns, size_t len)
|
||||
{
|
||||
size_t loc, pat;
|
||||
|
||||
patterns.resize(Locale::lang_unknown);
|
||||
|
||||
for(loc=0 ; loc < static_cast<size_t>(Locale::lang_unknown) ; ++loc)
|
||||
{
|
||||
patterns[loc].resize(len);
|
||||
|
||||
for(pat=0 ; pat<len ; ++pat)
|
||||
patterns[loc][pat].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
|
|
@ -72,12 +72,11 @@ void Read(Patterns & patterns, size_t pat, Locale & locale, LocaleFilter & local
|
|||
patterns[i][pat].ParseFile(file);
|
||||
patterns[i][pat].CacheFunctions(ezc_fun);
|
||||
|
||||
locale_filter.Filter(patterns[i][pat], locale, static_cast<Locale::Lang>(i));
|
||||
locale_filter.Filter(patterns[i][pat], locale, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClearPatterns(Patterns & patterns, size_t len);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -54,7 +54,7 @@ Ezc::Pattern * content_for_function()
|
|||
return 0;
|
||||
}
|
||||
|
||||
const size_t loc_index = static_cast<size_t>(locale.GetLang());
|
||||
const size_t loc_index = locale.GetLang();
|
||||
const size_t fun_id = static_cast<size_t>(cur->request->function->id);
|
||||
|
||||
if( loc_index >= patterns_fun.size() || fun_id >= patterns_fun[loc_index].size() )
|
||||
|
@ -72,7 +72,7 @@ void content(Info & i)
|
|||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
||||
if( locale.GetLang() >= patterns.size() )
|
||||
{
|
||||
log << log1 << "Templates: there is no such a language in patterns" << logend;
|
||||
return;
|
||||
|
@ -464,14 +464,11 @@ void Templates::SetLocale()
|
|||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
Locale::Lang lang = Locale::StrToLang(config->locale_str);
|
||||
|
||||
if( lang != Locale::lang_unknown )
|
||||
locale.SetLang(lang);
|
||||
else
|
||||
locale.SetLang(Locale::lang_en);
|
||||
|
||||
locale.UTF8(config->utf8);
|
||||
locale.SetLocaleFiles(config->locale_files);
|
||||
// !! tutaj nie potrzeba ustawiac locali SetLang/SetLangDef (nie odczytujemy kluczy)
|
||||
locale.SetLang(config->locale_default_index); // !! w przyszlosci locale beda ustawiane dla kazdego uzytkownika osobno
|
||||
locale.SetLangDef(config->locale_default_index);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
}
|
||||
|
||||
|
@ -575,13 +572,31 @@ using namespace TemplatesFunctions;
|
|||
}
|
||||
|
||||
|
||||
|
||||
void Templates::ClearPatterns(TemplatesFunctions::Patterns & patterns, size_t len)
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
size_t loc, pat;
|
||||
|
||||
patterns.resize(locale.Size());
|
||||
|
||||
for(loc=0 ; loc < patterns.size() ; ++loc)
|
||||
{
|
||||
patterns[loc].resize(len);
|
||||
|
||||
for(pat=0 ; pat<len ; ++pat)
|
||||
patterns[loc][pat].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// index_patterns and patterns for items are not cleared here
|
||||
void Templates::ClearPatterns()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
TemplatesFunctions::ClearPatterns(patterns, pat_last);
|
||||
TemplatesFunctions::ClearPatterns(patterns_fun, functions->FunctionsSize());
|
||||
ClearPatterns(patterns, pat_last);
|
||||
ClearPatterns(patterns_fun, functions->FunctionsSize());
|
||||
}
|
||||
|
||||
|
||||
|
@ -590,7 +605,7 @@ void Templates::Generate()
|
|||
using namespace TemplatesFunctions;
|
||||
|
||||
// !! locale beda w zaleznosci od uzytkownika
|
||||
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
||||
if( locale.GetLang() >= patterns.size() )
|
||||
return;
|
||||
|
||||
Ezc::Pattern * index = 0;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
@ -397,6 +397,7 @@ private:
|
|||
void ReadFileFun(size_t index, const wchar_t * file);
|
||||
void ReadFunctionsTemplates();
|
||||
void SetLocale();
|
||||
void ClearPatterns(TemplatesFunctions::Patterns & patterns, size_t len);
|
||||
|
||||
TemplatesFunctions::EzcGen generator;
|
||||
std::wstring temp;
|
||||
|
|
|
@ -181,8 +181,6 @@ void winix_err_code(Info & i)
|
|||
|
||||
|
||||
|
||||
static std::wstring winix_error_key;
|
||||
|
||||
|
||||
void winix_is_err_in_locales(Info & i)
|
||||
{
|
||||
|
@ -190,9 +188,7 @@ wchar_t buff[40];
|
|||
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
|
||||
|
||||
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
|
||||
winix_error_key = buff;
|
||||
|
||||
i.res = locale.IsKey(winix_error_key);
|
||||
i.res = locale.IsKey(buff);
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,9 +198,7 @@ wchar_t buff[40];
|
|||
size_t buff_len = sizeof(buff) / sizeof(wchar_t);
|
||||
|
||||
swprintf(buff, buff_len, L"winix_err_%d", cur->request->status);
|
||||
winix_error_key = buff;
|
||||
|
||||
i.out << locale.Get(winix_error_key);
|
||||
i.out << locale.Get(buff);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue