1 | // Aseprite |
---|---|
2 | // Copyright (C) 2017 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/i18n/xml_translator.h" |
12 | |
13 | #include "app/i18n/strings.h" |
14 | #include "tinyxml.h" |
15 | |
16 | namespace app { |
17 | |
18 | std::string XmlTranslator::operator()(const TiXmlElement* elem, |
19 | const char* attrName) |
20 | { |
21 | const char* value = elem->Attribute(attrName); |
22 | if (!value) |
23 | return std::string(); |
24 | else if (value[0] == '@') { // Translate string |
25 | if (value[1] == '.') |
26 | return Strings::instance()->translate((m_stringIdPrefix + (value+1)).c_str()); |
27 | else |
28 | return Strings::instance()->translate(value+1); |
29 | } |
30 | else if (value[0] == '!') // Raw string |
31 | return std::string(value+1); |
32 | else |
33 | return std::string(value); |
34 | } |
35 | |
36 | void XmlTranslator::clearStringIdPrefix() |
37 | { |
38 | m_stringIdPrefix.clear(); |
39 | } |
40 | |
41 | void XmlTranslator::setStringIdPrefix(const char* prefix) |
42 | { |
43 | m_stringIdPrefix = prefix; |
44 | } |
45 | |
46 | } // namespace app |
47 |