Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
7.1 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef ILOCALIZE_H
  8. #define ILOCALIZE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "appframework/iappsystem.h"
  13. #include <tier1/keyvalues.h>
  14. // unicode character type
  15. // for more unicode manipulation functions #include <wchar.h>
  16. #if !defined( _WCHAR_T_DEFINED ) && !defined( _PS3 ) && !defined(__clang__)
  17. typedef unsigned short wchar_t;
  18. #define _WCHAR_T_DEFINED
  19. #endif
  20. //-----------------------------------------------------------------------------
  21. // Interface used to query text size so we can choose the longest one
  22. //-----------------------------------------------------------------------------
  23. abstract_class ILocalizeTextQuery
  24. {
  25. public:
  26. virtual int ComputeTextWidth( const wchar_t *pString ) = 0;
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Callback which is triggered when any localization string changes
  30. // Is not called when a localization string is added
  31. //-----------------------------------------------------------------------------
  32. abstract_class ILocalizationChangeCallback
  33. {
  34. public:
  35. virtual void OnLocalizationChanged() = 0;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Handles localization of text
  39. // looks up string names and returns the localized unicode text
  40. //-----------------------------------------------------------------------------
  41. // direct references to localized strings
  42. typedef uint32 LocalizeStringIndex_t;
  43. const uint32 LOCALIZE_INVALID_STRING_INDEX = (LocalizeStringIndex_t)-1;
  44. abstract_class ILocalize : public IAppSystem
  45. {
  46. public:
  47. // adds the contents of a file to the localization table
  48. virtual bool AddFile( const char *fileName, const char *pPathID = NULL, bool bIncludeFallbackSearchPaths = false ) = 0;
  49. // Remove all strings from the table
  50. virtual void RemoveAll() = 0;
  51. // Finds the localized text for tokenName. Returns NULL if none is found.
  52. virtual wchar_t *Find(const char *tokenName) = 0;
  53. // Like Find(), but as a failsafe, returns an error message instead of NULL if the string isn't found.
  54. virtual const wchar_t *FindSafe(const char *tokenName) = 0;
  55. // converts an english string to unicode
  56. // returns the number of wchar_t in resulting string, including null terminator
  57. virtual int ConvertANSIToUnicode(const char *ansi, OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicode, int unicodeBufferSizeInBytes) = 0;
  58. // converts an unicode string to an english string
  59. // unrepresentable characters are converted to system default
  60. // returns the number of characters in resulting string, including null terminator
  61. virtual int ConvertUnicodeToANSI(const wchar_t *unicode, OUT_Z_CAP(ansiBufferSize) char *ansi, int ansiBufferSize) = 0;
  62. // finds the index of a token by token name, INVALID_STRING_INDEX if not found
  63. virtual LocalizeStringIndex_t FindIndex(const char *tokenName) = 0;
  64. // gets the values by the string index
  65. virtual const char *GetNameByIndex(LocalizeStringIndex_t index) = 0;
  66. virtual wchar_t *GetValueByIndex(LocalizeStringIndex_t index) = 0;
  67. ///////////////////////////////////////////////////////////////////
  68. // the following functions should only be used by localization editors
  69. // iteration functions
  70. virtual LocalizeStringIndex_t GetFirstStringIndex() = 0;
  71. // returns the next index, or INVALID_STRING_INDEX if no more strings available
  72. virtual LocalizeStringIndex_t GetNextStringIndex(LocalizeStringIndex_t index) = 0;
  73. // adds a single name/unicode string pair to the table
  74. virtual void AddString( const char *tokenName, wchar_t *unicodeString, const char *fileName ) = 0;
  75. // changes the value of a string
  76. virtual void SetValueByIndex(LocalizeStringIndex_t index, wchar_t *newValue) = 0;
  77. // saves the entire contents of the token tree to the file
  78. virtual bool SaveToFile( const char *fileName ) = 0;
  79. // iterates the filenames
  80. virtual int GetLocalizationFileCount() = 0;
  81. virtual const char *GetLocalizationFileName(int index) = 0;
  82. // returns the name of the file the specified localized string is stored in
  83. virtual const char *GetFileNameByIndex(LocalizeStringIndex_t index) = 0;
  84. // for development only, reloads localization files
  85. virtual void ReloadLocalizationFiles( ) = 0;
  86. // need to replace the existing ConstructString with this
  87. virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const char *tokenName, KeyValues *localizationVariables) = 0;
  88. virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, LocalizeStringIndex_t unlocalizedTextSymbol, KeyValues *localizationVariables) = 0;
  89. // Used to install a callback to query which localized strings are the longest
  90. virtual void SetTextQuery( ILocalizeTextQuery *pQuery ) = 0;
  91. // Is called when any localization strings change
  92. virtual void InstallChangeCallback( ILocalizationChangeCallback *pCallback ) = 0;
  93. virtual void RemoveChangeCallback( ILocalizationChangeCallback *pCallback ) = 0;
  94. virtual wchar_t* GetAsianFrequencySequence( const char * pLanguage ) = 0;
  95. virtual const char *FindAsUTF8( const char *pchTokenName ) = 0;
  96. // builds a localized formatted string
  97. // uses the format strings first: %s1, %s2, ... unicode strings (wchar_t *)
  98. template < typename T >
  99. void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOuput, int unicodeBufferSizeInBytes, const T *formatString, int numFormatParameters, ...)
  100. {
  101. va_list argList;
  102. va_start( argList, numFormatParameters );
  103. ConstructStringVArgsInternal( unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList );
  104. va_end( argList );
  105. }
  106. template < typename T >
  107. void ConstructStringVArgs(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOuput, int unicodeBufferSizeInBytes, const T *formatString, int numFormatParameters, va_list argList)
  108. {
  109. ConstructStringVArgsInternal( unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList );
  110. }
  111. template < typename T >
  112. void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOutput, int unicodeBufferSizeInBytes, const T *formatString, KeyValues *localizationVariables)
  113. {
  114. ConstructStringKeyValuesInternal( unicodeOutput, unicodeBufferSizeInBytes, formatString, localizationVariables );
  115. }
  116. protected:
  117. // internal "interface"
  118. virtual void ConstructStringVArgsInternal(char *unicodeOutput, int unicodeBufferSizeInBytes, const char *formatString, int numFormatParameters, va_list argList) = 0;
  119. virtual void ConstructStringVArgsInternal(wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t *formatString, int numFormatParameters, va_list argList) = 0;
  120. virtual void ConstructStringKeyValuesInternal(char *unicodeOutput, int unicodeBufferSizeInBytes, const char *formatString, KeyValues *localizationVariables) = 0;
  121. virtual void ConstructStringKeyValuesInternal(wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t *formatString, KeyValues *localizationVariables) = 0;
  122. };
  123. #endif // ILOCALIZE_H