Merge branch 'master' of git://github.com/Shyotl/SingularityViewer

This commit is contained in:
Lirusaito
2012-01-09 05:10:15 -05:00
18 changed files with 495 additions and 375 deletions

View File

@@ -66,12 +66,12 @@ set(llui_SOURCE_FILES
lltextbox.cpp
lltexteditor.cpp
lltextparser.cpp
lltrans.cpp
llui.cpp
lluictrl.cpp
lluictrlfactory.cpp
lluiimage.cpp
lluistring.cpp
lluitrans.cpp
llundo.cpp
llviewborder.cpp
llview.cpp
@@ -128,6 +128,7 @@ set(llui_HEADER_FILES
lltextbox.h
lltexteditor.h
lltextparser.h
lltrans.h
lluiconstants.h
lluictrlfactory.h
lluictrl.h
@@ -135,7 +136,6 @@ set(llui_HEADER_FILES
llui.h
lluiimage.h
lluistring.h
lluitrans.h
lluixmltags.h
llundo.h
llviewborder.h

View File

@@ -59,8 +59,7 @@
#include "llresmgr.h"
#include "llui.h"
#include "lluitrans.h"
#include "lltrans.h"
#include "llstl.h"
#include "v2math.h"
@@ -271,24 +270,24 @@ void LLMenuItemGL::appendAcceleratorString( std::string& st ) const
{
if ( mAcceleratorMask & MASK_MAC_CONTROL )
{
st.append( LLUITrans::getString("accel-mac-control") );
st.append( LLTrans::getString("accel-mac-control") );
}
else
{
st.append( LLUITrans::getString("accel-mac-command") ); // Symbol would be "\xE2\x8C\x98"
st.append( LLTrans::getString("accel-mac-command") ); // Symbol would be "\xE2\x8C\x98"
}
}
if( mAcceleratorMask & MASK_ALT )
st.append( LLUITrans::getString("accel-mac-option") ); // Symbol would be "\xE2\x8C\xA5"
st.append( LLTrans::getString("accel-mac-option") ); // Symbol would be "\xE2\x8C\xA5"
if( mAcceleratorMask & MASK_SHIFT )
st.append( LLUITrans::getString("accel-mac-shift") ); // Symbol would be "\xE2\x8C\xA7"
st.append( LLTrans::getString("accel-mac-shift") ); // Symbol would be "\xE2\x8C\xA7"
#else
if( mAcceleratorMask & MASK_CONTROL )
st.append( LLUITrans::getString("accel-win-control") );
st.append( LLTrans::getString("accel-win-control") );
if( mAcceleratorMask & MASK_ALT )
st.append( LLUITrans::getString("accel-win-alt") );
st.append( LLTrans::getString("accel-win-alt") );
if( mAcceleratorMask & MASK_SHIFT )
st.append( LLUITrans::getString("accel-win-shift") );
st.append( LLTrans::getString("accel-win-shift") );
#endif
std::string keystr = LLKeyboard::stringFromKey( mAcceleratorKey );

View File

@@ -1,6 +1,6 @@
/**
* @file lluitrans.cpp
* @brief LLUITrans implementation
* @file lltrans.cpp
* @brief LLTrans implementation
*
* $LicenseInfo:firstyear=2000&license=viewergpl$
*
@@ -32,7 +32,7 @@
#include "linden_common.h"
#include "lluitrans.h"
#include "lltrans.h"
#include "llxmlnode.h"
#include "lluictrlfactory.h"
#include "llalertdialog.h"
@@ -40,10 +40,11 @@
#include <map>
LLUITrans::template_map_t LLUITrans::sStringTemplates;
LLTrans::template_map_t LLTrans::sStringTemplates;
LLStringUtil::format_map_t LLTrans::sDefaultArgs;
//static
bool LLUITrans::parseStrings(const std::string& xml_filename)
bool LLTrans::parseStrings(const std::string& xml_filename, const std::set<std::string>& default_args)
{
LLXMLNodePtr root;
BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root);
@@ -54,6 +55,7 @@ bool LLUITrans::parseStrings(const std::string& xml_filename)
return false;
}
sDefaultArgs.clear();
for (LLXMLNode* string = root->getFirstChild();
string != NULL; string = string->getNextSibling())
{
@@ -70,21 +72,32 @@ bool LLUITrans::parseStrings(const std::string& xml_filename)
continue;
}
LLUITransTemplate xml_template(string_name, string->getTextContents());
LLTransTemplate xml_template(string_name, string->getTextContents());
sStringTemplates[xml_template.mName] = xml_template;
std::set<std::string>::const_iterator iter = default_args.find(xml_template.mName);
if (iter != default_args.end())
{
std::string name = *iter;
if (name[0] != '[')
name = llformat("[%s]",name.c_str());
sDefaultArgs[name] = xml_template.mText;
}
}
return true;
}
//static
std::string LLUITrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args)
std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
{
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);
return text;
@@ -96,7 +109,7 @@ std::string LLUITrans::getString(const std::string &xml_desc, const LLStringUtil
LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
LLNotificationsUtil::add("MissingString", args);
return xml_desc;
return "MissingString("+xml_desc+")";
}
}

View File

@@ -30,34 +30,41 @@
* $/LicenseInfo$
*/
#ifndef LL_UI_TRANS_H
#define LL_UI_TRANS_H
#ifndef LL_TRANS_H
#define LL_TRANS_H
#include <map>
/**
* @brief String template loaded from strings.xml
*/
class LLUITransTemplate
class LLTransTemplate
{
public:
LLUITransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {}
LLTransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {}
std::string mName;
std::string mText;
};
class LLUITrans
/**
* @brief Localized strings class
* This class is used to retrieve translations of strings used to build larger ones, as well as
* strings with a general usage that don't belong to any specific floater. For example,
* "Owner:", "Retrieving..." used in the place of a not yet known name, etc.
*/
class LLTrans
{
public:
LLUITrans();
LLTrans();
/**
* @brief Parses the xml file that holds the strings. Used once on startup
* @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);
static bool parseStrings(const std::string& xml_filename, const std::set<std::string>& default_args);
/**
* @brief Returns a translated string
@@ -80,8 +87,9 @@ public:
private:
typedef std::map<std::string, LLUITransTemplate > template_map_t;
typedef std::map<std::string, LLTransTemplate > template_map_t;
static template_map_t sStringTemplates;
static LLStringUtil::format_map_t sDefaultArgs;
};
#endif