CmStringTable.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include "CmModule.h"
  4. #include "boost/signals.hpp"
  5. namespace CamelotFramework
  6. {
  7. /**
  8. * @brief Loosely based on ISO 639-1 two letter language codes
  9. */
  10. enum class Language
  11. {
  12. Afar,
  13. Abkhazian,
  14. Avestan,
  15. Afrikaans,
  16. Akan,
  17. Amharic,
  18. Aragonese,
  19. Arabic,
  20. Assamese,
  21. Avaric,
  22. Aymara,
  23. Azerbaijani,
  24. Bashkir,
  25. Belarusian,
  26. Bulgarian,
  27. Bihari,
  28. Bislama,
  29. Bambara,
  30. Bengali,
  31. Tibetan,
  32. Breton,
  33. Bosnian,
  34. Catalan,
  35. Chechen,
  36. Chamorro,
  37. Corsican,
  38. Cree,
  39. Czech,
  40. ChurchSlavic,
  41. Chuvash,
  42. Welsh,
  43. Danish,
  44. German,
  45. Maldivian,
  46. Bhutani,
  47. Ewe,
  48. Greek,
  49. EnglishUK,
  50. EnglishUS,
  51. Esperanto,
  52. Spanish,
  53. Estonian,
  54. Basque,
  55. Persian,
  56. Fulah,
  57. Finnish,
  58. Fijian,
  59. Faroese,
  60. French,
  61. WesternFrisian,
  62. Irish,
  63. ScottishGaelic,
  64. Galician,
  65. Guarani,
  66. Gujarati,
  67. Manx,
  68. Hausa,
  69. Hebrew,
  70. Hindi,
  71. HiriMotu,
  72. Croatian,
  73. Haitian,
  74. Hungarian,
  75. Armenian,
  76. Herero,
  77. Interlingua,
  78. Indonesian,
  79. Interlingue,
  80. Igbo,
  81. SichuanYi,
  82. Inupiak,
  83. Ido,
  84. Icelandic,
  85. Italian,
  86. Inuktitut,
  87. Japanese,
  88. Javanese,
  89. Georgian,
  90. Kongo,
  91. Kikuyu,
  92. Kuanyama,
  93. Kazakh,
  94. Kalaallisut,
  95. Cambodian,
  96. Kannada,
  97. Korean,
  98. Kanuri,
  99. Kashmiri,
  100. Kurdish,
  101. Komi,
  102. Cornish,
  103. Kirghiz,
  104. Latin,
  105. Luxembourgish,
  106. Ganda,
  107. Limburgish,
  108. Lingala,
  109. Laotian,
  110. Lithuanian,
  111. LubaKatanga,
  112. Latvian,
  113. Malagasy,
  114. Marshallese,
  115. Maori,
  116. Macedonian,
  117. Malayalam,
  118. Mongolian,
  119. Moldavian,
  120. Marathi,
  121. Malay,
  122. Maltese,
  123. Burmese,
  124. Nauru,
  125. NorwegianBokmal,
  126. Ndebele,
  127. Nepali,
  128. Ndonga,
  129. Dutch,
  130. NorwegianNynorsk,
  131. Norwegian,
  132. Navaho,
  133. Nyanja,
  134. Provençal,
  135. Ojibwa,
  136. Oromo,
  137. Oriya,
  138. Ossetic,
  139. Punjabi,
  140. Pali,
  141. Polish,
  142. Pushto,
  143. Portuguese,
  144. Quechua,
  145. Romansh,
  146. Kirundi,
  147. Romanian,
  148. Russian,
  149. Kinyarwanda,
  150. Sanskrit,
  151. Sardinian,
  152. Sindhi,
  153. NorthernSami,
  154. Sangro,
  155. Sinhalese,
  156. Slovak,
  157. Slovenian,
  158. Samoan,
  159. Shona,
  160. Somali,
  161. Albanian,
  162. Serbian,
  163. Swati,
  164. Sesotho,
  165. Sundanese,
  166. Swedish,
  167. Swahili,
  168. Tamil,
  169. Telugu,
  170. Tajik,
  171. Thai,
  172. Tigrinya,
  173. Turkmen,
  174. Tagalog,
  175. Setswana,
  176. Tonga,
  177. Turkish,
  178. Tsonga,
  179. Tatar,
  180. Twi,
  181. Tahitian,
  182. Uighur,
  183. Ukrainian,
  184. Urdu,
  185. Uzbek,
  186. Venda,
  187. Vietnamese,
  188. Volapuk,
  189. Walloon,
  190. Wolof,
  191. Xhosa,
  192. Yiddish,
  193. Yoruba,
  194. Zhuang,
  195. Chinese,
  196. Zulu,
  197. Count // Number of entries
  198. };
  199. struct LocalizedStringData
  200. {
  201. struct Common
  202. {
  203. WString identifier;
  204. boost::signal<void()> onStringDataModified;
  205. };
  206. struct ParamOffset
  207. {
  208. ParamOffset()
  209. :paramIdx(0), location(0)
  210. { }
  211. ParamOffset(UINT32 _paramIdx, UINT32 _location)
  212. :paramIdx(_paramIdx), location(_location)
  213. { }
  214. UINT32 paramIdx;
  215. UINT32 location;
  216. };
  217. LocalizedStringData();
  218. ~LocalizedStringData();
  219. WString string;
  220. UINT32 numParameters;
  221. ParamOffset* parameterOffsets;
  222. Common* commonData;
  223. void concatenateString(WString& outputString, WString* parameters, UINT32 numParameterValues) const;
  224. void updateString(const WString& string);
  225. };
  226. class CM_UTILITY_EXPORT StringTable : public Module<StringTable>
  227. {
  228. // TODO - When editing string table I will need to ensure that all languages of the same string have the same number of parameters
  229. struct LanguageData
  230. {
  231. UnorderedMap<WString, LocalizedStringData*>::type strings;
  232. };
  233. public:
  234. StringTable();
  235. ~StringTable();
  236. Language getActiveLanguage() const { return mActiveLanguage; }
  237. void setActiveLanguage(Language language);
  238. void setString(const WString& identifier, Language language, const WString& string);
  239. void removeString(const WString& identifier);
  240. /**
  241. * @brief Gets a string data for the specified string identifier and currently active language.
  242. *
  243. * @param identifier Unique string identifier.
  244. * @param insertIfNonExisting If true, a new string data for the specified identifier and language will be
  245. * added to the table if data doesn't already exist. The data will use the identifier as
  246. * the translation string.
  247. *
  248. * @return The string data. Don't store reference to this data as it may get deleted.
  249. */
  250. LocalizedStringData& getStringData(const WString& identifier, bool insertIfNonExisting = true);
  251. /**
  252. * @brief Gets a string data for the specified string identifier and language.
  253. *
  254. * @param identifier Unique string identifier.
  255. * @param language Language.
  256. * @param insertIfNonExisting If true, a new string data for the specified identifier and language will be
  257. * added to the table if data doesn't already exist. The data will use the identifier as
  258. * the translation string.
  259. *
  260. * @return The string data. Don't store reference to this data as it may get deleted.
  261. */
  262. LocalizedStringData& getStringData(const WString& identifier, Language language, bool insertIfNonExisting = true);
  263. private:
  264. friend class HString;
  265. static const Language DEFAULT_LANGUAGE;
  266. Language mActiveLanguage;
  267. LanguageData* mActiveLanguageData;
  268. LanguageData* mDefaultLanguageData;
  269. LanguageData* mAllLanguages;
  270. UnorderedMap<WString, LocalizedStringData::Common*>::type mCommonData;
  271. void notifyAllStringsChanged();
  272. };
  273. }