SDL_locale.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryLocale
  20. *
  21. * SDL locale services.
  22. */
  23. #ifndef SDL_locale_h
  24. #define SDL_locale_h
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_begin_code.h>
  28. /* Set up for C function definitions, even when using C++ */
  29. #ifdef __cplusplus
  30. /* *INDENT-OFF* */
  31. extern "C" {
  32. /* *INDENT-ON* */
  33. #endif
  34. /**
  35. * A struct to provide locale data.
  36. *
  37. * Locale data is split into a spoken language, like English, and an optional
  38. * country, like Canada. The language will be in ISO-639 format (so English
  39. * would be "en"), and the country, if not NULL, will be an ISO-3166 country
  40. * code (so Canada would be "CA").
  41. *
  42. * \since This function is available since SDL 3.0.0.
  43. *
  44. * \sa SDL_GetPreferredLocales
  45. */
  46. typedef struct SDL_Locale
  47. {
  48. const char *language; /**< A language name, like "en" for English. */
  49. const char *country; /**< A country, like "US" for America. Can be NULL. */
  50. } SDL_Locale;
  51. /**
  52. * Report the user's preferred locale.
  53. *
  54. * This returns an array of SDL_Locale structs, the final item zeroed out.
  55. * When the caller is done with this array, it should call SDL_free() on the
  56. * returned value; all the memory involved is allocated in a single block, so
  57. * a single SDL_free() will suffice.
  58. *
  59. * Returned language strings are in the format xx, where 'xx' is an ISO-639
  60. * language specifier (such as "en" for English, "de" for German, etc).
  61. * Country strings are in the format YY, where "YY" is an ISO-3166 country
  62. * code (such as "US" for the United States, "CA" for Canada, etc). Country
  63. * might be NULL if there's no specific guidance on them (so you might get {
  64. * "en", "US" } for American English, but { "en", NULL } means "English
  65. * language, generically"). Language strings are never NULL, except to
  66. * terminate the array.
  67. *
  68. * Please note that not all of these strings are 2 characters; some are three
  69. * or more.
  70. *
  71. * The returned list of locales are in the order of the user's preference. For
  72. * example, a German citizen that is fluent in US English and knows enough
  73. * Japanese to navigate around Tokyo might have a list like: { "de", "en_US",
  74. * "jp", NULL }. Someone from England might prefer British English (where
  75. * "color" is spelled "colour", etc), but will settle for anything like it: {
  76. * "en_GB", "en", NULL }.
  77. *
  78. * This function returns NULL on error, including when the platform does not
  79. * supply this information at all.
  80. *
  81. * This might be a "slow" call that has to query the operating system. It's
  82. * best to ask for this once and save the results. However, this list can
  83. * change, usually because the user has changed a system preference outside of
  84. * your program; SDL will send an SDL_EVENT_LOCALE_CHANGED event in this case,
  85. * if possible, and you can call this function again to get an updated copy of
  86. * preferred locales.
  87. *
  88. * This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
  89. *
  90. * \param count a pointer filled in with the number of locales returned, may
  91. * be NULL.
  92. * \returns a NULL terminated array of locale pointers, or NULL on failure; call SDL_GetError() for more
  93. * information.
  94. *
  95. * \since This function is available since SDL 3.0.0.
  96. */
  97. extern SDL_DECLSPEC const SDL_Locale * const * SDLCALL SDL_GetPreferredLocales(int *count);
  98. /* Ends C function definitions when using C++ */
  99. #ifdef __cplusplus
  100. /* *INDENT-OFF* */
  101. }
  102. /* *INDENT-ON* */
  103. #endif
  104. #include <SDL3/SDL_close_code.h>
  105. #endif /* SDL_locale_h */