PageRenderTime 42ms CodeModel.GetById 25ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llxuixml/lltrans.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 133 lines | 56 code | 20 blank | 57 comment | 0 complexity | 3bbae520ce8ceb6ab059e46b05819e9f MD5 | raw file
  1/**
  2 * @file lltrans.h
  3 * @brief LLTrans definition
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_TRANS_H
 28#define LL_TRANS_H
 29
 30#include <map>
 31
 32#include "llpointer.h"
 33#include "llstring.h"
 34
 35class LLXMLNode;
 36
 37class LLSD;
 38
 39/**
 40 * @brief String template loaded from strings.xml
 41 */
 42class LLTransTemplate
 43{
 44public:
 45	LLTransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {}
 46
 47	std::string mName;
 48	std::string mText;
 49};
 50
 51/**
 52 * @brief Localized strings class
 53 * This class is used to retrieve translations of strings used to build larger ones, as well as
 54 * strings with a general usage that don't belong to any specific floater. For example,
 55 * "Owner:", "Retrieving..." used in the place of a not yet known name, etc.
 56 */
 57class LLTrans
 58{
 59public:
 60	LLTrans();
 61
 62	/**
 63	 * @brief Parses the xml root that holds the strings. Used once on startup
 64// *FIXME	 * @param xml_filename Filename to parse
 65	 * @param default_args Set of strings (expected to be in the file) to use as default replacement args, e.g. "SECOND_LIFE"
 66	 * @returns true if the file was parsed successfully, true if something went wrong
 67	 */
 68	static bool parseStrings(LLPointer<LLXMLNode> & root, const std::set<std::string>& default_args);
 69
 70	static bool parseLanguageStrings(LLPointer<LLXMLNode> & root);
 71
 72	/**
 73	 * @brief Returns a translated string
 74	 * @param xml_desc String's description
 75	 * @param args A list of substrings to replace in the string
 76	 * @returns Translated string
 77	 */
 78	static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
 79	static std::string getString(const std::string &xml_desc, const LLSD& args);
 80	static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args);
 81	static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args);
 82
 83	// Returns translated string with [COUNT] replaced with a number, following
 84	// special per-language logic for plural nouns.  For example, some languages
 85	// may have different plurals for 0, 1, 2 and > 2.
 86	// See "AgeWeeksA", "AgeWeeksB", etc. in strings.xml for examples.
 87	static std::string getCountString(const std::string& language, const std::string& xml_desc, S32 count);
 88
 89	/**
 90	 * @brief Returns a translated string
 91	 * @param xml_desc String's description
 92	 * @returns Translated string
 93	 */
 94	static std::string getString(const std::string &xml_desc)
 95	{
 96		LLStringUtil::format_map_t empty;
 97		return getString(xml_desc, empty);
 98	}
 99
100	static bool findString(std::string &result, const std::string &xml_desc)
101	{
102		LLStringUtil::format_map_t empty;
103		return findString(result, xml_desc, empty);
104	}
105
106	static std::string getKeyboardString(const char* keystring)
107	{
108		std::string key_str(keystring);
109		std::string trans_str;
110		return findString(trans_str, key_str) ? trans_str : key_str; 
111	}
112
113	// get the default args
114	static const LLStringUtil::format_map_t& getDefaultArgs()
115	{
116		return sDefaultArgs;
117	}
118
119	static void setDefaultArg(const std::string& name, const std::string& value);
120
121	// insert default args into an arg list
122	static void getArgs(LLStringUtil::format_map_t& args)
123	{
124		args.insert(sDefaultArgs.begin(), sDefaultArgs.end());
125	}
126	
127private:
128	typedef std::map<std::string, LLTransTemplate > template_map_t;
129	static template_map_t sStringTemplates;
130	static LLStringUtil::format_map_t sDefaultArgs;
131};
132
133#endif