PageRenderTime 166ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_TRANS_H
  27. #define LL_TRANS_H
  28. #include <map>
  29. #include "llpointer.h"
  30. #include "llstring.h"
  31. class LLXMLNode;
  32. class LLSD;
  33. /**
  34. * @brief String template loaded from strings.xml
  35. */
  36. class LLTransTemplate
  37. {
  38. public:
  39. LLTransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {}
  40. std::string mName;
  41. std::string mText;
  42. };
  43. /**
  44. * @brief Localized strings class
  45. * This class is used to retrieve translations of strings used to build larger ones, as well as
  46. * strings with a general usage that don't belong to any specific floater. For example,
  47. * "Owner:", "Retrieving..." used in the place of a not yet known name, etc.
  48. */
  49. class LLTrans
  50. {
  51. public:
  52. LLTrans();
  53. /**
  54. * @brief Parses the xml root that holds the strings. Used once on startup
  55. // *FIXME * @param xml_filename Filename to parse
  56. * @param default_args Set of strings (expected to be in the file) to use as default replacement args, e.g. "SECOND_LIFE"
  57. * @returns true if the file was parsed successfully, true if something went wrong
  58. */
  59. static bool parseStrings(LLPointer<LLXMLNode> & root, const std::set<std::string>& default_args);
  60. static bool parseLanguageStrings(LLPointer<LLXMLNode> & root);
  61. /**
  62. * @brief Returns a translated string
  63. * @param xml_desc String's description
  64. * @param args A list of substrings to replace in the string
  65. * @returns Translated string
  66. */
  67. static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
  68. static std::string getString(const std::string &xml_desc, const LLSD& args);
  69. static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args);
  70. static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args);
  71. // Returns translated string with [COUNT] replaced with a number, following
  72. // special per-language logic for plural nouns. For example, some languages
  73. // may have different plurals for 0, 1, 2 and > 2.
  74. // See "AgeWeeksA", "AgeWeeksB", etc. in strings.xml for examples.
  75. static std::string getCountString(const std::string& language, const std::string& xml_desc, S32 count);
  76. /**
  77. * @brief Returns a translated string
  78. * @param xml_desc String's description
  79. * @returns Translated string
  80. */
  81. static std::string getString(const std::string &xml_desc)
  82. {
  83. LLStringUtil::format_map_t empty;
  84. return getString(xml_desc, empty);
  85. }
  86. static bool findString(std::string &result, const std::string &xml_desc)
  87. {
  88. LLStringUtil::format_map_t empty;
  89. return findString(result, xml_desc, empty);
  90. }
  91. static std::string getKeyboardString(const char* keystring)
  92. {
  93. std::string key_str(keystring);
  94. std::string trans_str;
  95. return findString(trans_str, key_str) ? trans_str : key_str;
  96. }
  97. // get the default args
  98. static const LLStringUtil::format_map_t& getDefaultArgs()
  99. {
  100. return sDefaultArgs;
  101. }
  102. static void setDefaultArg(const std::string& name, const std::string& value);
  103. // insert default args into an arg list
  104. static void getArgs(LLStringUtil::format_map_t& args)
  105. {
  106. args.insert(sDefaultArgs.begin(), sDefaultArgs.end());
  107. }
  108. private:
  109. typedef std::map<std::string, LLTransTemplate > template_map_t;
  110. static template_map_t sStringTemplates;
  111. static LLStringUtil::format_map_t sDefaultArgs;
  112. };
  113. #endif