00001 00033 #include "llviewerprecompiledheaders.h" 00034 #include "lltrans.h" 00035 #include "llxmlnode.h" 00036 #include "lluictrlfactory.h" 00037 #include "llalertdialog.h" 00038 00039 #include <map> 00040 00041 LLTrans::template_map_t LLTrans::sStringTemplates; 00042 00043 //static 00044 bool LLTrans::parseStrings(const LLString& xml_filename) 00045 { 00046 LLXMLNodePtr root; 00047 BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); 00048 00049 if (!success || root.isNull() || !root->hasName( "strings" )) 00050 { 00051 llerrs << "Problem reading strings: " << xml_filename << llendl; 00052 return false; 00053 } 00054 00055 for (LLXMLNode* string = root->getFirstChild(); 00056 string != NULL; string = string->getNextSibling()) 00057 { 00058 if (!string->hasName("string")) 00059 { 00060 continue; 00061 } 00062 00063 LLString string_name; 00064 00065 if (! string->getAttributeString("name", string_name)) 00066 { 00067 llwarns << "Unable to parse string with no name" << llendl; 00068 continue; 00069 } 00070 00071 LLTransTemplate xml_template(string_name, string->getTextContents()); 00072 sStringTemplates[xml_template.mName] = xml_template; 00073 } 00074 00075 return true; 00076 } 00077 00078 //static 00079 LLString LLTrans::getString(const LLString &xml_desc, const LLString::format_map_t& args) 00080 { 00081 template_map_t::iterator iter = sStringTemplates.find(xml_desc); 00082 00083 if (iter != sStringTemplates.end()) 00084 { 00085 LLString text = iter->second.mText; 00086 LLString::format(text, args); 00087 00088 return text; 00089 } 00090 else 00091 { 00092 LLString::format_map_t args; 00093 args["[STRING_NAME]"] = xml_desc; 00094 llwarns << "Missing String: [" << xml_desc << "]" << llendl; 00095 LLAlertDialog* dialogp = LLAlertDialog::showXml("MissingString", args); 00096 if (dialogp == NULL) 00097 { 00098 llerrs << "Bad or missing alerts.xml!" << llendl; 00099 } 00100 return ""; 00101 } 00102 } 00103