Public Member Functions | |
operator const char * () const | |
tLocaleItem (const char *identifier) | |
~tLocaleItem () | |
Static Public Member Functions | |
static void | Load (const char *file, bool complete=true) |
static void | Clear () |
static tLocaleItem & | Find (const char *identifier) |
Private Attributes | |
tString | identifier |
tLocaleSubItem * | items |
bool | istemplate |
Friends | |
class | tLocaleSubItem |
Definition at line 44 of file tLocale.cpp.
tLocaleItem::tLocaleItem | ( | const char * | identifier | ) |
Definition at line 276 of file tLocale.cpp.
Referenced by Find().
00277 :tListItem<tLocaleItem>(st_localeAnchor), 00278 :identifier(id), items(NULL), istemplate(false) 00279 { 00280 }
tLocaleItem::~tLocaleItem | ( | ) |
tLocaleItem::operator const char * | ( | ) | const |
Definition at line 193 of file tLocale.cpp.
References c, tString::Clear(), tLanguage::FindStrict(), identifier, istemplate, items, tLocaleSubItem::language, tString::Len(), tLanguage::Load(), tListItem< T >::Next(), NULL, s_gameName, and tLocaleSubItem::translation.
00194 { 00195 static tLanguage * english = tLanguage::FindStrict( tString("British English") ); 00196 00197 tString *first = NULL, *second = NULL, *third = NULL, *fourth = NULL; 00198 const tString *ret = NULL; 00199 00200 tLocaleSubItem *run = items; 00201 while (run) 00202 { 00203 if (st_firstLanguage && run->language == st_firstLanguage) 00204 first = &run->translation; 00205 00206 if (st_secondLanguage && run->language == st_secondLanguage) 00207 second = &run->translation; 00208 00209 if (run->language == english) 00210 third = &run->translation; 00211 00212 fourth = &run->translation; 00213 run = run->Next(); 00214 } 00215 00216 if (first) 00217 ret = first; 00218 else if (second) 00219 ret = second; 00220 else 00221 { 00222 if (third) 00223 ret = third; 00224 else 00225 { 00226 // load english and try again 00227 static bool loadEnglish = true; 00228 if ( loadEnglish ) 00229 { 00230 loadEnglish = false; 00231 english->Load(); 00232 return *this; 00233 } 00234 } 00235 00236 if (!ret && fourth) 00237 ret = fourth; 00238 if (!ret) 00239 ret = &identifier; 00240 } 00241 00242 if (!istemplate) 00243 return *ret; // no template replacements need to be made 00244 else 00245 { 00246 const tString& temp = *ret; 00247 static tString replaced; 00248 replaced.Clear(); 00249 for(int i = 0; i < temp.Len(); i++) 00250 { 00251 char c = temp(i); 00252 if (c != '\\') 00253 replaced += c; 00254 else if (i < temp.Len() - 1) 00255 { 00256 c = temp(i+1); 00257 if (c == 'g') 00258 replaced << s_gameName; 00259 else 00260 { 00261 int index = c-'0'; 00262 if (index > 0 && index < 10) 00263 replaced << st_TemplateParameters[index]; 00264 else if (temp(i+1) == '\\') 00265 replaced << '\n'; 00266 } 00267 i++; 00268 } 00269 } 00270 00271 return replaced; 00272 } 00273 }
void tLocaleItem::Load | ( | const char * | file, | |
bool | complete = true | |||
) | [static] |
Definition at line 329 of file tLocale.cpp.
References c, tString::Clear(), tDirectories::Data(), Find(), tLanguage::Find(), INCLUDE, istemplate, items, tLocaleSubItem::language, LANGUAGE, tLanguage::LoadLater(), tListItem< T >::Next(), tString::ReadLine(), tString::Size(), tNEW, and tLocaleSubItem::translation.
Referenced by tLocale::Load(), and tLanguage::Load().
00330 { 00331 // bool check = false; 00332 { 00333 tString f; 00334 00335 f << "language/" << file; 00336 00337 std::ifstream s; 00338 if ( tDirectories::Data().Open( s, f ) ) 00339 { 00340 while (!s.eof() && s.good()) 00341 { 00342 tString id; 00343 s >> id; 00344 00345 if (id.Len() <= 1 ) 00346 { 00347 continue; 00348 } 00349 00350 if(id[0] == '#') 00351 { 00352 tString dummy; 00353 dummy.ReadLine(s); 00354 continue; 00355 } 00356 00357 if (LANGUAGE == id) 00358 { 00359 tString lang; 00360 lang.ReadLine(s); 00361 currentLanguage = tLanguage::Find(lang); 00362 00363 // delayed loading 00364 if (!complete) 00365 { 00366 currentLanguage->LoadLater(file); 00367 return; 00368 } 00369 continue; 00370 } 00371 00372 if (INCLUDE == id) 00373 { 00374 tString inc; 00375 inc.ReadLine(s); 00376 Load(inc, complete); 00377 continue; 00378 } 00379 00380 /* 00381 if (CHECK == id) 00382 { 00383 check = true; 00384 tString dummy; 00385 dummy.ReadLine(s); 00386 continue; 00387 } 00388 */ 00389 00390 // id is a true string identifier. 00391 tLocaleItem &li = Find(id); 00392 tLocaleSubItem *r = li.items; 00393 bool done = false; 00394 while (r && !done) 00395 { 00396 if (r->language == currentLanguage) 00397 { 00398 // r->translation.ReadLine(s); 00399 done = true; 00400 continue; 00401 } 00402 r = r->Next(); 00403 } 00404 00405 if (!done) 00406 r = tNEW(tLocaleSubItem)(&li); 00407 else 00408 { 00409 // st_Breakpoint(); 00410 // con << "Locale item " << id << " defined twice in language " 00411 // << currentLanguage->Name() << ".\n"; 00412 } 00413 00414 tString pre; 00415 pre.ReadLine(s); 00416 r->translation.Clear(); 00417 00418 for (size_t i=0; i< pre.Size(); i++) 00419 { 00420 char c = pre(i); 00421 if (c != '\\') 00422 r->translation += c; 00423 else if (i < pre.Size()) 00424 switch (pre(i+1)) 00425 { 00426 case 'n': 00427 r->translation += '\n'; 00428 i++; 00429 break; 00430 00431 case '1': 00432 case '2': 00433 case '3': 00434 case '4': 00435 case '5': 00436 case '6': 00437 case '7': 00438 case '8': 00439 case '9': 00440 case 'g': 00441 r->translation += '\\'; 00442 li.istemplate = true; 00443 break; 00444 00445 /* 00446 case '\\': 00447 r->translation << "\\\\"; 00448 i++; 00449 */ 00450 00451 default: 00452 r->translation += '\\'; 00453 break; 00454 } 00455 } 00456 00457 r->language = currentLanguage; 00458 // r->translation.ReadLine(s); 00459 00460 00461 } 00462 } 00463 } 00464 00465 /* 00466 if (check) 00467 Check(); 00468 */ 00469 }
void tLocaleItem::Clear | ( | void | ) | [static] |
Definition at line 289 of file tLocale.cpp.
Referenced by tLocale::Clear().
00290 { 00291 //while (st_localeAnchor) 00292 // delete (st_localeAnchor); 00293 00294 while (st_languageAnchor) 00295 delete (st_languageAnchor); 00296 }
tLocaleItem & tLocaleItem::Find | ( | const char * | identifier | ) | [static] |
Definition at line 299 of file tLocale.cpp.
References tLocaleItem(), and tNEW.
Referenced by tLocale::Find(), and Load().
00300 { 00301 /* 00302 tLocaleItem *ret = st_localeAnchor; 00303 tString n(nn); 00304 00305 while (ret) 00306 { 00307 if (ret->identifier == n) 00308 return *ret; 00309 ret = ret->Next(); 00310 } 00311 00312 00313 return *tNEW(tLocaleItem(n)); 00314 */ 00315 static tLocaleItemMap st_localeMap; 00316 00317 tJUST_CONTROLLED_PTR< tLocaleItem > & ret = st_localeMap[ nn ]; 00318 00319 if ( !ret ) 00320 ret = tNEW(tLocaleItem(nn)); 00321 00322 return *ret; 00323 }
friend class tLocaleSubItem [friend] |
Definition at line 46 of file tLocale.cpp.
tString tLocaleItem::identifier [private] |
tLocaleSubItem* tLocaleItem::items [private] |
Definition at line 49 of file tLocale.cpp.
Referenced by Load(), operator const char *(), and ~tLocaleItem().
bool tLocaleItem::istemplate [private] |