Final Platform Layer 1.0.0
Loading...
Searching...
No Matches
Query Locale information

Table of Contents

FPL provides a couple of functions for querying the currently configured locale.
A locale is written into a caller-provided string buffer in a format described by the fplLocaleFormat enumeration.

Currently the only supported format is fplLocaleFormat_ISO639, which produces ISO-639 strings like en-US or de-DE.

Querying a locale

FPL distinguishes three kinds of locale:

Function Returns the locale of
fplGetUserLocale() The current user account
fplGetSystemLocale() The operating system / system-wide setting
fplGetInputLocale() The active keyboard / input layout

All three functions share the same signature - pass the desired fplLocaleFormat, a destination buffer and its maximum length.
They return the number of characters written, excluding the null terminator.

char localeBuffer[16];
// Query the current user locale, e.g. "en-US"
if (fplGetUserLocale(fplLocaleFormat_ISO639, localeBuffer, fplArrayCount(localeBuffer)) > 0) {
fplConsoleFormatOut("User locale: %s\n", localeBuffer);
}
// Query the system locale
if (fplGetSystemLocale(fplLocaleFormat_ISO639, localeBuffer, fplArrayCount(localeBuffer)) > 0) {
fplConsoleFormatOut("System locale: %s\n", localeBuffer);
}
// Query the input/keyboard locale
if (fplGetInputLocale(fplLocaleFormat_ISO639, localeBuffer, fplArrayCount(localeBuffer)) > 0) {
fplConsoleFormatOut("Input locale: %s\n", localeBuffer);
}
fpl_common_api void fplConsoleFormatOut(const char *format,...)
Writes the given formatted text to the standard output console buffer.
fpl_platform_api size_t fplGetInputLocale(const fplLocaleFormat targetFormat, char *buffer, const size_t maxBufferLen)
Gets the input locale in the given target format.
fpl_platform_api size_t fplGetUserLocale(const fplLocaleFormat targetFormat, char *buffer, const size_t maxBufferLen)
Gets the user locale in the given target format.
fpl_platform_api size_t fplGetSystemLocale(const fplLocaleFormat targetFormat, char *buffer, const size_t maxBufferLen)
Gets the system locale in the given target format.
@ fplLocaleFormat_ISO639
ISO-639 format (de-DE, en-US, etc.).
#define fplArrayCount(arr)
Returns the element count from a static array.
Note
A return value of zero means the locale could not be determined or the buffer was too small.