From 008dd4195b5a9f5bdbb83fccf5ada973b0ffb17c Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 5 Oct 2026 13:28:01 -0400
Subject: [PATCH] docs: Corrections and improvements to Locale documentation.
---
docs/README-migration.md | 4 +++
include/SDL3/SDL_locale.h | 73 +++++++++++++++++++++++++++------------
2 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index e0a6bfc1d0e64..74b3bc488f4d5 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1117,6 +1117,10 @@ Shared object handles are now `SDL_SharedObject *`, an opaque type, instead of `
SDL_LoadFunction() now returns `SDL_FunctionPointer` instead of `void *`, and should be cast to the appropriate function type. You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior.
+## SDL_locale.h
+
+SDL_GetPreferredLocales() now returns a NULL-terminated array of pointers, instead of an array of structs where the last struct has its fields set to NULL, and also can optionally report the count of the array. The returned pointer is still disposed of by the caller with a single SDL_free() call, that will take care of all the strings and structs in one block.
+
## SDL_log.h
SDL_Log() no longer prints a log prefix by default for SDL_LOG_PRIORITY_INFO and below. The log prefixes can be customized with SDL_SetLogPriorityPrefix().
diff --git a/include/SDL3/SDL_locale.h b/include/SDL3/SDL_locale.h
index 0bceec8f8b786..cee6bbb892a3a 100644
--- a/include/SDL3/SDL_locale.h
+++ b/include/SDL3/SDL_locale.h
@@ -49,9 +49,17 @@ extern "C" {
* A struct to provide locale data.
*
* Locale data is split into a spoken language, like English, and an optional
- * country, like Canada. The language will be in ISO-639 format (so English
- * would be "en"), and the country, if not NULL, will be an ISO-3166 country
- * code (so Canada would be "CA").
+ * country, like Canada.
+ *
+ * Language strings are ISO-639 language specifiers (such as "en" for
+ * English, "de" for German, etc). Country strings are ISO-3166 country codes
+ * (such as "US" for the United States, "CA" for Canada, etc). The country might
+ * be NULL if there's no specific guidance on them (so you might have
+ * `{ "en", "US" }` for American English, but `{ "en", NULL }` means "English
+ * language, generically"). Language strings are never NULL.
+ *
+ * Please note that not all of these strings are 2 characters; some are three
+ * or more.
*
* \since This struct is available since SDL 3.2.0.
*
@@ -66,28 +74,39 @@ typedef struct SDL_Locale
/**
* Report the user's preferred locale.
*
- * Returned language strings are in the format xx, where 'xx' is an ISO-639
- * language specifier (such as "en" for English, "de" for German, etc).
- * Country strings are in the format YY, where "YY" is an ISO-3166 country
- * code (such as "US" for the United States, "CA" for Canada, etc). Country
- * might be NULL if there's no specific guidance on them (so you might get {
- * "en", "US" } for American English, but { "en", NULL } means "English
- * language, generically"). Language strings are never NULL, except to
- * terminate the array.
+ * This returns a NULL-terminated array of pointers to locale information. The
+ * returned list of locales are in the order of the user's preference. For
+ * example, a German citizen that is fluent in US English and knows enough
+ * Japanese to navigate around Tokyo might have a list like:
*
- * Please note that not all of these strings are 2 characters; some are three
- * or more.
+ * ```c
+ * {
+ * { "de", "DE" },
+ * { "en", "US" },
+ * { "jp", NULL },
+ * NULL
+ * }
+ * ```
*
- * The returned list of locales are in the order of the user's preference. For
- * example, a German citizen that is fluent in US English and knows enough
- * Japanese to navigate around Tokyo might have a list like: { "de", "en_US",
- * "jp", NULL }. Someone from England might prefer British English (where
- * "color" is spelled "colour", etc), but will settle for anything like it: {
- * "en_GB", "en", NULL }.
+ * Someone from England might prefer British English (where "color" is spelled
+ * "colour", etc), but will settle for anything like it:
+ *
+ * ```c
+ * {
+ * { "en", "GB" },
+ * { "en", NULL },
+ * NULL
+ * }
+ * ```
*
* This function returns NULL on error, including when the platform does not
* supply this information at all.
*
+ * Note that this information is merely guidance; some platforms don't supply
+ * it, some only supply a single language ever, some don't ever provide country
+ * information, etc. Be prepared to receive surprising results and plan to have
+ * fallbacks.
+ *
* This might be a "slow" call that has to query the operating system. It's
* best to ask for this once and save the results. However, this list can
* change, usually because the user has changed a system preference outside of
@@ -95,12 +114,20 @@ typedef struct SDL_Locale
* if possible, and you can call this function again to get an updated copy of
* preferred locales.
*
+ * The returned pointer is a single allocation (all the strings and structures
+ * are allocated in a single chunk, even though they look like separate data),
+ * and should be disposed of with a single call to SDL_free() when it is no
+ * longer needed.
+ *
+ * If not NULL, `*count` will be set to number of items returned, not counting
+ * the terminating NULL pointer. `count` may be NULL if one plans to simply
+ * iterate the returned array directly.
+ *
* \param count a pointer filled in with the number of locales returned, may
* be NULL.
- * \returns a NULL terminated array of locale pointers, or NULL on failure;
- * call SDL_GetError() for more information. This is a single
- * allocation that should be freed with SDL_free() when it is no
- * longer needed.
+ * \returns a NULL-terminated array of locale pointers, or NULL on failure;
+ * call SDL_GetError() for more information. Call SDL_free() when
+ * done with this pointer.
*
* \threadsafety This function is not thread safe.
*