SDL_locale.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  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. * This provides a way to get a list of preferred locales (language plus
  24. * country) for the user. There is exactly one function:
  25. * SDL_GetPreferredLocales(), which handles all the heavy lifting, and offers
  26. * documentation on all the strange ways humans might have configured their
  27. * language settings.
  28. */
  29. #ifndef SDL_locale_h
  30. #define SDL_locale_h
  31. #include <SDL3/SDL_stdinc.h>
  32. #include <SDL3/SDL_error.h>
  33. #include <SDL3/SDL_begin_code.h>
  34. /* Set up for C function definitions, even when using C++ */
  35. #ifdef __cplusplus
  36. /* *INDENT-OFF* */
  37. extern "C" {
  38. /* *INDENT-ON* */
  39. #endif
  40. /**
  41. * A struct to provide locale data.
  42. *
  43. * Locale data is split into a spoken language, like English, and an optional
  44. * country, like Canada. The language will be in ISO-639 format (so English
  45. * would be "en"), and the country, if not NULL, will be an ISO-3166 country
  46. * code (so Canada would be "CA").
  47. *
  48. * \since This function is available since SDL 3.2.0.
  49. *
  50. * \sa SDL_GetPreferredLocales
  51. */
  52. typedef struct SDL_Locale
  53. {
  54. const char *language; /**< A language name, like "en" for English. */
  55. const char *country; /**< A country, like "US" for America. Can be NULL. */
  56. } SDL_Locale;
  57. /**
  58. * Report the user's preferred locale.
  59. *
  60. * Returned language strings are in the format xx, where 'xx' is an ISO-639
  61. * language specifier (such as "en" for English, "de" for German, etc).
  62. * Country strings are in the format YY, where "YY" is an ISO-3166 country
  63. * code (such as "US" for the United States, "CA" for Canada, etc). Country
  64. * might be NULL if there's no specific guidance on them (so you might get {
  65. * "en", "US" } for American English, but { "en", NULL } means "English
  66. * language, generically"). Language strings are never NULL, except to
  67. * terminate the array.
  68. *
  69. * Please note that not all of these strings are 2 characters; some are three
  70. * or more.
  71. *
  72. * The returned list of locales are in the order of the user's preference. For
  73. * example, a German citizen that is fluent in US English and knows enough
  74. * Japanese to navigate around Tokyo might have a list like: { "de", "en_US",
  75. * "jp", NULL }. Someone from England might prefer British English (where
  76. * "color" is spelled "colour", etc), but will settle for anything like it: {
  77. * "en_GB", "en", NULL }.
  78. *
  79. * This function returns NULL on error, including when the platform does not
  80. * supply this information at all.
  81. *
  82. * This might be a "slow" call that has to query the operating system. It's
  83. * best to ask for this once and save the results. However, this list can
  84. * change, usually because the user has changed a system preference outside of
  85. * your program; SDL will send an SDL_EVENT_LOCALE_CHANGED event in this case,
  86. * if possible, and you can call this function again to get an updated copy of
  87. * preferred locales.
  88. *
  89. * \param count a pointer filled in with the number of locales returned, may
  90. * be NULL.
  91. * \returns a NULL terminated array of locale pointers, or NULL on failure;
  92. * call SDL_GetError() for more information. This is a single
  93. * allocation that should be freed with SDL_free() when it is no
  94. * longer needed.
  95. *
  96. * \since This function is available since SDL 3.2.0.
  97. */
  98. extern SDL_DECLSPEC SDL_Locale ** SDLCALL SDL_GetPreferredLocales(int *count);
  99. /* Ends C function definitions when using C++ */
  100. #ifdef __cplusplus
  101. /* *INDENT-OFF* */
  102. }
  103. /* *INDENT-ON* */
  104. #endif
  105. #include <SDL3/SDL_close_code.h>
  106. #endif /* SDL_locale_h */