diff options
Diffstat (limited to 'linden/indra/llui/lluitrans.cpp')
-rw-r--r-- | linden/indra/llui/lluitrans.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/linden/indra/llui/lluitrans.cpp b/linden/indra/llui/lluitrans.cpp new file mode 100644 index 0000000..920fe6a --- /dev/null +++ b/linden/indra/llui/lluitrans.cpp | |||
@@ -0,0 +1,101 @@ | |||
1 | /** | ||
2 | * @file lluitrans.cpp | ||
3 | * @brief LLUITrans implementation | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2000-2009, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at | ||
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | |||
33 | |||
34 | #include "linden_common.h" | ||
35 | #include "lluitrans.h" | ||
36 | #include "llxmlnode.h" | ||
37 | #include "lluictrlfactory.h" | ||
38 | #include "llalertdialog.h" | ||
39 | |||
40 | #include <map> | ||
41 | |||
42 | LLUITrans::template_map_t LLUITrans::sStringTemplates; | ||
43 | |||
44 | //static | ||
45 | bool LLUITrans::parseStrings(const std::string& xml_filename) | ||
46 | { | ||
47 | LLXMLNodePtr root; | ||
48 | BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); | ||
49 | |||
50 | if (!success || root.isNull() || !root->hasName( "strings" )) | ||
51 | { | ||
52 | llerrs << "Problem reading strings: " << xml_filename << llendl; | ||
53 | return false; | ||
54 | } | ||
55 | |||
56 | for (LLXMLNode* string = root->getFirstChild(); | ||
57 | string != NULL; string = string->getNextSibling()) | ||
58 | { | ||
59 | if (!string->hasName("string")) | ||
60 | { | ||
61 | continue; | ||
62 | } | ||
63 | |||
64 | std::string string_name; | ||
65 | |||
66 | if (! string->getAttributeString("name", string_name)) | ||
67 | { | ||
68 | llwarns << "Unable to parse string with no name" << llendl; | ||
69 | continue; | ||
70 | } | ||
71 | |||
72 | LLUITransTemplate xml_template(string_name, string->getTextContents()); | ||
73 | sStringTemplates[xml_template.mName] = xml_template; | ||
74 | } | ||
75 | |||
76 | return true; | ||
77 | } | ||
78 | |||
79 | //static | ||
80 | std::string LLUITrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args) | ||
81 | { | ||
82 | template_map_t::iterator iter = sStringTemplates.find(xml_desc); | ||
83 | |||
84 | if (iter != sStringTemplates.end()) | ||
85 | { | ||
86 | std::string text = iter->second.mText; | ||
87 | LLStringUtil::format(text, args); | ||
88 | |||
89 | return text; | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | LLSD args; | ||
94 | args["STRING_NAME"] = xml_desc; | ||
95 | LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; | ||
96 | LLNotifications::instance().add("MissingString", args); | ||
97 | |||
98 | return xml_desc; | ||
99 | } | ||
100 | } | ||
101 | |||