SDL
3.0
SDL_locale.h
Go to the documentation of this file.
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
4
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
8
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
12
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
/**
23
* # CategoryLocale
24
*
25
* SDL locale services.
26
*
27
* This provides a way to get a list of preferred locales (language plus
28
* country) for the user. There is exactly one function:
29
* SDL_GetPreferredLocales(), which handles all the heavy lifting, and offers
30
* documentation on all the strange ways humans might have configured their
31
* language settings.
32
*/
33
34
#ifndef SDL_locale_h
35
#define SDL_locale_h
36
37
#include <
SDL3/SDL_stdinc.h
>
38
#include <
SDL3/SDL_error.h
>
39
40
#include <
SDL3/SDL_begin_code.h
>
41
/* Set up for C function definitions, even when using C++ */
42
#ifdef __cplusplus
43
/* *INDENT-OFF* */
44
extern
"C"
{
45
/* *INDENT-ON* */
46
#endif
47
48
/**
49
* A struct to provide locale data.
50
*
51
* Locale data is split into a spoken language, like English, and an optional
52
* country, like Canada.
53
*
54
* Language strings are ISO-639 language specifiers (such as "en" for English,
55
* "de" for German, etc). Country strings are ISO-3166 country codes (such as
56
* "US" for the United States, "CA" for Canada, etc). The country might be
57
* NULL if there's no specific guidance on them (so you might have `{ "en",
58
* "US" }` for American English, but `{ "en", NULL }` means "English language,
59
* generically"). Language strings are never NULL.
60
*
61
* Please note that not all of these strings are 2 characters; some are three
62
* or more.
63
*
64
* \since This struct is available since SDL 3.2.0.
65
*
66
* \sa SDL_GetPreferredLocales
67
*/
68
typedef
struct
SDL_Locale
69
{
70
const
char
*
language
;
/**< A language name, like "en" for English. */
71
const
char
*
country
;
/**< A country, like "US" for America. Can be NULL. */
72
}
SDL_Locale
;
73
74
/**
75
* Report the user's preferred locale.
76
*
77
* This returns a NULL-terminated array of pointers to locale information. The
78
* returned list of locales are in the order of the user's preference. For
79
* example, a German citizen that is fluent in US English and knows enough
80
* Japanese to navigate around Tokyo might have a list like:
81
*
82
* ```c
83
* {
84
* { "de", "DE" },
85
* { "en", "US" },
86
* { "jp", NULL },
87
* NULL
88
* }
89
* ```
90
*
91
* Someone from England might prefer British English (where "color" is spelled
92
* "colour", etc), but will settle for anything like it:
93
*
94
* ```c
95
* {
96
* { "en", "GB" },
97
* { "en", NULL },
98
* NULL
99
* }
100
* ```
101
*
102
* This function returns NULL on error, including when the platform does not
103
* supply this information at all.
104
*
105
* Note that this information is merely guidance; some platforms don't supply
106
* it, some only supply a single language ever, some don't ever provide
107
* country information, etc. Be prepared to receive surprising results and
108
* plan to have fallbacks.
109
*
110
* This might be a "slow" call that has to query the operating system. It's
111
* best to ask for this once and save the results. However, this list can
112
* change, usually because the user has changed a system preference outside of
113
* your program; SDL will send an SDL_EVENT_LOCALE_CHANGED event in this case,
114
* if possible, and you can call this function again to get an updated copy of
115
* preferred locales.
116
*
117
* The returned pointer is a single allocation (all the strings and structures
118
* are allocated in a single chunk, even though they look like separate data),
119
* and should be disposed of with a single call to SDL_free() when it is no
120
* longer needed.
121
*
122
* If not NULL, `*count` will be set to number of items returned, not counting
123
* the terminating NULL pointer. `count` may be NULL if one plans to simply
124
* iterate the returned array directly.
125
*
126
* \param count a pointer filled in with the number of locales returned, may
127
* be NULL.
128
* \returns a NULL-terminated array of locale pointers, or NULL on failure;
129
* call SDL_GetError() for more information. Call SDL_free() when
130
* done with this pointer.
131
*
132
* \threadsafety This function is not thread safe.
133
*
134
* \since This function is available since SDL 3.2.0.
135
*/
136
extern
SDL_DECLSPEC
SDL_Locale
** SDLCALL
SDL_GetPreferredLocales
(
int
*count);
137
138
/* Ends C function definitions when using C++ */
139
#ifdef __cplusplus
140
/* *INDENT-OFF* */
141
}
142
/* *INDENT-ON* */
143
#endif
144
#include <
SDL3/SDL_close_code.h
>
145
146
#endif
/* SDL_locale_h */
SDL_begin_code.h
SDL_close_code.h
SDL_error.h
SDL_GetPreferredLocales
SDL_Locale ** SDL_GetPreferredLocales(int *count)
SDL_stdinc.h
SDL_Locale
Definition
SDL_locale.h:69
SDL_Locale::country
const char * country
Definition
SDL_locale.h:71
SDL_Locale::language
const char * language
Definition
SDL_locale.h:70
include
SDL3
SDL_locale.h
Generated by
1.17.0