ILocalizationManager.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_CRYCOMMON_ILOCALIZATIONMANAGER_H
  9. #define CRYINCLUDE_CRYCOMMON_ILOCALIZATIONMANAGER_H
  10. #pragma once
  11. #include "LocalizationManagerBus.h"
  12. //#include <platform.h> // Needed for LARGE_INTEGER (for consoles).
  13. ////////////////////////////////////////////////////////////////////////////////////////////////
  14. // Forward declarations
  15. ////////////////////////////////////////////////////////////////////////////////////////////////
  16. class XmlNodeRef;
  17. //////////////////////////////////////////////////////////////////////////
  18. // Localized strings manager interface.
  19. //////////////////////////////////////////////////////////////////////////
  20. // Localization Info structure
  21. struct SLocalizedInfoGame
  22. {
  23. SLocalizedInfoGame ()
  24. : szCharacterName(nullptr)
  25. , bUseSubtitle(false)
  26. {
  27. }
  28. const char* szCharacterName;
  29. AZStd::string sUtf8TranslatedText;
  30. bool bUseSubtitle;
  31. };
  32. struct SLocalizedAdvancesSoundEntry
  33. {
  34. AZStd::string sName;
  35. float fValue;
  36. };
  37. // Localization Sound Info structure, containing sound related parameters.
  38. struct SLocalizedSoundInfoGame
  39. : public SLocalizedInfoGame
  40. {
  41. SLocalizedSoundInfoGame()
  42. : sSoundEvent(nullptr)
  43. , fVolume(0.f)
  44. , fRadioRatio (0.f)
  45. , bIsDirectRadio(false)
  46. , bIsIntercepted(false)
  47. , nNumSoundMoods(0)
  48. , pSoundMoods (nullptr)
  49. , nNumEventParameters(0)
  50. , pEventParameters(nullptr)
  51. {
  52. }
  53. const char* sSoundEvent;
  54. float fVolume;
  55. float fRadioRatio;
  56. bool bIsDirectRadio;
  57. bool bIsIntercepted;
  58. // SoundMoods.
  59. size_t nNumSoundMoods;
  60. SLocalizedAdvancesSoundEntry* pSoundMoods;
  61. // EventParameters.
  62. size_t nNumEventParameters;
  63. SLocalizedAdvancesSoundEntry* pEventParameters;
  64. };
  65. // Localization Sound Info structure, containing sound related parameters.
  66. struct SLocalizedInfoEditor
  67. : public SLocalizedInfoGame
  68. {
  69. SLocalizedInfoEditor()
  70. : sKey(nullptr)
  71. , sOriginalCharacterName(nullptr)
  72. , sOriginalActorLine(nullptr)
  73. , sUtf8TranslatedActorLine(nullptr)
  74. , nRow(0)
  75. {
  76. }
  77. const char* sKey;
  78. const char* sOriginalCharacterName;
  79. const char* sOriginalActorLine;
  80. const char* sUtf8TranslatedActorLine;
  81. unsigned int nRow;
  82. };
  83. // Summary:
  84. // Interface to the Localization Manager.
  85. struct ILocalizationManager
  86. : public LocalizationManagerRequestBus::Handler
  87. {
  88. //Platform independent language IDs. These are used to map the platform specific language codes to localization pakfiles
  89. //Please ensure that each entry in this enum has a corresponding entry in the PLATFORM_INDEPENDENT_LANGUAGE_NAMES array which is defined in LocalizedStringManager.cpp currently.
  90. enum EPlatformIndependentLanguageID
  91. {
  92. ePILID_English_US,
  93. ePILID_English_GB,
  94. ePILID_German_DE,
  95. ePILID_Russian_RU,
  96. ePILID_Polish_PL,
  97. ePILID_Turkish_TR,
  98. ePILID_Spanish_ES,
  99. ePILID_Spanish_MX,
  100. ePILID_French_FR,
  101. ePILID_French_CA,
  102. ePILID_Italian_IT,
  103. ePILID_Portugese_PT,
  104. ePILID_Portugese_BR,
  105. ePILID_Japanese_JP,
  106. ePILID_Korean_KR,
  107. ePILID_Chinese_T,
  108. ePILID_Chinese_S,
  109. ePILID_Dutch_NL,
  110. ePILID_Finnish_FI,
  111. ePILID_Swedish_SE,
  112. ePILID_Czech_CZ,
  113. ePILID_Norwegian_NO,
  114. ePILID_Arabic_SA,
  115. ePILID_Danish_DK,
  116. ePILID_MAX_OR_INVALID, //Not a language, denotes the maximum number of languages or an unknown language
  117. };
  118. using TLocalizationBitfield = uint32;
  119. // <interfuscator:shuffle>
  120. virtual ~ILocalizationManager()= default;
  121. virtual const char* LangNameFromPILID(const ILocalizationManager::EPlatformIndependentLanguageID id) = 0;
  122. virtual ILocalizationManager::EPlatformIndependentLanguageID PILIDFromLangName(AZStd::string langName) = 0;
  123. virtual ILocalizationManager::EPlatformIndependentLanguageID GetSystemLanguage() { return ILocalizationManager::EPlatformIndependentLanguageID::ePILID_English_US; }
  124. virtual ILocalizationManager::TLocalizationBitfield MaskSystemLanguagesFromSupportedLocalizations(const ILocalizationManager::TLocalizationBitfield systemLanguages) = 0;
  125. virtual ILocalizationManager::TLocalizationBitfield IsLanguageSupported(const ILocalizationManager::EPlatformIndependentLanguageID id) = 0;
  126. bool SetLanguage([[maybe_unused]] const char* sLanguage) override { return false; }
  127. const char* GetLanguage() override { return nullptr; }
  128. int GetLocalizationFormat() const override { return -1; }
  129. AZStd::string GetLocalizedSubtitleFilePath([[maybe_unused]] const AZStd::string& localVideoPath, [[maybe_unused]] const AZStd::string& subtitleFileExtension) const override { return ""; }
  130. AZStd::string GetLocalizedLocXMLFilePath([[maybe_unused]] const AZStd::string& localXmlPath) const override { return ""; }
  131. // load the descriptor file with tag information
  132. virtual bool InitLocalizationData(const char* sFileName, bool bReload = false) = 0;
  133. // request to load loca data by tag. Actual loading will happen during next level load begin event.
  134. virtual bool RequestLoadLocalizationDataByTag(const char* sTag) = 0;
  135. // direct load of loca data by tag
  136. virtual bool LoadLocalizationDataByTag(const char* sTag, bool bReload = false) = 0;
  137. virtual bool ReleaseLocalizationDataByTag(const char* sTag) = 0;
  138. virtual bool LoadAllLocalizationData(bool bReload = false) = 0;
  139. bool LoadExcelXmlSpreadsheet([[maybe_unused]] const char* sFileName, [[maybe_unused]] bool bReload = false) override { return false; }
  140. void ReloadData() override {};
  141. // Summary:
  142. // Free localization data.
  143. virtual void FreeData() = 0;
  144. // Summary:
  145. // Translate a string into the currently selected language.
  146. // Description:
  147. // Processes the input string and translates all labels contained into the currently selected language.
  148. // Parameters:
  149. // sString - String to be translated.
  150. // outLocalizedString - Translated version of the string.
  151. // bEnglish - if true, translates the string into the always present English language.
  152. // Returns:
  153. // true if localization was successful, false otherwise
  154. bool LocalizeString_ch([[maybe_unused]] const char* sString, [[maybe_unused]] AZStd::string& outLocalizedString, [[maybe_unused]] bool bEnglish = false) override { return false; }
  155. // Summary:
  156. // Same as LocalizeString( const char* sString, AZStd::string& outLocalizedString, bool bEnglish=false )
  157. // but at the moment this is faster.
  158. bool LocalizeString_s([[maybe_unused]] const AZStd::string& sString, [[maybe_unused]] AZStd::string& outLocalizedString, [[maybe_unused]] bool bEnglish = false) override { return false; }
  159. // Summary:
  160. void LocalizeAndSubstituteInternal([[maybe_unused]] AZStd::string& locString, [[maybe_unused]] const AZStd::vector<AZStd::string>& keys, [[maybe_unused]] const AZStd::vector<AZStd::string>& values) override {}
  161. // Return the localized version corresponding to a label.
  162. // Description:
  163. // A label has to start with '@' sign.
  164. // Parameters:
  165. // sLabel - Label to be translated, must start with '@' sign.
  166. // outLocalizedString - Localized version of the label.
  167. // bEnglish - if true, returns the always present English version of the label.
  168. // Returns:
  169. // True if localization was successful, false otherwise.
  170. bool LocalizeLabel([[maybe_unused]] const char* sLabel, [[maybe_unused]] AZStd::string& outLocalizedString, [[maybe_unused]] bool bEnglish = false) override { return false; }
  171. virtual bool IsLocalizedInfoFound([[maybe_unused]] const char* sKey) { return false; }
  172. // Summary:
  173. // Get localization info structure corresponding to a key (key=label without the '@' sign).
  174. // Parameters:
  175. // sKey - Key to be looked up. Key = Label without '@' sign.
  176. // outGameInfo - Reference to localization info structure to be filled in.
  177. // Returns:
  178. // True if info for key was found, false otherwise.
  179. virtual bool GetLocalizedInfoByKey(const char* sKey, SLocalizedInfoGame& outGameInfo) = 0;
  180. // Summary:
  181. // Get the sound localization info structure corresponding to a key.
  182. // Parameters:
  183. // sKey - Key to be looked up. Key = Label without '@' sign.
  184. // outSoundInfo - reference to sound info structure to be filled in
  185. // pSoundMoods requires nNumSoundMoods-times allocated memory
  186. // on return nNumSoundMoods will hold how many SoundsMood entries are needed
  187. // pEventParameters requires nNumEventParameters-times allocated memory
  188. // on return nNumEventParameters will hold how many EventParameter entries are needed
  189. // Passing 0 in the Num fields will make the query ignore checking for allocated memory
  190. // Returns:
  191. // True if successful, false otherwise (key not found, or not enough memory provided to write additional info).
  192. virtual bool GetLocalizedInfoByKey(const char* sKey, SLocalizedSoundInfoGame* pOutSoundInfo) = 0;
  193. // Summary:
  194. // Return number of localization entries.
  195. int GetLocalizedStringCount() override { return -1; }
  196. // Summary:
  197. // Get the localization info structure at index nIndex.
  198. // Parameters:
  199. // nIndex - Index.
  200. // outEditorInfo - Reference to localization info structure to be filled in.
  201. // Returns:
  202. // True if successful, false otherwise (out of bounds).
  203. virtual bool GetLocalizedInfoByIndex(int nIndex, SLocalizedInfoEditor& outEditorInfo) = 0;
  204. // Summary:
  205. // Get the localization info structure at index nIndex.
  206. // Parameters:
  207. // nIndex - Index.
  208. // outGameInfo - Reference to localization info structure to be filled in.
  209. // Returns:
  210. // True if successful, false otherwise (out of bounds).
  211. virtual bool GetLocalizedInfoByIndex(int nIndex, SLocalizedInfoGame& outGameInfo) = 0;
  212. // Summary:
  213. // Get the english localization info structure corresponding to a key.
  214. // Parameters:
  215. // sKey - Key to be looked up. Key = Label without '@' sign.
  216. // sLocalizedString - Corresponding english language string.
  217. // Returns:
  218. // True if successful, false otherwise (key not found).
  219. bool GetEnglishString([[maybe_unused]] const char* sKey, [[maybe_unused]] AZStd::string& sLocalizedString) override { return false; }
  220. // Summary:
  221. // Get Subtitle for Key or Label .
  222. // Parameters:
  223. // sKeyOrLabel - Key or Label to be used for subtitle lookup. Key = Label without '@' sign.
  224. // outSubtitle - Subtitle (untouched if Key/Label not found).
  225. // bForceSubtitle - If true, get subtitle (sLocalized or sEnglish) even if not specified in Data file.
  226. // Returns:
  227. // True if subtitle found (and outSubtitle filled in), false otherwise.
  228. bool GetSubtitle([[maybe_unused]] const char* sKeyOrLabel, [[maybe_unused]] AZStd::string& outSubtitle, [[maybe_unused]] bool bForceSubtitle = false) override { return false; }
  229. // Description:
  230. // These methods format outString depending on sString with ordered arguments
  231. // FormatStringMessage(outString, "This is %2 and this is %1", "second", "first");
  232. // Arguments:
  233. // outString - This is first and this is second.
  234. void FormatStringMessage_List([[maybe_unused]] AZStd::string& outString, [[maybe_unused]] const AZStd::string& sString, [[maybe_unused]] const char** sParams, [[maybe_unused]] int nParams) override {}
  235. void FormatStringMessage([[maybe_unused]] AZStd::string& outString, [[maybe_unused]] const AZStd::string& sString, [[maybe_unused]] const char* param1, [[maybe_unused]] const char* param2 = nullptr, [[maybe_unused]] const char* param3 = nullptr, [[maybe_unused]] const char* param4 = nullptr) override {}
  236. void LocalizeTime([[maybe_unused]] time_t t, [[maybe_unused]] bool bMakeLocalTime, [[maybe_unused]] bool bShowSeconds, [[maybe_unused]] AZStd::string& outTimeString) override {}
  237. void LocalizeDate([[maybe_unused]] time_t t, [[maybe_unused]] bool bMakeLocalTime, [[maybe_unused]] bool bShort, [[maybe_unused]] bool bIncludeWeekday, [[maybe_unused]] AZStd::string& outDateString) override {}
  238. void LocalizeDuration([[maybe_unused]] int seconds, [[maybe_unused]] AZStd::string& outDurationString) override {}
  239. void LocalizeNumber([[maybe_unused]] int number, [[maybe_unused]] AZStd::string& outNumberString) override {}
  240. void LocalizeNumber_Decimal([[maybe_unused]] float number, [[maybe_unused]] int decimals, [[maybe_unused]] AZStd::string& outNumberString) override {}
  241. // Summary:
  242. // Returns true if the project has localization configured for use, false otherwise.
  243. bool ProjectUsesLocalization() const override { return false; }
  244. // </interfuscator:shuffle>
  245. static ILINE TLocalizationBitfield LocalizationBitfieldFromPILID(EPlatformIndependentLanguageID pilid)
  246. {
  247. assert(pilid >= 0 && pilid < ePILID_MAX_OR_INVALID);
  248. return (1 << pilid);
  249. }
  250. };
  251. // Summary:
  252. // Simple bus that notifies listeners that the language (g_language) has changed.
  253. #endif // CRYINCLUDE_CRYCOMMON_ILOCALIZATIONMANAGER_H