diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2012-10-16 09:56:45 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2012-10-16 09:56:45 -0400 |
commit | 988767d5ec4631ad9f0099180a92c4f186553940 (patch) | |
tree | 7ce37b43288813407c0d69fa5eb0b6f2a0a8bcc8 | |
parent | c5373b90eb2de8f29be6801a07e937064ecb7fbb (diff) |
Introduce LLAppViewer::initStrings(); reload default_trans_args.
Calling LLTrans::setDefaultArg() after LLTransUtil::parseStrings() is almost
good enough -- but it fails to address the case in which one or more of the
default_trans_args strings (e.g. "create_account_url") embeds a reference to
the new substitution. So after the setDefaultArg() call, go back through
default_trans_args, refetching each string to perform the substitution and
updating it with a setDefaultArg() call of its own. All this is way too much
logic to replicate in both LLAppViewer::initConfiguration() and init(), so
break out new LLAppViewer::initStrings() method and call it from both places.
-rw-r--r-- | indra/newview/llappviewer.cpp | 62 | ||||
-rw-r--r-- | indra/newview/llappviewer.h | 1 |
2 files changed, 52 insertions, 11 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 9637bd328e..0c4c8a66e5 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -114,6 +114,7 @@ #include "llnotificationsutil.h" #include "llleap.h" +#include "stringize.h" // Third party library includes #include <boost/bind.hpp> @@ -768,11 +769,7 @@ bool LLAppViewer::init() LL_INFOS("InitInfo") << "UI initialized." << LL_ENDL ; // Setup paths and LLTrans after LLUI::initClass has been called. - LLUI::setupPaths(); - LLTransUtil::parseStrings("strings.xml", default_trans_args); - LLTransUtil::parseLanguageStrings("language_settings.xml"); - // parseStrings() sets up the LLTrans substitution table. Add this one item. - LLTrans::setDefaultArg("[sourceid]", gSavedSettings.getString("sourceid")); + initStrings(); // Setup notifications after LLUI::setupPaths() has been called. LLNotifications::instance(); @@ -2240,12 +2237,8 @@ bool LLAppViewer::initConfiguration() OSMessageBox(msg.str(),LLStringUtil::null,OSMB_OK); return false; } - - LLUI::setupPaths(); // setup paths for LLTrans based on settings files only - LLTransUtil::parseStrings("strings.xml", default_trans_args); - LLTransUtil::parseLanguageStrings("language_settings.xml"); - // parseStrings() sets up the LLTrans substitution table. Add this one item. - LLTrans::setDefaultArg("[sourceid]", gSavedSettings.getString("sourceid")); + + initStrings(); // setup paths for LLTrans based on settings files only // - set procedural settings // Note: can't use LL_PATH_PER_SL_ACCOUNT for any of these since we haven't logged in yet gSavedSettings.setString("ClientSettingsFile", @@ -2730,6 +2723,53 @@ bool LLAppViewer::initConfiguration() return true; // Config was successful. } +// The following logic is replicated in initConfiguration() (to be able to get +// some initial strings before we've finished initializing enough to know the +// current language) and also in init() (to initialize for real). Somehow it +// keeps growing, necessitating a method all its own. +void LLAppViewer::initStrings() +{ + LLUI::setupPaths(); + LLTransUtil::parseStrings("strings.xml", default_trans_args); + LLTransUtil::parseLanguageStrings("language_settings.xml"); + + // parseStrings() sets up the LLTrans substitution table. Add this one item. + LLTrans::setDefaultArg("[sourceid]", gSavedSettings.getString("sourceid")); + + // Now that we've set "[sourceid]", have to go back through + // default_trans_args and reinitialize all those other keys because some + // of them, in turn, reference "[sourceid]". + BOOST_FOREACH(std::string key, default_trans_args) + { + std::string brackets(key), nobrackets(key); + // Invalid to inspect key[0] if key is empty(). But then, the entire + // body of this loop is pointless if key is empty(). + if (key.empty()) + continue; + + if (key[0] != '[') + { + // key was passed without brackets. That means that 'nobrackets' + // is correct but 'brackets' is not. + brackets = STRINGIZE('[' << brackets << ']'); + } + else + { + // key was passed with brackets. That means that 'brackets' is + // correct but 'nobrackets' is not. Erase the left bracket. + nobrackets.erase(0, 1); + std::string::size_type length(nobrackets.length()); + if (length && nobrackets[length - 1] == ']') + { + nobrackets.erase(length - 1); + } + } + // Calling LLTrans::getString() is what embeds the other default + // translation strings into this one. + LLTrans::setDefaultArg(brackets, LLTrans::getString(nobrackets)); + } +} + namespace { // *TODO - decide if there's a better place for these functions. // do we need a file llupdaterui.cpp or something? -brad diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h index ae3c795d1e..5a3a41690a 100644 --- a/indra/newview/llappviewer.h +++ b/indra/newview/llappviewer.h @@ -194,6 +194,7 @@ private: void initMaxHeapSize(); bool initThreads(); // Initialize viewer threads, return false on failure. bool initConfiguration(); // Initialize settings from the command line/config file. + void initStrings(); // Initialize LLTrans machinery void initUpdater(); // Initialize the updater service. bool initCache(); // Initialize local client cache. void checkMemory() ; |