summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authormaxim_productengine <mnikolenko@productengine.com>2018-01-30 17:45:04 +0200
committermaxim_productengine <mnikolenko@productengine.com>2018-01-30 17:45:04 +0200
commit22050467f5ec42b30e98d7bd59dd0ca617b259e4 (patch)
treeb2a0ed35a9a4358f52b9663a73d9e687bc9ee586 /indra/llui
parent6e445e82e2a1c1559be5193cd2c131c5f1207f55 (diff)
MAINT-8180 Add the way to get default string despite of current localiztion
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/lltrans.cpp60
-rw-r--r--indra/llui/lltrans.h9
2 files changed, 62 insertions, 7 deletions
diff --git a/indra/llui/lltrans.cpp b/indra/llui/lltrans.cpp
index 4d4ff4236d..a1a8feedaa 100644
--- a/indra/llui/lltrans.cpp
+++ b/indra/llui/lltrans.cpp
@@ -36,6 +36,7 @@
#include <map>
LLTrans::template_map_t LLTrans::sStringTemplates;
+LLTrans::template_map_t LLTrans::sDefaultStringTemplates;
LLStringUtil::format_map_t LLTrans::sDefaultArgs;
struct StringDef : public LLInitParam::Block<StringDef>
@@ -76,7 +77,7 @@ bool LLTrans::parseStrings(LLXMLNodePtr &root, const std::set<std::string>& defa
LL_ERRS() << "Problem reading strings: " << xml_filename << LL_ENDL;
return false;
}
-
+ static bool default_strings_init = false;
sStringTemplates.clear();
sDefaultArgs.clear();
@@ -86,7 +87,10 @@ bool LLTrans::parseStrings(LLXMLNodePtr &root, const std::set<std::string>& defa
{
LLTransTemplate xml_template(it->name, it->value);
sStringTemplates[xml_template.mName] = xml_template;
-
+ if (!default_strings_init)
+ {
+ sDefaultStringTemplates[xml_template.mName] = xml_template;
+ }
std::set<std::string>::const_iterator iter = default_args.find(xml_template.mName);
if (iter != default_args.end())
{
@@ -96,6 +100,7 @@ bool LLTrans::parseStrings(LLXMLNodePtr &root, const std::set<std::string>& defa
sDefaultArgs[name] = xml_template.mText;
}
}
+ default_strings_init = true;
return true;
}
@@ -138,12 +143,17 @@ bool LLTrans::parseLanguageStrings(LLXMLNodePtr &root)
static LLTrace::BlockTimerStatHandle FTM_GET_TRANS("Translate string");
//static
-std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
+std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args, bool def_string)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
LL_RECORD_BLOCK_TIME(FTM_GET_TRANS);
+ if (def_string)
+ {
+ return getDefString(xml_desc, msg_args);
+ }
+
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
@@ -161,13 +171,38 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::
}
}
+//static
+std::string LLTrans::getDefString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
+{
+ template_map_t::iterator iter = sDefaultStringTemplates.find(xml_desc);
+ if (iter != sDefaultStringTemplates.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);
+
+ return text;
+ }
+ else
+ {
+ LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
+ return "MissingString(" + xml_desc + ")";
+ }
+}
+
//static
-std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args)
+std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args, bool def_string)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
LL_RECORD_BLOCK_TIME(FTM_GET_TRANS);
+ if (def_string)
+ {
+ return getDefString(xml_desc, msg_args);
+ }
+
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
@@ -182,6 +217,23 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args
}
}
+//static
+std::string LLTrans::getDefString(const std::string &xml_desc, const LLSD& msg_args)
+{
+ template_map_t::iterator iter = sDefaultStringTemplates.find(xml_desc);
+ if (iter != sDefaultStringTemplates.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)
{
diff --git a/indra/llui/lltrans.h b/indra/llui/lltrans.h
index a47ce94f08..bdffc75f4f 100644
--- a/indra/llui/lltrans.h
+++ b/indra/llui/lltrans.h
@@ -76,8 +76,10 @@ public:
* @param args A list of substrings to replace in the string
* @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 std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args, bool def_string = false);
+ static std::string getDefString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
+ static std::string getString(const std::string &xml_desc, const LLSD& args, bool def_string = false);
+ static std::string getDefString(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);
@@ -92,7 +94,7 @@ public:
* @param xml_desc String's description
* @returns Translated string
*/
- static std::string getString(const std::string &xml_desc)
+ static std::string getString(const std::string &xml_desc, bool def_string = false)
{
LLStringUtil::format_map_t empty;
return getString(xml_desc, empty);
@@ -128,6 +130,7 @@ public:
private:
typedef std::map<std::string, LLTransTemplate > template_map_t;
static template_map_t sStringTemplates;
+ static template_map_t LLTrans::sDefaultStringTemplates;
static LLStringUtil::format_map_t sDefaultArgs;
};