Team Fortress 2 Source Code as on 22/4/2020
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.

102 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: provide a layer of abstraction between GC and vgui localization systems
  4. //
  5. //=============================================================================
  6. #ifndef LOCALIZATION_PROVIDER_H
  7. #define LOCALIZATION_PROVIDER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "language.h"
  12. #include "ilocalize.h"
  13. // interface matches a subset of VGUI functions
  14. class CLocalizationProvider
  15. {
  16. public:
  17. virtual locchar_t *Find( const char *pchKey ) const = 0;
  18. locchar_t* FindSafe( const char* pchKey ) const;
  19. // new interface
  20. virtual void ConvertLoccharToANSI ( const locchar_t *loc_In, CUtlConstString *out_ansi ) const = 0;
  21. virtual void ConvertLoccharToUnicode( const locchar_t *loc_In, CUtlConstWideString *out_unicode ) const = 0;
  22. virtual void ConvertUTF8ToLocchar ( const char *utf8_In, CUtlConstStringBase<locchar_t> *out_loc ) const = 0;
  23. // old C-style interface
  24. virtual int ConvertLoccharToANSI( const locchar_t *loc, OUT_Z_BYTECAP(ansiBufferSize) char *ansi, int ansiBufferSize ) const = 0;
  25. virtual int ConvertLoccharToUnicode( const locchar_t *loc, OUT_Z_BYTECAP(unicodeBufferSize) wchar_t *unicode, int unicodeBufferSize ) const = 0;
  26. virtual void ConvertUTF8ToLocchar( const char *utf8, OUT_Z_BYTECAP(loccharBufferSize) locchar_t *locchar, int loccharBufferSize ) const = 0;
  27. virtual ELanguage GetELang() const = 0;
  28. };
  29. CLocalizationProvider *GLocalizationProvider();
  30. #ifdef GC
  31. // GC localization is handled by the GC itself
  32. class CGCLocalizationProvider : public CLocalizationProvider
  33. {
  34. public:
  35. CGCLocalizationProvider( CGCGameBase *pGC, ELanguage eLang = k_Lang_English )
  36. {
  37. m_pGC = pGC;
  38. m_eLang = eLang;
  39. }
  40. static bool BEnsureCleanUTF8Truncation( char *unicodeOutput );
  41. virtual locchar_t *Find( const char *pchKey ) const;
  42. // new interface
  43. virtual void ConvertLoccharToANSI ( const locchar_t *loc_In, CUtlConstString *out_ansi ) const;
  44. virtual void ConvertLoccharToUnicode( const locchar_t *loc_In, CUtlConstWideString *out_unicode ) const;
  45. virtual void ConvertUTF8ToLocchar ( const char *utf8_In, CUtlConstStringBase<locchar_t> *out_loc ) const;
  46. // old C-style interface
  47. virtual int ConvertLoccharToANSI( const locchar_t *loc, char *ansi, int ansiBufferSize ) const;
  48. virtual int ConvertLoccharToUnicode( const locchar_t *loc, wchar_t *unicode, int unicodeBufferSize ) const;
  49. virtual void ConvertUTF8ToLocchar( const char *utf8, locchar_t *locchar, int loccharBufferSize ) const;
  50. virtual ELanguage GetELang() const { return m_eLang; }
  51. private:
  52. CGCGameBase *m_pGC;
  53. ELanguage m_eLang;
  54. };
  55. #else
  56. #include "vgui/ILocalize.h"
  57. extern vgui::ILocalize *g_pVGuiLocalize;
  58. // Game localization is handled by vgui
  59. class CVGUILocalizationProvider : public CLocalizationProvider
  60. {
  61. public:
  62. CVGUILocalizationProvider();
  63. virtual locchar_t *Find( const char *pchKey ) const;
  64. // new interface
  65. virtual void ConvertLoccharToANSI ( const locchar_t *loc_In, CUtlConstString *out_ansi ) const;
  66. virtual void ConvertLoccharToUnicode( const locchar_t *loc_In, CUtlConstWideString *out_unicode ) const;
  67. virtual void ConvertUTF8ToLocchar ( const char *utf8_In, CUtlConstStringBase<locchar_t> *out_loc ) const;
  68. // old C-style interface
  69. virtual int ConvertLoccharToANSI( const locchar_t *loc, char *ansi, int ansiBufferSize ) const;
  70. virtual int ConvertLoccharToUnicode( const locchar_t *loc, wchar_t *unicode, int unicodeBufferSize ) const;
  71. virtual void ConvertUTF8ToLocchar( const char *utf8, locchar_t *locchar, int loccharBufferSize ) const;
  72. virtual ELanguage GetELang() const { return k_Lang_None; }
  73. };
  74. #endif
  75. #endif // LOCALIZATION_PROVIDER_H