added: winix functions: locale, timezone
changed: time zones -- now we have the daylight saving time
different for each year (start, end)
added: config option: time_zone_id (size_t)
time zone identifier for not logged users
or for newly created accounts
those identifiers you can see in etc/time_zones.conf file
or by using timezone winix function with 'a' parameter (timezone/a) (!!IMPROVE ME NOT IMPLEMENTED YET)
default: 34 (Coordinated Universal Time UTC+00:00)
added: config option: locale_default_id (size_t)
locale for not logged users
or for newly created accounts
added: config option: locale_max_id (size_t)
a maximum value of a locale identifier
default: 100 (maximum: 1000)
each locale files should have its own identifier (in "winix_locale_id" field)
from zero to this value
added: config option: time_zone_max_id (size_t)
maximum value of a time zone identifier
time zones with an id greater than this will be skipped
default: 130 (maximum: 1000)
removed: config option: locale_default
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@852 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,16 +10,13 @@
|
||||
#include <algorithm>
|
||||
#include "locale.h"
|
||||
#include "core/log.h"
|
||||
#include "core/misc.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
|
||||
Locale::Locale()
|
||||
{
|
||||
locale_files.push_back(L"en");
|
||||
loc_tab.resize(locale_files.size());
|
||||
loc_tab_multi.resize(locale_files.size());
|
||||
|
||||
default_lang = 0;
|
||||
current_lang = 0;
|
||||
input_as_utf8 = false;
|
||||
@@ -29,55 +26,75 @@ Locale::Locale()
|
||||
void Locale::SetLocaleFiles(const std::vector<std::wstring> & files)
|
||||
{
|
||||
locale_files = files;
|
||||
|
||||
if( locale_files.empty() )
|
||||
locale_files.push_back(L"en");
|
||||
|
||||
loc_tab.resize(locale_files.size());
|
||||
loc_tab_multi.resize(locale_files.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, size_t lang, const char * file)
|
||||
void Locale::SetLocaleMaxId(size_t max_id)
|
||||
{
|
||||
if( lang >= loc_tab.size() )
|
||||
return;
|
||||
if( max_id > 1000 )
|
||||
{
|
||||
max_id = 1000;
|
||||
log << log1 << "Locale: locale_max_id is too big (changed to 1000)" << logend;
|
||||
}
|
||||
|
||||
loc_tab[lang].clear();
|
||||
bool read = false;
|
||||
size_t old_size = locale_indices.size();
|
||||
locale_indices.resize(max_id + 1);
|
||||
|
||||
if( dir_def && ReadFile(dir_def, lang, file) )
|
||||
read = true;
|
||||
|
||||
if( dir && ReadFile(dir, lang, file) )
|
||||
read = true;
|
||||
|
||||
if( !read )
|
||||
log << log1 << "Locale: can't open locale's file: " << file << logend;
|
||||
for(size_t i=old_size ; i<locale_indices.size() ; ++i)
|
||||
locale_indices[i] = size_t(-1);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::ReadFile(const char * dir, size_t lang, const char * file)
|
||||
|
||||
|
||||
bool Locale::HasLanguage(size_t lang_id)
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
return locale_indices[lang_id] < locale_tab.size();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
temp_space.Clear();
|
||||
|
||||
if( dir_def && ReadFile(dir_def, file) )
|
||||
read = true;
|
||||
|
||||
if( dir && ReadFile(dir, file) )
|
||||
read = true;
|
||||
|
||||
if( read )
|
||||
AddLocale(file);
|
||||
else
|
||||
log << log1 << "Locale: can't open locale's file: " << file << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::ReadFile(const char * dir, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
file_name = dir;
|
||||
file_name += '/';
|
||||
file_name += file; // !! dodac sprawdzenie poprawnosci nazwy pliku (czy nie zawiera specjalnych znakow)
|
||||
file_name += file;
|
||||
|
||||
loc_parser.SplitSingle(true);
|
||||
loc_parser.UTF8(input_as_utf8);
|
||||
loc_parser.SetSpace(space);
|
||||
loc_parser.SetSpace(temp_space);
|
||||
|
||||
PT::SpaceParser::Status status = loc_parser.Parse(file_name);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
read = true;
|
||||
AddLocale(lang);
|
||||
log << log3 << "Locale: read locale from: " << file_name << logend;
|
||||
}
|
||||
else
|
||||
@@ -91,22 +108,31 @@ return read;
|
||||
|
||||
|
||||
|
||||
void Locale::AddLocale(size_t lang)
|
||||
void Locale::AddLocale(const char * file)
|
||||
{
|
||||
PT::Space::TableSingle::iterator i = space.table_single.begin();
|
||||
std::wstring * id_str = temp_space.GetValue(L"winix_locale_id");
|
||||
|
||||
for( ; i != space.table_single.end() ; ++i)
|
||||
loc_tab[lang][i->first] = i->second;
|
||||
if( !id_str )
|
||||
{
|
||||
log << log1 << "Locale: winix_locale_id field should be defined in locale file: "
|
||||
<< file << " (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t id = (size_t)Tol(*id_str);
|
||||
|
||||
// lists
|
||||
PT::Space::Table::iterator i2 = space.table.begin();
|
||||
if( id >= locale_indices.size() )
|
||||
{
|
||||
log << log1 << "Locale: locale identifier is greater than locale_max_id (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
for( ; i2 != space.table.end() ; ++i2)
|
||||
loc_tab_multi[lang][i2->first] = i2->second;
|
||||
locale_tab.push_back(temp_space);
|
||||
locale_indices[id] = locale_tab.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::ReadSubstTable(const char * dir, const char * dir_def)
|
||||
{
|
||||
bool read = false;
|
||||
@@ -137,14 +163,15 @@ bool read = false;
|
||||
|
||||
loc_parser.SplitSingle(true);
|
||||
loc_parser.UTF8(input_as_utf8);
|
||||
loc_parser.SetSpace(temp_space);
|
||||
|
||||
if( loc_parser.Parse(file_name) == PT::SpaceParser::ok )
|
||||
{
|
||||
read = true;
|
||||
CreateSubstVector(subst_url, space.table_single[L"url_original"], space.table_single[L"url_changeto"]);
|
||||
CreateSubstVector(subst_smalllet, space.table_single[L"smallleters"], space.table_single[L"capitalics"]);
|
||||
CreateSubstVector(subst_capitallet, space.table_single[L"capitalics"], space.table_single[L"smallleters"]);
|
||||
CreateSubstSortVector(subst_sort, space.table[L"sort"]);
|
||||
CreateSubstVector(subst_url, temp_space.table_single[L"url_original"], temp_space.table_single[L"url_changeto"]);
|
||||
CreateSubstVector(subst_smalllet, temp_space.table_single[L"smallleters"], temp_space.table_single[L"capitalics"]);
|
||||
CreateSubstVector(subst_capitallet, temp_space.table_single[L"capitalics"], temp_space.table_single[L"smallleters"]);
|
||||
CreateSubstSortVector(subst_sort, temp_space.table[L"sort"]);
|
||||
|
||||
log << log3 << "Locale: read characters substitution tables from: " << file_name << logend;
|
||||
}
|
||||
@@ -206,10 +233,15 @@ void Locale::CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<st
|
||||
|
||||
void Locale::Read(const char * dir, const char * dir_def)
|
||||
{
|
||||
locale_tab.clear();
|
||||
|
||||
for(size_t i=0 ; i<locale_indices.size() ; ++i)
|
||||
locale_indices[i] = size_t(-1);
|
||||
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
{
|
||||
PT::WideToUTF8(locale_files[i], locale_filea);
|
||||
ReadFile(dir, dir_def, i, locale_filea.c_str());
|
||||
ReadFile(dir, dir_def, locale_filea.c_str());
|
||||
}
|
||||
|
||||
ReadSubstTable(dir, dir_def);
|
||||
@@ -250,37 +282,27 @@ void Locale::Read(const std::wstring & dir, const std::wstring & dir_def)
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::Size() const
|
||||
|
||||
|
||||
void Locale::SetCurLang(size_t lang_id)
|
||||
{
|
||||
return loc_tab.size();
|
||||
current_lang = lang_id;
|
||||
}
|
||||
|
||||
|
||||
void Locale::SetLang(size_t lang)
|
||||
{
|
||||
current_lang = lang;
|
||||
|
||||
if( current_lang >= loc_tab.size() )
|
||||
current_lang = loc_tab.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::GetLang() const
|
||||
size_t Locale::GetCurLang() const
|
||||
{
|
||||
return current_lang;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::SetLangDef(size_t lang)
|
||||
void Locale::SetDefLang(size_t lang_id)
|
||||
{
|
||||
default_lang = lang;
|
||||
|
||||
if( default_lang >= loc_tab.size() )
|
||||
default_lang = loc_tab.size() - 1;
|
||||
default_lang = lang_id;
|
||||
}
|
||||
|
||||
size_t Locale::GetLangDef() const
|
||||
|
||||
size_t Locale::GetDefLang() const
|
||||
{
|
||||
return default_lang;
|
||||
}
|
||||
@@ -293,10 +315,10 @@ bool Locale::IsKey(const wchar_t * key)
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const wchar_t * key, size_t lang)
|
||||
bool Locale::IsKey(const wchar_t * key, size_t lang_id)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKey(key_str, lang);
|
||||
return IsKey(key_str, lang_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,32 +329,31 @@ bool Locale::IsKey(const std::wstring & key) const
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key, size_t lang) const
|
||||
const std::wstring * Locale::GetKeyInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang >= loc_tab.size() )
|
||||
return false;
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
return locale_tab[index].GetValue(key);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
const std::wstring * value = GetKeyInLanguage(key, lang_id);
|
||||
|
||||
// looking in the 'lang' language
|
||||
PT::Space::TableSingle::const_iterator i = loc_tab[lang].find(key);
|
||||
|
||||
if( i != loc_tab[lang].end() )
|
||||
if( value )
|
||||
return true;
|
||||
|
||||
if( lang == default_lang )
|
||||
if( lang_id == default_lang )
|
||||
return false;
|
||||
|
||||
|
||||
if( default_lang >= loc_tab.size() )
|
||||
return false;
|
||||
|
||||
// looking in a default language
|
||||
i = loc_tab[default_lang].find(key);
|
||||
|
||||
if( i != loc_tab[default_lang].end() )
|
||||
return true;
|
||||
|
||||
// there is no such a key
|
||||
return false;
|
||||
return GetKeyInLanguage(key, default_lang) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -343,19 +364,12 @@ bool Locale::IsKeyLang(const wchar_t * key, size_t lang)
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKeyLang(const std::wstring & key, size_t lang) const
|
||||
bool Locale::IsKeyLang(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang >= loc_tab.size() )
|
||||
return false;
|
||||
|
||||
// looking in the 'lang' language
|
||||
PT::Space::TableSingle::const_iterator i = loc_tab[lang].find(key);
|
||||
|
||||
return i != loc_tab[lang].end();
|
||||
return GetKeyInLanguage(key, lang_id) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key)
|
||||
{
|
||||
key_str = key;
|
||||
@@ -363,10 +377,10 @@ const std::wstring & Locale::Get(const wchar_t * key)
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key, size_t lang)
|
||||
const std::wstring & Locale::Get(const wchar_t * key, size_t lang_id)
|
||||
{
|
||||
key_str = key;
|
||||
return Get(key_str, lang);
|
||||
return Get(key_str, lang_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -378,52 +392,36 @@ const std::wstring & Locale::Get(const std::wstring & key) const
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const std::wstring & key, size_t lang) const
|
||||
const std::wstring & Locale::Get(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang >= loc_tab.size() )
|
||||
return empty;
|
||||
const std::wstring * value = GetKeyInLanguage(key, lang_id);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
|
||||
// looking in the 'lang' language
|
||||
PT::Space::TableSingle::const_iterator i = loc_tab[lang].find(key);
|
||||
|
||||
if( i != loc_tab[lang].end() )
|
||||
return i->second;
|
||||
|
||||
if( lang == default_lang )
|
||||
if( lang_id == default_lang )
|
||||
return empty;
|
||||
|
||||
value = GetKeyInLanguage(key, default_lang);
|
||||
|
||||
if( default_lang >= loc_tab.size() )
|
||||
return empty;
|
||||
if( value )
|
||||
return *value;
|
||||
|
||||
// looking in a default language
|
||||
i = loc_tab[default_lang].find(key);
|
||||
|
||||
if( i != loc_tab[default_lang].end() )
|
||||
return i->second;
|
||||
|
||||
// there is no such a key
|
||||
return empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsKeyLangList(const wchar_t * key, size_t lang)
|
||||
bool Locale::IsKeyLangList(const wchar_t * key, size_t lang_id)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKeyLangList(key_str, lang);
|
||||
return IsKeyLangList(key_str, lang_id);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKeyLangList(const std::wstring & key, size_t lang) const
|
||||
bool Locale::IsKeyLangList(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang >= loc_tab_multi.size() )
|
||||
return false;
|
||||
|
||||
// looking in the 'lang' language
|
||||
PT::Space::Table::const_iterator i = loc_tab_multi[lang].find(key);
|
||||
|
||||
return i != loc_tab_multi[lang].end();
|
||||
return GetListInLanguage(key, lang_id) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -433,56 +431,88 @@ const std::vector<std::wstring> & Locale::GetList(const std::wstring & key) cons
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key, size_t lang) const
|
||||
|
||||
const std::vector<std::wstring> * Locale::GetListInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang >= loc_tab_multi.size() )
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
|
||||
|
||||
if( i != locale_tab[index].table.end() )
|
||||
return &i->second;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
const std::vector<std::wstring> * list = GetListInLanguage(key, lang_id);
|
||||
|
||||
if( list )
|
||||
return *list;
|
||||
|
||||
if( lang_id == default_lang )
|
||||
return empty_list;
|
||||
|
||||
// looking in the 'lang' language
|
||||
PT::Space::Table::const_iterator i = loc_tab_multi[lang].find(key);
|
||||
list = GetListInLanguage(key, default_lang);
|
||||
|
||||
if( i != loc_tab_multi[lang].end() )
|
||||
return i->second;
|
||||
if( list )
|
||||
return *list;
|
||||
|
||||
if( lang == default_lang )
|
||||
return empty_list;
|
||||
|
||||
|
||||
if( default_lang >= loc_tab_multi.size() )
|
||||
return empty_list;
|
||||
|
||||
// looking in a default language
|
||||
i = loc_tab_multi[default_lang].find(key);
|
||||
|
||||
if( i != loc_tab_multi[default_lang].end() )
|
||||
return i->second;
|
||||
|
||||
// there is no such a key
|
||||
return empty_list;
|
||||
return empty_list;
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::FileNameToLang(const std::wstring & str) const
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
size_t Locale::IdToIndex(size_t lang_id)
|
||||
{
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
if( lang_id < locale_indices.size() )
|
||||
return locale_indices[lang_id]; // here can be size(-1) as well
|
||||
|
||||
return size_t(-1);
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::Size() const
|
||||
{
|
||||
return locale_tab.size();
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::GetByIndex(const wchar_t * key, size_t index)
|
||||
{
|
||||
key_str = key;
|
||||
return GetByIndex(key_str, index);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index) const
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
if( locale_files[i] == str )
|
||||
return i;
|
||||
const std::wstring * value = locale_tab[index].GetValue(key);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
}
|
||||
|
||||
// we have at least one item "en"
|
||||
return 0;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::LangToFileName(size_t lang) const
|
||||
{
|
||||
if( lang >=locale_files.size() )
|
||||
return empty;
|
||||
|
||||
return locale_files[lang];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -492,6 +522,7 @@ void Locale::UTF8(bool utf)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
binary search in vect
|
||||
vect should be sorted by 'from'
|
||||
|
||||
@@ -27,6 +27,11 @@ public:
|
||||
// default one item: en
|
||||
void SetLocaleFiles(const std::vector<std::wstring> & files);
|
||||
|
||||
// preparing locale_indices table
|
||||
// if you change this values you should reload all locale files
|
||||
void SetLocaleMaxId(size_t max_id);
|
||||
|
||||
|
||||
// reading locales
|
||||
// you should call SetLocaleFiles() beforehand
|
||||
void Read(const char * dir, const char * dir_def = 0);
|
||||
@@ -34,57 +39,67 @@ public:
|
||||
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
|
||||
void Read(const std::wstring & dir, const std::wstring & dir_def);
|
||||
|
||||
// returns true if a language with lang_id exists
|
||||
bool HasLanguage(size_t lang_id);
|
||||
|
||||
// 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 wchar_t * key, size_t lang_id);
|
||||
bool IsKey(const std::wstring & key) const;
|
||||
bool IsKey(const std::wstring & key, size_t lang) const;
|
||||
bool IsKey(const std::wstring & key, size_t lang_id) 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;
|
||||
bool IsKeyLang(const wchar_t * key, size_t lang_id);
|
||||
bool IsKeyLang(const std::wstring & key, size_t lang_id) 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 wchar_t * key, size_t lang_id);
|
||||
const std::wstring & Get(const std::wstring & key) const;
|
||||
const std::wstring & Get(const std::wstring & key, size_t lang) const;
|
||||
const std::wstring & Get(const std::wstring & key, size_t lang_id) 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;
|
||||
// lists
|
||||
bool IsKeyLangList(const wchar_t * key, size_t lang_id);
|
||||
bool IsKeyLangList(const std::wstring & key, size_t lang_id) 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;
|
||||
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang_id) const;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// setting/getting current language
|
||||
// default: 0
|
||||
void SetLang(size_t lang);
|
||||
size_t GetLang() const;
|
||||
void SetCurLang(size_t lang_id);
|
||||
size_t GetCurLang() const;
|
||||
|
||||
// which language is used instead if there is no a key in an other language
|
||||
// which language is used instead of if there is no a key in an other language
|
||||
// default: 0
|
||||
void SetLangDef(size_t lang);
|
||||
size_t GetLangDef() const;
|
||||
void SetDefLang(size_t lang_id);
|
||||
size_t GetDefLang() 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;
|
||||
|
||||
|
||||
// converting lang_id to an internal index
|
||||
// returns an index from <0, Size()-1> or size_t(-1) if lang_id is incorrect
|
||||
// it does it in O(1) time
|
||||
size_t IdToIndex(size_t lang_id);
|
||||
|
||||
// returning how many locale files (languages) there are
|
||||
// this is how many files were correctly parsed
|
||||
// this is size of locale_tab table
|
||||
size_t Size() const;
|
||||
|
||||
// accessing by an internal index
|
||||
// internal index is from zero to Size()-1
|
||||
const std::wstring & GetByIndex(const wchar_t * key, size_t index);
|
||||
const std::wstring & GetByIndex(const std::wstring & key, size_t index) const;
|
||||
|
||||
|
||||
|
||||
// it sets whether we should parse locale files as utf-8 files
|
||||
// default: false
|
||||
void UTF8(bool utf);
|
||||
@@ -104,8 +119,11 @@ public:
|
||||
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
|
||||
{
|
||||
@@ -116,36 +134,45 @@ private:
|
||||
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 AddLocale(const char * file);
|
||||
void ReadFile(const char * dir, const char * dir_def, const char * file);
|
||||
bool ReadFile(const char * dir, 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);
|
||||
void CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<std::wstring> & tab);
|
||||
size_t SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val);
|
||||
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
|
||||
const std::wstring * GetKeyInLanguage(const std::wstring & key, size_t lang_id) const;
|
||||
const std::vector<std::wstring> * GetListInLanguage(const std::wstring & key, size_t lang_id) const;
|
||||
|
||||
|
||||
// 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<PT::Space::TableSingle> loc_tab;
|
||||
// a map from <0, config->locale_max_id> returning an index to
|
||||
// locale_tab table (you should check whether the index is correct)
|
||||
// with this we have O(1) time to find the specified locale
|
||||
// and locale_tab doesn't have to be so large
|
||||
std::vector<size_t> locale_indices;
|
||||
|
||||
// messages vector<via language>
|
||||
// this table has the same size as locale_files (at least one item)
|
||||
std::vector<PT::Space::Table> loc_tab_multi;
|
||||
std::vector<PT::Space> locale_tab;
|
||||
|
||||
// default locale index (index to locale_indexes)
|
||||
size_t default_lang;
|
||||
|
||||
// current locale index (index to locale_indexes)
|
||||
size_t current_lang;
|
||||
|
||||
// vectors of characters substitution (sort by 'from')
|
||||
std::vector<SubstItem> subst_url;
|
||||
std::vector<SubstItem> subst_url; // for url substitution
|
||||
std::vector<SubstItem> subst_smalllet; // changing from small to capital
|
||||
std::vector<SubstItem> subst_capitallet; // changing from capital to small
|
||||
std::vector<SubstItem> subst_sort; // local characters for comparison
|
||||
|
||||
|
||||
PT::Space space;
|
||||
PT::Space temp_space;
|
||||
PT::SpaceParser loc_parser;
|
||||
std::string locale_filea;
|
||||
std::string file_name;
|
||||
@@ -153,8 +180,6 @@ private:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -35,35 +35,6 @@ void LocaleFilter::ReadKey()
|
||||
}
|
||||
|
||||
|
||||
std::wstring & LocaleFilter::FilterValue(const std::wstring & in)
|
||||
{
|
||||
value.clear();
|
||||
const wchar_t * p = in.c_str();
|
||||
|
||||
while( *p )
|
||||
{
|
||||
if( *p == '\\' && (*(p+1) == 'n') )
|
||||
{
|
||||
value += '\n';
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
if( *p == '\\' && (*(p+1) == '\\') )
|
||||
{
|
||||
value += '\\';
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
value += *p;
|
||||
p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Parse(std::wstring & str)
|
||||
{
|
||||
@@ -76,7 +47,7 @@ void LocaleFilter::Parse(std::wstring & str)
|
||||
{
|
||||
++pchar;
|
||||
ReadKey();
|
||||
res += FilterValue(plocale->Get(key, lang));
|
||||
res += plocale->GetByIndex(key, lang);
|
||||
}
|
||||
else
|
||||
if( *pchar == '\\' && (*(pchar+1) == open_mark || *(pchar+1) == closing_mark || *(pchar+1) == '\\') )
|
||||
@@ -96,7 +67,6 @@ void LocaleFilter::Parse(std::wstring & str)
|
||||
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::FilterText(Ezc::Item & item)
|
||||
{
|
||||
if( !item.text.empty() )
|
||||
@@ -110,10 +80,10 @@ void LocaleFilter::FilterText(Ezc::Item & item)
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_)
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_index)
|
||||
{
|
||||
plocale = &locale;
|
||||
lang = lang_;
|
||||
lang = lang_index;
|
||||
|
||||
FilterText( pattern.item_root );
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -21,11 +21,12 @@ class LocaleFilter
|
||||
public:
|
||||
|
||||
LocaleFilter();
|
||||
void Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_);
|
||||
|
||||
// lang_index is an internal index from Locale <0, Size()-1>
|
||||
void Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_index);
|
||||
|
||||
private:
|
||||
void ReadKey();
|
||||
std::wstring & FilterValue(const std::wstring & in);
|
||||
void FilterText(Ezc::Item & item);
|
||||
void Parse(std::wstring & str);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -115,12 +115,17 @@ void Patterns::ReadPatterns(Template & templ)
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * Patterns::Get(size_t index, size_t lang)
|
||||
Ezc::Pattern * Patterns::Get(size_t index, size_t lang_id)
|
||||
{
|
||||
if( index >= pat_tab.size() || pat_tab[index].references == 0 || lang >= pat_tab[index].patterns.size() )
|
||||
if( index >= pat_tab.size() || pat_tab[index].references == 0 )
|
||||
return 0;
|
||||
|
||||
return &pat_tab[index].patterns[lang];
|
||||
size_t lang_index = locale->IdToIndex(lang_id);
|
||||
|
||||
if( lang_index >= pat_tab[index].patterns.size() )
|
||||
return 0;
|
||||
|
||||
return &pat_tab[index].patterns[lang_index];
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +154,7 @@ void Patterns::Clear()
|
||||
|
||||
void Patterns::Erase(size_t index)
|
||||
{
|
||||
if( index < pat_tab.size() )
|
||||
if( index < pat_tab.size() && pat_tab[index].references > 0 )
|
||||
{
|
||||
pat_tab[index].references -= 1;
|
||||
|
||||
@@ -160,7 +165,7 @@ void Patterns::Erase(size_t index)
|
||||
pat_tab[index].file_name.clear();
|
||||
pat_tab[index].patterns.clear();
|
||||
// don't erase pat_tab.erase() here
|
||||
// because indexes would be invalidated
|
||||
// because indices would be invalidated
|
||||
// those gaps will be cleared when Clear() method is called
|
||||
// normally in reload/templates winix function
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
returning a pattern (if exists)
|
||||
if the pattern does not exist return a null pointer
|
||||
*/
|
||||
Ezc::Pattern * Get(size_t index, size_t lang);
|
||||
Ezc::Pattern * Get(size_t index, size_t lang_id);
|
||||
|
||||
|
||||
/*
|
||||
@@ -110,7 +110,9 @@ private:
|
||||
bool to_delete;
|
||||
std::wstring file_name;
|
||||
size_t references; // starts from 1 (zero means the pattern was deleted)
|
||||
std::vector<Ezc::Pattern> patterns; // table[lang]
|
||||
// (we do not delete the Template immediately because
|
||||
// indices would be invalidated)
|
||||
std::vector<Ezc::Pattern> patterns; // table[through lang index]
|
||||
};
|
||||
|
||||
typedef std::vector<Template> PatTab;
|
||||
|
||||
@@ -72,12 +72,12 @@ static std::wstring fun_file;
|
||||
fun_file += cur->request->function->fun.url;
|
||||
fun_file += config->templates_fun_postfix;
|
||||
|
||||
Ezc::Pattern * p = change_patterns.Get(cur->mount->dir_id, fun_file, locale.GetLang());
|
||||
Ezc::Pattern * p = change_patterns.Get(cur->mount->dir_id, fun_file, locale.GetCurLang());
|
||||
|
||||
if( p )
|
||||
return p;
|
||||
|
||||
return patterns.Get(cur->request->function->template_index, locale.GetLang());
|
||||
return patterns.Get(cur->request->function->template_index, locale.GetCurLang());
|
||||
}
|
||||
|
||||
|
||||
@@ -99,14 +99,14 @@ Ezc::Pattern * p = 0;
|
||||
case WINIX_ERR_CANT_CHANGE_GROUP:
|
||||
case WINIX_ERR_CANT_CHANGE_PRIVILEGES:
|
||||
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = patterns.Get(pat_err_per_denied, locale.GetLang());
|
||||
p = patterns.Get(pat_err_per_denied, locale.GetCurLang());
|
||||
break;
|
||||
|
||||
case WINIX_ERR_NO_ITEM:
|
||||
case WINIX_ERR_NO_FUNCTION:
|
||||
case WINIX_ERR_UNKNOWN_PARAM:
|
||||
// !! locale.GetLang() bedzie brane indywidualnie dla kazdego uzytkownika
|
||||
p = patterns.Get(pat_err_404, locale.GetLang());
|
||||
p = patterns.Get(pat_err_404, locale.GetCurLang());
|
||||
break;
|
||||
|
||||
//default:
|
||||
@@ -507,6 +507,13 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("user_can_use_html", user_can_use_html);
|
||||
ezc_functions.Insert("user_can_use_bbcode", user_can_use_bbcode);
|
||||
ezc_functions.Insert("user_can_use_raw", user_can_use_raw);
|
||||
ezc_functions.Insert("user_has_correct_time_zone",user_has_correct_time_zone);
|
||||
ezc_functions.Insert("user_time_zone_name", user_time_zone_name);
|
||||
ezc_functions.Insert("user_time_zone_id", user_time_zone_id);
|
||||
ezc_functions.Insert("user_time_zone_offset_hour_min", user_time_zone_offset_hour_min);
|
||||
ezc_functions.Insert("user_has_correct_locale", user_has_correct_locale);
|
||||
ezc_functions.Insert("user_locale_name", user_locale_name);
|
||||
ezc_functions.Insert("user_locale_id", user_locale_id);
|
||||
ezc_functions.Insert("user_tab", user_tab);
|
||||
ezc_functions.Insert("user_tab_index", user_tab_index);
|
||||
ezc_functions.Insert("user_tab_id", user_tab_id);
|
||||
@@ -573,11 +580,9 @@ void Templates::CreateFunctions()
|
||||
ezc_functions.Insert("winix_tz_tab_name", winix_tz_tab_name);
|
||||
ezc_functions.Insert("winix_tz_tab_offset_sec", winix_tz_tab_offset_sec);
|
||||
ezc_functions.Insert("winix_tz_tab_offset_hour_min", winix_tz_tab_offset_hour_min);
|
||||
ezc_functions.Insert("winix_tz_tab_has_dst", winix_tz_tab_has_dst);
|
||||
ezc_functions.Insert("winix_tz_tab_dst_offset_sec", winix_tz_tab_dst_offset_sec);
|
||||
ezc_functions.Insert("winix_tz_tab_dst_offset_hour_min", winix_tz_tab_dst_offset_hour_min);
|
||||
ezc_functions.Insert("winix_tz_tab_dst_start", winix_tz_tab_dst_start);
|
||||
ezc_functions.Insert("winix_tz_tab_dst_end", winix_tz_tab_dst_end);
|
||||
ezc_functions.Insert("winix_locale_tab", winix_locale_tab);
|
||||
ezc_functions.Insert("winix_locale_tab_id", winix_locale_tab_id);
|
||||
ezc_functions.Insert("winix_locale_tab_name", winix_locale_tab_name);
|
||||
|
||||
|
||||
/*
|
||||
@@ -612,9 +617,8 @@ using namespace TemplatesFunctions;
|
||||
|
||||
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.SetLocaleMaxId(config->locale_max_id);
|
||||
locale.SetDefLang(config->locale_default_id);
|
||||
locale.Read(config->locale_dir, config->locale_dir_default);
|
||||
|
||||
log << log3 << "Templates: there are " << locale.Size() << " locales" << logend;
|
||||
@@ -682,6 +686,8 @@ using namespace TemplatesFunctions;
|
||||
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// we need such a html filter for each language (orphans are different in each language)
|
||||
void Templates::SetHtmlFilter()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
@@ -701,6 +707,9 @@ using namespace TemplatesFunctions;
|
||||
if( locale.IsKeyLang(L"html_lang_attr_value", i) &&
|
||||
locale.IsKeyLangList(L"language_orphans", i) )
|
||||
{
|
||||
// !! FIX ME
|
||||
// this is not the proper index
|
||||
// we should use locale.GetByIndex() instead
|
||||
html_filter.AssignOrphans(locale.Get(L"html_lang_attr_value", i),
|
||||
locale.GetList(L"language_orphans", i));
|
||||
}
|
||||
@@ -835,7 +844,7 @@ using namespace TemplatesFunctions;
|
||||
}
|
||||
|
||||
if( index_file_local && *index_file_local != config->templates_index )
|
||||
index = index_patterns.Get(*index_file_local, locale.GetLang());
|
||||
index = index_patterns.Get(*index_file_local, locale.GetCurLang());
|
||||
|
||||
return index;
|
||||
}
|
||||
@@ -851,18 +860,18 @@ using namespace TemplatesFunctions;
|
||||
Ezc::Pattern * index = 0;
|
||||
|
||||
if( cur->request->IsParam(L"rawcontent") )
|
||||
index = patterns.Get(pat_index_rawcontent, locale.GetLang());
|
||||
index = patterns.Get(pat_index_rawcontent, locale.GetCurLang());
|
||||
else
|
||||
if( cur->request->IsParam(L"fullscreen") )
|
||||
index = patterns.Get(pat_index_fullscreen, locale.GetLang());
|
||||
index = patterns.Get(pat_index_fullscreen, locale.GetCurLang());
|
||||
else
|
||||
index = SelectIndexPatternFromItemAndMountPoint();
|
||||
|
||||
if( !index )
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetLang());
|
||||
index = change_patterns.Get(cur->mount->dir_id, config->templates_index, locale.GetCurLang());
|
||||
|
||||
if( !index )
|
||||
index = patterns.Get(pat_index, locale.GetLang());;
|
||||
index = patterns.Get(pat_index, locale.GetCurLang());;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -425,6 +425,13 @@ namespace TemplatesFunctions
|
||||
void user_can_use_html(Info & i);
|
||||
void user_can_use_bbcode(Info & i);
|
||||
void user_can_use_raw(Info & i);
|
||||
void user_has_correct_time_zone(Info & i);
|
||||
void user_time_zone_name(Info & i);
|
||||
void user_time_zone_id(Info & i);
|
||||
void user_time_zone_offset_hour_min(Info & i);
|
||||
void user_has_correct_locale(Info & i);
|
||||
void user_locale_name(Info & i);
|
||||
void user_locale_id(Info & i);
|
||||
void user_tab(Info & i);
|
||||
void user_tab_index(Info & i);
|
||||
void user_tab_id(Info & i);
|
||||
@@ -491,11 +498,9 @@ namespace TemplatesFunctions
|
||||
void winix_tz_tab_name(Info & i);
|
||||
void winix_tz_tab_offset_sec(Info & i);
|
||||
void winix_tz_tab_offset_hour_min(Info & i);
|
||||
void winix_tz_tab_has_dst(Info & i);
|
||||
void winix_tz_tab_dst_offset_sec(Info & i);
|
||||
void winix_tz_tab_dst_offset_hour_min(Info & i);
|
||||
void winix_tz_tab_dst_start(Info & i);
|
||||
void winix_tz_tab_dst_end(Info & i);
|
||||
void winix_locale_tab(Info & i);
|
||||
void winix_locale_tab_id(Info & i);
|
||||
void winix_locale_tab_name(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -110,6 +110,79 @@ void user_can_use_raw(Info & i)
|
||||
}
|
||||
|
||||
|
||||
void user_has_correct_time_zone(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.res = system->time_zones.HasZone(cur->session->puser->time_zone_id);
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_name(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZone(cur->session->puser->time_zone_id);
|
||||
|
||||
if( tz )
|
||||
i.out << locale.Get(tz->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_id(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->time_zone_id;
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_offset_hour_min(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(cur->session->puser->time_zone_id);
|
||||
|
||||
if( tz )
|
||||
{
|
||||
time_t offset = tz->offset;
|
||||
|
||||
if( offset < 0 )
|
||||
{
|
||||
i.out << '-';
|
||||
offset = -offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << '+';
|
||||
}
|
||||
|
||||
print_hour_min(i, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void user_has_correct_locale(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.res = locale.HasLanguage(cur->session->puser->locale_id);
|
||||
}
|
||||
|
||||
|
||||
void user_locale_name(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << locale.Get(L"locale_name");
|
||||
}
|
||||
|
||||
|
||||
void user_locale_id(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->locale_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static Users::Iterator user_iter;
|
||||
|
||||
@@ -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-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -336,33 +336,38 @@ void winix_tz_tab(Info & i)
|
||||
|
||||
void winix_tz_tab_id(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
i.out << system->time_zones[tz_index].time_zone.tz_id;
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << tz->id;
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_name(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
{
|
||||
std::wstring & key = system->time_zones[tz_index].name_key;
|
||||
i.out << locale.Get(key); // !! IMPROVE ME which locale?
|
||||
}
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << locale.Get(tz->name);
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_offset_sec(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
i.out << system->time_zones[tz_index].time_zone.tz_offset;
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << tz->offset;
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_offset_hour_min(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
{
|
||||
time_t offset = system->time_zones[tz_index].time_zone.tz_offset;
|
||||
time_t offset = tz->offset;
|
||||
|
||||
if( offset < 0 )
|
||||
{
|
||||
@@ -379,65 +384,31 @@ void winix_tz_tab_offset_hour_min(Info & i)
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_has_dst(Info & i)
|
||||
|
||||
static size_t locale_id;
|
||||
|
||||
void winix_locale_tab(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
i.res = system->time_zones[tz_index].time_zone.tz_has_dst;
|
||||
locale_id = i.iter;
|
||||
i.res = locale_id < locale.Size();
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_dst_offset_sec(Info & i)
|
||||
void winix_locale_tab_id(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
i.out << system->time_zones[tz_index].time_zone.tz_dst_offset;
|
||||
if( locale_id < locale.Size() )
|
||||
i.out << Toi(locale.GetByIndex(L"winix_locale_id", locale_id));
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_dst_offset_hour_min(Info & i)
|
||||
void winix_locale_tab_name(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
{
|
||||
time_t offset = system->time_zones[tz_index].time_zone.tz_dst_offset;
|
||||
|
||||
if( offset < 0 )
|
||||
{
|
||||
i.out << '-';
|
||||
offset = -offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << '+';
|
||||
}
|
||||
|
||||
print_hour_min(i, offset);
|
||||
}
|
||||
if( locale_id < locale.Size() )
|
||||
i.out << locale.GetByIndex(L"locale_name", locale_id);
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_dst_start(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
{
|
||||
PT::Date & date = system->time_zones[tz_index].time_zone.tz_dst_start;
|
||||
|
||||
date.SerializeMonthDay(i.out);
|
||||
i.out << ' ';
|
||||
date.SerializeHourMin(i.out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_dst_end(Info & i)
|
||||
{
|
||||
if( tz_index < system->time_zones.Size() )
|
||||
{
|
||||
PT::Date & date = system->time_zones[tz_index].time_zone.tz_dst_end;
|
||||
|
||||
date.SerializeMonthDay(i.out);
|
||||
i.out << ' ';
|
||||
date.SerializeHourMin(i.out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user