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.

73 lines
2.4 KiB

  1. #include "cbase.h"
  2. #include "localization_provider.h"
  3. enum { kScratchBufferSize = 1024 };
  4. CLocalizationProvider *GLocalizationProvider()
  5. {
  6. static CVGUILocalizationProvider g_VGUILocalizationProvider;
  7. return &g_VGUILocalizationProvider;
  8. }
  9. // vgui localization implementation
  10. CVGUILocalizationProvider::CVGUILocalizationProvider()
  11. {
  12. }
  13. locchar_t *CVGUILocalizationProvider::Find( const char *pchKey )
  14. {
  15. return (locchar_t*)g_pVGuiLocalize->Find( pchKey );
  16. }
  17. void CVGUILocalizationProvider::ConstructString( locchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const locchar_t *formatString, int numFormatParameters, ... )
  18. {
  19. va_list argList;
  20. va_start(argList, numFormatParameters);
  21. g_pVGuiLocalize->ConstructStringVArgs( unicodeOutput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList);
  22. va_end(argList);
  23. }
  24. void CVGUILocalizationProvider::ConstructString( OUT_Z_BYTECAP(unicodeBufferSizeInBytes) locchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const locchar_t *formatString, KeyValues *localizationVariables )
  25. {
  26. g_pVGuiLocalize->ConstructString( unicodeOutput, unicodeBufferSizeInBytes, formatString, localizationVariables );
  27. }
  28. void CVGUILocalizationProvider::ConvertLoccharToANSI( const locchar_t *loc_In, CUtlConstString *out_ansi ) const
  29. {
  30. char ansi_Scratch[kScratchBufferSize];
  31. g_pVGuiLocalize->ConvertUnicodeToANSI( loc_In, ansi_Scratch, kScratchBufferSize );
  32. *out_ansi = ansi_Scratch;
  33. }
  34. void CVGUILocalizationProvider::ConvertLoccharToUnicode( const locchar_t *loc_In, CUtlConstWideString *out_unicode ) const
  35. {
  36. *out_unicode = loc_In;
  37. }
  38. void CVGUILocalizationProvider::ConvertUTF8ToLocchar( const char *utf8_In, CUtlConstStringBase<locchar_t> *out_loc ) const
  39. {
  40. locchar_t loc_Scratch[kScratchBufferSize];
  41. V_UTF8ToUnicode( utf8_In, loc_Scratch, sizeof( loc_Scratch ) );
  42. *out_loc = loc_Scratch;
  43. }
  44. void CVGUILocalizationProvider::ConvertUTF8ToLocchar( const char *utf8, locchar_t *locchar, int cubDestSizeInBytes )
  45. {
  46. V_UTF8ToUnicode( utf8, locchar, cubDestSizeInBytes );
  47. }
  48. int CVGUILocalizationProvider::ConvertLoccharToANSI( const locchar_t *loc, char *ansi, int ansiBufferSize )
  49. {
  50. return g_pVGuiLocalize->ConvertUnicodeToANSI( loc, ansi, ansiBufferSize );
  51. }
  52. int CVGUILocalizationProvider::ConvertLoccharToUnicode( const locchar_t *loc, wchar_t *unicode, int unicodeBufferSizeInBytes )
  53. {
  54. Q_wcsncpy( unicode, loc, unicodeBufferSizeInBytes );
  55. return 0;
  56. }