22 mXmlLanguageTagName(
"Language"),
23 mSingletonHolder(this)
46 mIsInitialise =
false;
51 std::string default_lang;
52 bool event_change =
false;
56 while (root.
next(mXmlLanguageTagName))
63 while (info.
next(
"Info"))
72 while (source_info.
next(
"Source"))
81 while (source_info.next(
"Source"))
83 std::string file_source = source_info->
getContent();
85 mMapFile[name].push_back(file_source);
88 if (name == mCurrentLanguageName)
90 loadLanguage(file_source,
false);
99 if (!default_lang.empty())
101 else if (event_change)
107 MapListString::iterator item = mMapFile.find(_name);
108 if (item == mMapFile.end())
110 MYGUI_LOG(Error,
"Language '" << _name <<
"' is not found");
114 mMapLanguage.clear();
115 mCurrentLanguageName = _name;
117 for (VectorString::const_iterator iter = item->second.begin(); iter != item->second.end(); ++iter)
119 loadLanguage(*iter,
false);
125 bool LanguageManager::loadLanguage(
const std::string& _file,
bool _user)
130 MYGUI_LOG(Error,
"file '" << _file <<
"' not found");
134 if (_file.find(
".xml") != std::string::npos)
135 _loadLanguageXML(data.
getData(), _user);
137 _loadLanguage(data.
getData(), _user);
142 void LanguageManager::_loadLanguageXML(IDataStream* _stream,
bool _user)
146 if (doc.open(_stream))
152 while (tag.next(
"Tag"))
155 mUserMapLanguage[tag->findAttribute(
"name")] = tag->getContent();
157 mMapLanguage[tag->findAttribute(
"name")] = tag->getContent();
163 void LanguageManager::_loadLanguage(IDataStream* _stream,
bool _user)
167 while (!_stream->eof())
169 _stream->readline(read,
'\n');
170 if (read.empty())
continue;
173 if ((
uint8)read[0] == 0xEF && read.size() > 2)
178 if (read[read.size() - 1] ==
'\r') read.erase(read.size() - 1, 1);
179 if (read.empty())
continue;
181 size_t pos = read.find_first_of(
" \t");
184 if (pos == std::string::npos) mUserMapLanguage[read] =
"";
185 else mUserMapLanguage[read.substr(0, pos)] = read.substr(pos + 1, std::string::npos);
189 if (pos == std::string::npos) mMapLanguage[read] =
"";
190 else mMapLanguage[read.substr(0, pos)] = read.substr(pos + 1, std::string::npos);
199 bool replace =
false;
202 result = replaceTagsPass(result, replace);
211 MapLanguageString::const_iterator iter = mMapLanguage.find(_tag);
212 if (iter != mMapLanguage.end())
217 MapLanguageString::const_iterator iterUser = mUserMapLanguage.find(_tag);
218 if (iterUser != mUserMapLanguage.end())
220 return iterUser->second;
228 return mCurrentLanguageName;
235 for (MapListString::const_iterator iter = mMapFile.begin(); iter != mMapFile.end(); ++iter)
237 result.push_back(iter->first);
244 mUserMapLanguage[_tag] = _replace;
249 mUserMapLanguage.clear();
254 return loadLanguage(_file,
true);
257 UString LanguageManager::replaceTagsPass(
const UString& _line,
bool& _replaceResult)
259 _replaceResult =
false;
263 UString::utf32string::iterator end = line.end();
264 for (UString::utf32string::iterator iter = line.begin(); iter != end; )
280 UString::utf32string::iterator iter2 = iter;
286 return UString(line);
290 size_t start = iter - line.begin();
291 size_t len = (iter2 - line.begin()) - start - 1;
297 MapLanguageString::iterator replace = mMapLanguage.find(UString(tag));
298 if (replace != mMapLanguage.end())
300 replacement = replace->second;
305 replace = mUserMapLanguage.find(UString(tag));
306 if (replace != mUserMapLanguage.end())
308 replacement = replace->second;
325 iter = line.insert(iter,
'#') + size_t(
len + 2);
331 _replaceResult =
true;
333 iter = line.erase(iter -
size_t(1), iter2 +
size_t(1));
334 size_t pos = iter - line.begin();
335 line.insert(pos, replacement.asUTF32());
336 iter = line.begin() + pos + replacement.length();
339 return UString(line);
352 return UString(line);
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
virtual IDataStream * getData(const std::string &_name) const =0
static DataManager & getInstance()
const std::string & getCurrentLanguage() const
delegates::CDelegate2< const UString &, UString & > eventRequestTag
void addUserTag(const UString &_tag, const UString &_replace)
void setCurrentLanguage(const std::string &_name)
static const char * getClassTypeName()
VectorString getLanguages() const
UString getTag(const UString &_tag) const
delegates::CMultiDelegate1< const std::string & > eventChangeLanguage
bool loadUserTags(const std::string &_file)
UString replaceTags(const UString &_line)
void unregisterLoadXmlDelegate(const std::string &_key)
static ResourceManager & getInstance()
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
const utf32string & asUTF32() const
returns the current string in UTF-32 form within a utf32string
std::basic_string< unicode_char > utf32string
string type used for returning UTF-32 formatted data
const std::string & getContent() const
ElementEnumerator getElementEnumerator()
bool findAttribute(const std::string &_name, std::string &_value)
std::vector< std::string > VectorString
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
MYGUI_SINGLETON_DEFINITION(ClipboardManager)
float len(float x, float y)