#include <i18n.h>
This class provide an easy way to localise all string. First you have to get all available language with getLanguageNames(). If you already know the number of the language (that is the index in the vector returns by getLanguagesNames()), you can load the language file with load(). Now, you can get a localised string with his association with get().
// get all language names (you must call this before calling load()) CI18N::getLanguageNames (); // load the language 1 (french) CI18N::load (1); // display "Salut" that is the "hi" string in the selected language (french). nlinfo (CI18N::get("hi").c_str ()); // display "rms est un master", the french version of the string nlinfo (CI18N::get("%s is a master").c_str (), "mrs"); *
If the string doesn't exist, it will be automatically added in all language files with a mention. If the language file doesn't exist, it'll be automatically create.
Update 26-02-2002 Boris Boucher
Language are now preferably handled via official language code. We use the ISO 639-1 code for language. Optionnaly, we can append a country code (ISO 3066) to differentiate between language flavor (eg chinese is ISO 639-1 zh, but come in traditionnal or simplified form. So we append the country code : zh-CN (china) for simplified, zh for traditionnal).
Nevrax France
Definition at line 76 of file i18n.h.
Static Public Member Functions | |
| std::string | encodeUTF8 (const ucstring &str) |
| const ucstring & | get (const std::string &label) |
| Find a string in the selected language and return his association. | |
| ucstring | getCurrentLanguageName () |
| Returns the name of the language in english (french, english...). | |
| const std::vector< std::string > & | getLanguageCodes () |
| const std::vector< ucstring > & | getLanguageNames () |
| void | load (const std::string &languageCode) |
| Load a language file depending of the language. | |
| ucstring | makeMarkedString (ucchar openMark, ucchar closeMark, const ucstring &text) |
| void | readTextBuffer (uint8 *buffer, uint size, ucstring &result, bool forceUtf8=false) |
| void | readTextFile (const std::string &filename, ucstring &result, bool forceUtf8=false, bool fileLookup=true, bool preprocess=false) |
| Temporary, we don't have file system for now, so we do a tricky cheat. there s not check so be careful! | |
| void | remove_C_Comment (ucstring &commentedString) |
| void | setLoadProxy (ILoadProxy *loadProxy) |
| Set the load proxy class. Proxy can be NULL to unregister. | |
| void | writeTextFile (const std::string filename, const ucstring &content, bool utf8=true) |
| std::string | hashToString (uint64 hash) |
| void | hashToUCString (uint64 hash, ucstring &dst) |
| uint64 | makeHash (const ucstring &str) |
| uint64 | stringToHash (const std::string &str) |
Category control | |
| bool | parseLabel (ucstring::const_iterator &it, ucstring::const_iterator &last, std::string &label) |
| Parse a label. | |
| bool | parseMarkedString (ucchar openMark, ucchar closeMark, ucstring::const_iterator &it, ucstring::const_iterator &last, ucstring &result) |
| Parse a marked string. NB : usualy, we use [ and ] as string delimiters in translation files. | |
| void | skipWhiteSpace (ucstring::const_iterator &it, ucstring::const_iterator &last, ucstring *storeComments=NULL) |
Private Types | |
| typedef std::map< std::string, ucstring > | StrMapContainer |
Static Private Attributes | |
| const std::string | _LanguageCodes [] |
| bool | _LanguagesNamesLoaded = false |
| ILoadProxy * | _LoadProxy = 0 |
| const uint | _NbLanguages = sizeof(CI18N::_LanguageCodes) / sizeof(std::string) |
| const ucstring | _NotTranslatedValue |
| sint32 | _SelectedLanguage = -1 |
| StrMapContainer | _StrMap |
| bool | _StrMapLoaded = false |
|
|
|
|
|
Encode a unicode string into a string using UTF-8 encoding. Definition at line 627 of file i18n.cpp. References ucstring::toUtf8(). Referenced by writeTextFile().
00628 {
00629 return str.toUtf8();
00630 /*
00631 string res;
00632 ucstring::const_iterator first(str.begin()), last(str.end());
00633 for (; first != last; ++first)
00634 {
00635 //ucchar c = *first;
00636 uint nbLoop = 0;
00637 if (*first < 0x80)
00638 res += char(*first);
00639 else if (*first < 0x800)
00640 {
00641 ucchar c = *first;
00642 c = c >> 6;
00643 c = c & 0x1F;
00644 res += c | 0xC0;
00645 nbLoop = 1;
00646 }
00647 else if (*first < 0x10000)
00648 {
00649 ucchar c = *first;
00650 c = c >> 12;
00651 c = c & 0x0F;
00652 res += c | 0xE0;
00653 nbLoop = 2;
00654 }
00655
00656 for (uint i=0; i<nbLoop; ++i)
00657 {
00658 ucchar c = *first;
00659 c = c >> ((nbLoop - i - 1) * 6);
00660 c = c & 0x3F;
00661 res += char(c) | 0x80;
00662 }
00663 }
00664 return res;
00665 */
00666 }
|
|
|
Find a string in the selected language and return his association.
Definition at line 140 of file i18n.cpp. References _LanguageCodes, _SelectedLanguage, _StrMap, and nlwarning. Referenced by getCurrentLanguageName().
00141 {
00142 if (label.empty())
00143 {
00144 static ucstring emptyString;
00145 return emptyString;
00146 }
00147
00148 StrMapContainer::iterator it(_StrMap.find(label));
00149
00150 if (it != _StrMap.end())
00151 return it->second;
00152
00153 nlwarning("I18N: The string %s did not exist in language %s", label.c_str(), _LanguageCodes[_SelectedLanguage].c_str());
00154
00155 static ucstring badString;
00156
00157 badString = ucstring(std::string("<NotExist:")+label+">");
00158
00159 return badString;
00160 }
|
|
|
Returns the name of the language in english (french, english...).
Definition at line 162 of file i18n.cpp. References get().
00163 {
00164 return get("LanguageName");
00165 }
|
|
|
Return a vector with all language code available. Code are ISO 639-2 compliant. As in getLanguageNames(), the index in the vector can be used to call load() |
|
|
Return a vector with all language available. The vector contains the name of the language. The index in the vector is used in |
|
|
Definition at line 705 of file i18n.cpp. References uint32, and uint64.
|
|
||||||||||||
|
Definition at line 716 of file i18n.cpp. References sint, ucchar, and uint64.
00717 {
00718 static ucchar cvtTable[]= {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
00719
00720 dst.resize(16);
00721 for(sint i=15;i>=0;i--)
00722 {
00723 // Must decal dest of 8, cause of hashToString code (Little Endian)
00724 dst[(i+8)&15]= cvtTable[hash&15];
00725 hash>>=4;
00726 }
00727 }
|
|
|
Load a language file depending of the language.
Definition at line 67 of file i18n.cpp. References _LanguageCodes, _LoadProxy, _NbLanguages, _SelectedLanguage, _StrMap, _StrMapLoaded, NLMISC::CI18N::ILoadProxy::loadStringFile(), nlwarning, parseLabel(), parseMarkedString(), readTextFile(), remove_C_Comment(), skipWhiteSpace(), and uint.
00068 {
00069 // nlassert (lid < _NbLanguages);
00070 // nlassert (_LanguagesNamesLoaded);
00071
00072 uint i;
00073 for (i=0; i<_NbLanguages; ++i)
00074 {
00075 if (_LanguageCodes[i] == languageCode)
00076 break;
00077 }
00078
00079 if (i == _NbLanguages)
00080 {
00081 nlwarning("I18N: Unknow language code : %s, defaulting to %s", _LanguageCodes[0].c_str());
00082 i = 0;
00083 }
00084
00085 std::string fileName = _LanguageCodes[i] + ".uxt";
00086
00087 _SelectedLanguage = i;
00088
00089 if (_StrMapLoaded) _StrMap.clear ();
00090 else _StrMapLoaded = true;
00091
00092 ucstring text;
00093 // read in the text
00094 if (_LoadProxy)
00095 _LoadProxy->loadStringFile(fileName, text);
00096 else
00097 readTextFile(fileName, text);
00098 // remove any comment
00099 remove_C_Comment(text);
00100
00101 ucstring::const_iterator first(text.begin()), last(text.end());
00102 std::string lastReadLabel("nothing");
00103
00104 while (first != last)
00105 {
00106 skipWhiteSpace(first, last);
00107 std::string label;
00108 ucstring ucs;
00109 if (!parseLabel(first, last, label))
00110 {
00111 nlwarning("I18N: Error reading label field in %s. Stop reading after %s.", fileName.c_str(), lastReadLabel.c_str());
00112 return;
00113 }
00114 lastReadLabel = label;
00115 skipWhiteSpace(first, last);
00116 if (!parseMarkedString('[', ']', first, last, ucs))
00117 {
00118 nlwarning("I18N: Error reading text for label %s in %s. Stop reading.", label.c_str(), fileName.c_str());
00119 return;
00120 }
00121
00122 // ok, a line read.
00123 std::pair<std::map<std::string, ucstring>::iterator, bool> ret;
00124 ret = _StrMap.insert(std::make_pair(label, ucs));
00125 if (!ret.second)
00126 {
00127 nlwarning("I18N: Error in %s, the label %s exist twice !", fileName.c_str(), label.c_str());
00128 }
00129 skipWhiteSpace(first, last);
00130 }
00131
00132 // a little check to ensure that the lang name has been set.
00133 StrMapContainer::iterator it(_StrMap.find("LanguageName"));
00134 if (it == _StrMap.end())
00135 {
00136 nlwarning("I18N: In file %s, missing LanguageName translation (should be first in file)", fileName.c_str());
00137 }
00138 }
|
|
|
Definition at line 679 of file i18n.cpp. References uint, uint32, uint64, and uint8.
00680 {
00681 // on passe au moins 8 fois sur chaque octet de resultat
00682 if (str.empty())
00683 return 0;
00684 const uint32 MIN_TURN = 8*8;
00685 uint64 hash = 0;
00686 uint8 *ph = (uint8*)&hash;
00687 uint8 *pc = (uint8*)str.data();
00688
00689 uint nbLoop = max(uint32(str.size()*2), MIN_TURN);
00690 uint roll = 0;
00691
00692 for (uint i=0; i<nbLoop; ++i)
00693 {
00694 ph[(i/2) & 0x7] += pc[i%(str.size()*2)] << roll;
00695 ph[(i/2) & 0x7] += pc[i%(str.size()*2)] >> (8-roll);
00696
00697 roll++;
00698 roll &= 0x7;
00699 }
00700
00701 return hash;
00702 }
|
|
||||||||||||||||
|
Definition at line 590 of file i18n.cpp. References ucchar.
00591 {
00592 ucstring ret;
00593
00594 ret.push_back(openMark);
00595
00596 ucstring::const_iterator first(text.begin()), last(text.end());
00597 for (; first != last; ++first)
00598 {
00599 if (*first == '\n')
00600 {
00601 ret += '\\';
00602 ret += 'n';
00603 }
00604 else if (*first == '\t')
00605 {
00606 ret += '\\';
00607 ret += 't';
00608 }
00609 else if (*first == closeMark)
00610 {
00611 // excape the embeded closing mark
00612 ret += '\\';
00613 ret += closeMark;
00614 }
00615 else
00616 {
00617 ret += *first;
00618 }
00619 }
00620
00621 ret += closeMark;
00622
00623 return ret;
00624 }
|
|
||||||||||||||||
|
Parse a label.
Definition at line 264 of file i18n.cpp. Referenced by load().
00265 {
00266 label.erase();
00267
00268 // first char must be A-Za-z@_
00269 if (it != last &&
00270 (
00271 (*it >= '0' && *it <= '9')
00272 || (*it >= 'A' && *it <= 'Z')
00273 || (*it >= 'a' && *it <= 'z')
00274 || (*it == '_')
00275 || (*it == '@')
00276 )
00277 )
00278 label.push_back(char(*it++));
00279 else
00280 return false;
00281
00282 // other char must be [0-9A-Za-z@_]*
00283 while (it != last &&
00284 (
00285 (*it >= '0' && *it <= '9')
00286 || (*it >= 'A' && *it <= 'Z')
00287 || (*it >= 'a' && *it <= 'z')
00288 || (*it == '_')
00289 || (*it == '@')
00290 )
00291 )
00292 label.push_back(char(*it++));
00293
00294 return true;
00295 }
|
|
||||||||||||||||||||||||
|
Parse a marked string. NB : usualy, we use [ and ] as string delimiters in translation files.
Definition at line 297 of file i18n.cpp. References nlwarning, and ucchar. Referenced by load(), and readTextFile().
00298 {
00299 // ucstring ret;
00300 result.erase();
00301 // parse a string delimited by the specified opening and closing mark
00302
00303 if (it != last && *it == openMark)
00304 {
00305 ++it;
00306
00307 while (it != last && *it != closeMark)
00308 {
00309 // ignore tab, new lines and line feed
00310 if (*it == openMark)
00311 {
00312 nlwarning("I18N: Found a non escaped openmark %c in a delimited string (Delimiters : '%c' - '%c')", char(openMark), char(openMark), char(closeMark));
00313 return false;
00314 }
00315 if (*it == '\t' || *it == '\n' || *it == '\r')
00316 ++it;
00317 else if (*it == '\\' && it+1 != last && *(it+1) != '\\')
00318 {
00319 ++it;
00320 // this is an escape sequence !
00321 switch(*it)
00322 {
00323 case 't':
00324 result.push_back('\t');
00325 break;
00326 case 'n':
00327 result.push_back('\n');
00328 break;
00329 case 'd':
00330 // insert a delete
00331 result.push_back(8);
00332 break;
00333 default:
00334 // escape the close mark ?
00335 if(*it == closeMark)
00336 result.push_back(closeMark);
00337 // escape the open mark ?
00338 else if(*it == openMark)
00339 result.push_back(openMark);
00340 else
00341 {
00342 nlwarning("I18N: Ignoring unknown escape code \\%c (char value : %u)", char(*it), *it);
00343 return false;
00344 }
00345 }
00346 ++it;
00347 }
00348 else if (*it == '\\' && it+1 != last && *(it+1) == '\\')
00349 {
00350 // escape the \ char
00351 ++it;
00352 result.push_back(*it);
00353 ++it;
00354 }
00355 else
00356 result.push_back(*it++);
00357 }
00358
00359 if (it == last || *it != closeMark)
00360 {
00361 nlwarning("I18N: Missing end of delimited string (Delimiters : '%c' - '%c')", char(openMark), char(closeMark));
00362 return false;
00363 }
00364 else
00365 ++it;
00366 }
00367 else
00368 {
00369 nlwarning("I18N: Malformed or non existent delimited string (Delimiters : '%c' - '%c')", char(openMark), char(closeMark));
00370 return false;
00371 }
00372
00373 return true;
00374 }
|
|
||||||||||||||||||||
|
Read the content of a buffer as a unicode text. This is to read preloaded unicode files. The method support 16 bits or 8bits utf-8 tagged buffer. 8 bits UTF-8 encofing can be reconized by a non official header : EF,BB, BF. 16 bits encoding can be reconized by the official header : FF, FE, witch can be reversed if the data are MSB first. Optionnaly, you can force the reader to consider the file as UTF-8 encoded. Definition at line 475 of file i18n.cpp. References buffer, ucstring::fromUtf8(), nlassert, size, src, uint, uint16, and uint8. Referenced by readTextFile().
00476 {
00477 static uint8 utf16Header[] = {char(0xff), char(0xfe)};
00478 static uint8 utf16RevHeader[] = {char(0xfe), char(0xff)};
00479 static uint8 utf8Header[] = {char(0xef), char(0xbb), char(0xbf)};
00480
00481 if (forceUtf8)
00482 {
00483 if (size>=3 &&
00484 buffer[0]==utf8Header[0] &&
00485 buffer[1]==utf8Header[1] &&
00486 buffer[2]==utf8Header[2]
00487 )
00488 {
00489 // remove utf8 header
00490 buffer+= 3;
00491 size-=3;
00492 }
00493 std::string text((char*)buffer, size);
00494 result.fromUtf8(text);
00495 }
00496 else if (size>=3 &&
00497 buffer[0]==utf8Header[0] &&
00498 buffer[1]==utf8Header[1] &&
00499 buffer[2]==utf8Header[2]
00500 )
00501 {
00502 // remove utf8 header
00503 buffer+= 3;
00504 size-=3;
00505 std::string text((char*)buffer, size);
00506 result.fromUtf8(text);
00507 }
00508 else if (size>=2 &&
00509 buffer[0]==utf16Header[0] &&
00510 buffer[1]==utf16Header[1]
00511 )
00512 {
00513 // remove utf16 header
00514 buffer+= 2;
00515 size-= 2;
00516 // check pair number of bytes
00517 nlassert((size & 1) == 0);
00518 // and do manual conversion
00519 uint16 *src = (uint16*)(buffer);
00520 result.resize(size/2);
00521 for (uint j=0; j<result.size(); j++)
00522 result[j]= *src++;
00523 }
00524 else if (size>=2 &&
00525 buffer[0]==utf16RevHeader[0] &&
00526 buffer[1]==utf16RevHeader[1]
00527 )
00528 {
00529 // remove utf16 header
00530 buffer+= 2;
00531 size-= 2;
00532 // check pair number of bytes
00533 nlassert((size & 1) == 0);
00534 // and do manual conversion
00535 uint16 *src = (uint16*)(buffer);
00536 result.resize(size/2);
00537 uint j;
00538 for (j=0; j<result.size(); j++)
00539 result[j]= *src++;
00540 // Reverse byte order
00541 for (j=0; j<result.size(); j++)
00542 {
00543 uint8 *pc = (uint8*) &result[j];
00544 std::swap(pc[0], pc[1]);
00545 }
00546 }
00547 else
00548 {
00549 // hum.. ascii read ?
00550 // so, just to a direct conversion
00551 std::string text((char*)buffer, size);
00552 result = text;
00553 }
00554 }
|
|
||||||||||||||||||||||||
|
Temporary, we don't have file system for now, so we do a tricky cheat. there s not check so be careful! Read the content of a file as a unicode text. The method support 16 bits or 8bits utf-8 tagged files. 8 bits UTF-8 encofing can be reconized by a non official header : EF,BB, BF. 16 bits encoding can be reconized by the official header : FF, FE, witch can be reversed if the data are MSB first. Optionnaly, you can force the reader to consider the file as UTF-8 encoded. Optionnaly, you can ask the reader to interpret #include commands. Definition at line 377 of file i18n.cpp. References ucstring::c_str(), file, nldebug, nlwarning, NLMISC::CIFile::open(), parseMarkedString(), readTextBuffer(), skipWhiteSpace(), ucstring::toString(), uint, and uint8. Referenced by load().
00378 {
00379 std::string fullName;
00380 if (fileLookup)
00381 fullName = CPath::lookup(filename, false);
00382 else
00383 fullName = filename;
00384
00385 if (fullName.empty())
00386 return;
00387
00388 // If ::lookup is used, the file can be in a bnp and CFile::fileExists fails.
00389 // \todo Boris
00390 bool isInBnp = fullName.find('@') != string::npos;
00391 if (!isInBnp && !CFile::fileExists(fullName))
00392 {
00393 nlwarning("CI18N::readTextFile : file '%s' does not exist, returing empty string", fullName.c_str());
00394 return;
00395 }
00396
00397 NLMISC::CIFile file(fullName);
00398
00399
00400 // Fast read all the text in binary mode.
00401 std::string text;
00402 text.resize(file.getFileSize());
00403 file.serialBuffer((uint8*)(&text[0]), text.size());
00404
00405 // Transform the string in ucstring according to format header
00406 if (!text.empty())
00407 readTextBuffer((uint8*)&text[0], text.size(), result, forceUtf8);
00408
00409 if (preprocess)
00410 {
00411 ucstring final;
00412 // parse the file, looking for preprocessor command.
00413 ucstring::size_type pos = 0;
00414 ucstring::size_type lastPos = 0;
00415 ucstring includeCmd("#include");
00416
00417 while ((pos = result.find(includeCmd, pos)) != ucstring::npos)
00418 {
00419 // copy the previous text
00420 final += result.substr(lastPos, pos - lastPos);
00421
00422 // extract the inserted file name.
00423 ucstring::const_iterator first, last;
00424 first = result.begin()+pos+includeCmd.size();
00425 last = result.end();
00426
00427 ucstring name;
00428 skipWhiteSpace(first, last);
00429 if (parseMarkedString('\"', '\"', first, last, name))
00430 {
00431 string subFilename = name.toString();
00432 nldebug("I18N: Including '%s' into '%s'",
00433 subFilename.c_str(),
00434 filename.c_str());
00435 ucstring inserted;
00436
00437 {
00438 CIFile testFile;
00439 if (!testFile.open(subFilename))
00440 {
00441 // try to open the include file relative to current file
00442 subFilename = CFile::getPath(filename)+subFilename;
00443 }
00444 }
00445 readTextFile(subFilename, inserted, forceUtf8, fileLookup, preprocess);
00446
00447 final += inserted;
00448 }
00449 else
00450 {
00451 nlwarning("I18N: Error parsing include file in line '%s' from file '%s'",
00452 result.substr(pos, result.find(ucstring("\n"), pos) - pos).c_str(),
00453 filename.c_str());
00454 }
00455
00456 pos = lastPos = first - result.begin();
00457 }
00458
00459 // copy the remaining chars
00460 ucstring temp = final;
00461
00462 for (uint i=lastPos; i<result.size(); ++i)
00463 {
00464 temp += result[i];
00465 }
00466
00467 // final = final + temp;
00468
00469 result.swap(temp);
00470 }
00471
00472
00473 }
|
|
|
Remove any C style comment from the passed string. Definition at line 168 of file i18n.cpp. Referenced by load().
00169 {
00170 {
00171 ucstring temp;
00172 temp.reserve(commentedString.size());
00173 ucstring::const_iterator first(commentedString.begin()), last(commentedString.end());
00174 for (;first != last; ++first)
00175 {
00176 temp.push_back(*first);
00177 if (*first == '[')
00178 {
00179 // no comment inside string literal
00180 while (++first != last)
00181 {
00182 temp.push_back(*first);
00183 if (*first == ']')
00184 break;
00185 }
00186 }
00187 else if (*first == '/')
00188 {
00189 // start of comment ?
00190 ++first;
00191 if (first != last && *first == '/')
00192 {
00193 temp.pop_back();
00194 // one line comment, skip until end of line
00195 while (first != last && *first != '\n')
00196 ++first;
00197 }
00198 else if (first != last && *first == '*')
00199 {
00200 temp.pop_back();
00201 // start of multiline comment, skip until we found '*/'
00202 while (first != last && !(*first == '*' && (first+1) != last && *(first+1) == '/'))
00203 ++first;
00204 // skip the closing '/'
00205 if (first != last)
00206 ++first;
00207 }
00208 else
00209 {
00210 temp.push_back(*first);
00211 }
00212 }
00213 }
00214
00215 commentedString.swap(temp);
00216 }
00217 }
|
|
|
Set the load proxy class. Proxy can be NULL to unregister.
Definition at line 61 of file i18n.cpp. References _LoadProxy.
00062 {
00063 _LoadProxy = loadProxy;
00064 }
|
|
||||||||||||||||
|
Skip the white space. You can optionnaly pass a ucstring pointer to receive any comments string that build the white space. This is usefull if you whant to keep the comments. NB : comments are appended to the comments string. Definition at line 220 of file i18n.cpp. Referenced by load(), and readTextFile().
00221 {
00222 while (it != last &&
00223 (
00224 *it == 0xa
00225 || *it == 0xd
00226 || *it == ' '
00227 || *it == '\t'
00228 || (storeComments && *it == '/' && it+1 != last && *(it+1) == '/')
00229 || (storeComments && *it == '/' && it+1 != last && *(it+1) == '*')
00230 ))
00231 {
00232 if (storeComments && *it == '/' && it+1 != last && *(it+1) == '/')
00233 {
00234 // found a one line C comment. Store it until end of line.
00235 while (it != last && *it != '\n')
00236 storeComments->push_back(*it++);
00237 // store the final '\n'
00238 if (it != last)
00239 storeComments->push_back(*it++);
00240 }
00241 else if (storeComments && *it == '/' && it+1 != last && *(it+1) == '*')
00242 {
00243 // found a multiline C++ comment. store until we found the closing '*/'
00244 while (it != last && !(*it == '*' && it+1 != last && *(it+1) == '/'))
00245 storeComments->push_back(*it++);
00246 // store the final '*'
00247 if (it != last)
00248 storeComments->push_back(*it++);
00249 // store the final '/'
00250 if (it != last)
00251 storeComments->push_back(*it++);
00252 // and a new line.
00253 storeComments->push_back('\r');
00254 storeComments->push_back('\n');
00255 }
00256 else
00257 {
00258 // just skip white space or don't store comments
00259 ++it;
00260 }
00261 }
00262 }
|
|
|
Definition at line 730 of file i18n.cpp. References nlassert, uint32, and uint64. Referenced by STRING_MANAGER::TGetWorksheetHashValue::operator()().
00731 {
00732 nlassert(str.size() == 16);
00733 uint32 low, hight;
00734
00735 string sl, sh;
00736 sh = str.substr(0, 8);
00737 sl = str.substr(8, 8);
00738
00739 sscanf(sh.c_str(), "%08X", &hight);
00740 sscanf(sl.c_str(), "%08X", &low);
00741
00742 uint64 hash;
00743 uint32 *ph = (uint32*)&hash;
00744
00745 ph[0] = hight;
00746 ph[1] = low;
00747
00748 return hash;
00749 }
|
|
||||||||||||||||
|
Write a unicode text file using unicode 16 or UTF-8 encoding. Definition at line 557 of file i18n.cpp. References encodeUTF8(), file, uint, and uint16.
00558 {
00559 COFile file(filename);
00560
00561 if (!utf8)
00562 {
00563 // write the unicode 16 bits tag
00564 uint16 unicodeTag = 0xfeff;
00565 file.serial(unicodeTag);
00566
00567 uint i;
00568 for (i=0; i<content.size(); ++i)
00569 {
00570 uint16 c = content[i];
00571 file.serial(c);
00572 }
00573 }
00574 else
00575 {
00576 static char utf8Header[] = {char(0xef), char(0xbb), char(0xbf), 0};
00577
00578 std::string str = encodeUTF8(content);
00579 // add the UTF-8 'not official' header
00580 str = utf8Header + str;
00581
00582 uint i;
00583 for (i=0; i<str.size(); ++i)
00584 {
00585 file.serial(str[i]);
00586 }
00587 }
00588 }
|
|
|
Initial value:
{
std::string("en"),
std::string("fr"),
std::string("zh-TW"),
std::string("zh-CN")
}
|
|
|
|
|
|
Definition at line 58 of file i18n.cpp. Referenced by load(), and setLoadProxy(). |
|
|
Definition at line 52 of file i18n.cpp. Referenced by load(). |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 54 of file i18n.cpp. Referenced by load(). |
1.3.6