LLViewerRegion WIP: brought LLTrans up to speed with V3.

This commit is contained in:
Aleric Inglewood
2012-02-18 02:17:32 +01:00
parent 787e03e821
commit 0a7fc0e65e
2 changed files with 83 additions and 2 deletions

View File

@@ -113,6 +113,69 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::
}
}
//static
std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
//V3: LLFastTimer timer(FTM_GET_TRANS);
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
std::string text = iter->second.mText;
LLStringUtil::format(text, msg_args);
return text;
}
else
{
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return "MissingString("+xml_desc+")";
}
}
//static
bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
{
//V3: LLFastTimer timer(FTM_GET_TRANS);
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
std::string text = iter->second.mText;
LLStringUtil::format_map_t args = sDefaultArgs;
args.insert(msg_args.begin(), msg_args.end());
LLStringUtil::format(text, args);
result = text;
return true;
}
else
{
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return false;
}
}
//static
bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD& msg_args)
{
//V3: LLFastTimer timer(FTM_GET_TRANS);
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
std::string text = iter->second.mText;
LLStringUtil::format(text, msg_args);
result = text;
return true;
}
else
{
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
return false;
}
}
void LLTrans::setDefaultArg(const std::string& name, const std::string& value)
{
sDefaultArgs[name] = value;

View File

@@ -60,12 +60,14 @@ public:
/**
* @brief Parses the xml file that holds the strings. Used once on startup
* @param xml_filename Filename to parse
// *FIXME * @param xml_filename Filename to parse
* @param default_args Set of strings (expected to be in the file) to use as default replacement args, e.g. "SECOND_LIFE"
* @returns true if the file was parsed successfully, true if something went wrong
*/
static bool parseStrings(const std::string& xml_filename, const std::set<std::string>& default_args);
//V3: static bool parseLanguageStrings(LLPointer<LLXMLNode> & root);
/**
* @brief Returns a translated string
* @param xml_desc String's description
@@ -73,6 +75,9 @@ public:
* @returns Translated string
*/
static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
static std::string getString(const std::string &xml_desc, const LLSD& args);
static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args);
static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args);
/**
* @brief Returns a translated string
@@ -84,7 +89,20 @@ public:
LLStringUtil::format_map_t empty;
return getString(xml_desc, empty);
}
static bool findString(std::string &result, const std::string &xml_desc)
{
LLStringUtil::format_map_t empty;
return findString(result, xml_desc, empty);
}
static std::string getKeyboardString(const char* keystring)
{
std::string key_str(keystring);
std::string trans_str;
return findString(trans_str, key_str) ? trans_str : key_str;
}
// get the default args
static const LLStringUtil::format_map_t& getDefaultArgs()
{