lltrans.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file lltrans.h
  3. * @brief LLTrans definition
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. * Copyright (c) 2023, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_TRANS_H
  34. #define LL_TRANS_H
  35. #include "hbfastmap.h"
  36. #include "llstring.h"
  37. // String template loaded from strings.xml
  38. class LLTransTemplate
  39. {
  40. public:
  41. LLTransTemplate(const std::string& name = LLStringUtil::null,
  42. const std::string& text = LLStringUtil::null)
  43. : mName(name),
  44. mText(text)
  45. {
  46. }
  47. std::string mName;
  48. std::string mText;
  49. };
  50. // Purely static class for localized strings with a general usage and which do
  51. // not belong to any specific floater or panel XUI definition. E.g. "Owner:",
  52. // "Retrieving...".
  53. // Note: LLUITrans has been merged with LLTrans since they performed the same
  54. // operations with just different string files loaded; LLTrans::getUIString()
  55. // should now be used instead of the now removed LLUITrans::getString(). HB
  56. class LLTrans
  57. {
  58. protected:
  59. LOG_CLASS(LLTrans);
  60. public:
  61. LLTrans() = delete;
  62. ~LLTrans() = delete;
  63. // Called only once, at early viewer initialization stage (from
  64. // LLAppViewer::initWindow()). HB
  65. static void init();
  66. // Returns the translated string for 'xml_desc' string name, 'args' is a
  67. // list of substrings to replace in the string.
  68. static std::string getString(const std::string& xml_desc,
  69. const LLStringUtil::format_map_t& args);
  70. static std::string getString(const std::string& xml_desc,
  71. const LLSD& args);
  72. static bool hasString(const std::string& xml_desc);
  73. // Returns a translated string for 'xml_desc' string name
  74. LL_INLINE static std::string getString(const std::string& xml_desc)
  75. {
  76. LLStringUtil::format_map_t empty;
  77. return getString(xml_desc, empty);
  78. }
  79. // Same as above, but returns a wide characters string.
  80. LL_INLINE static LLWString getWString(const std::string& xml_desc)
  81. {
  82. return utf8str_to_wstring(getString(xml_desc));
  83. }
  84. // Returns a translated string for a llui-specific 'xml_desc' string name.
  85. static const std::string& getUIString(const std::string& xml_desc);
  86. private:
  87. typedef fast_hmap<std::string, LLTransTemplate> map_t;
  88. // Parses the 'xml_filename' file that holds the strings. Stops with a
  89. // llerrs if something went wrong. Used only by init(). HB
  90. static void parseStrings(const std::string& xml_filename,
  91. map_t& templates);
  92. // Used to find a string in one of the two template maps. Returns true when
  93. // found, with the iterator pointing on the template, or false when not
  94. // found (iterator equal to end() for the corresponding templates map).
  95. // Searches the llui-specicfic strings when ui_string is true. HB
  96. static bool findString(const std::string& xml_desc,
  97. map_t::const_iterator& it, bool ui_string = false);
  98. private:
  99. static map_t sStringTemplates;
  100. static map_t sUIStringTemplates;
  101. };
  102. class LLAnimStateLabels
  103. {
  104. public:
  105. LL_INLINE static std::string getStateLabel(const char* anim_name)
  106. {
  107. return LLTrans::getString(std::string("anim_") +
  108. std::string(anim_name));
  109. }
  110. };
  111. #endif