From e54e9b4eed615f98f1e1fd167178b6d75c3fda43 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 11 May 2011 17:36:11 -0700 Subject: WIP: viewer side of ER-864: Include message ids and args in login.cgi responses * Look for message_id and message_args in XMLRPC response, look up localized string in strings.xml * Support sub-maps in XMLRPC response conversion to LLSD * Explicitly request extended error info during login (since including sub-maps breaks older viewers) * Support LLSD-based substitutions in LLTrans::getString/findString --- indra/llxuixml/lltrans.cpp | 50 +++++++++++++++++++++++++++++++++++++--------- indra/llxuixml/lltrans.h | 4 ++++ 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'indra/llxuixml') diff --git a/indra/llxuixml/lltrans.cpp b/indra/llxuixml/lltrans.cpp index e13d73c640..7619e4b7ac 100644 --- a/indra/llxuixml/lltrans.cpp +++ b/indra/llxuixml/lltrans.cpp @@ -30,6 +30,7 @@ #include "llfasttimer.h" // for call count statistics #include "llxuiparser.h" +#include "llsd.h" #include @@ -154,13 +155,28 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil:: } else { - LLSD args; - args["STRING_NAME"] = xml_desc; LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; + return "MissingString("+xml_desc+")"; + } +} - //LLNotificationsUtil::add("MissingString", args); // *TODO: resurrect - //return xml_desc; +//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 + 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+")"; } } @@ -182,11 +198,27 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const } else { - LLSD args; - args["STRING_NAME"] = xml_desc; - LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - //LLNotificationsUtil::add("MissingString", args); - + 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) +{ + 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; } } diff --git a/indra/llxuixml/lltrans.h b/indra/llxuixml/lltrans.h index 5b127b53cf..63f7d431d3 100644 --- a/indra/llxuixml/lltrans.h +++ b/indra/llxuixml/lltrans.h @@ -32,6 +32,8 @@ #include "llstring.h" #include "llxmlnode.h" +class LLSD; + /** * @brief String template loaded from strings.xml */ @@ -72,7 +74,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); // Returns translated string with [COUNT] replaced with a number, following // special per-language logic for plural nouns. For example, some languages -- cgit v1.2.3