mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
ICU: use uloc_getDefault() for initdb.
Simpler, and better preserves the locale name as read from the environment. Author: Daniel Verite Discussion: https://postgr.es/m/a6204a46-c077-451b-8f9d-8965d95bb57c@manitou-mail.org
This commit is contained in:
parent
7a844c77ec
commit
ec1264f01e
@ -2354,42 +2354,13 @@ icu_validate_locale(const char *loc_str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine default ICU locale by opening the default collator and reading
|
* Determine the default ICU locale
|
||||||
* its locale.
|
|
||||||
*
|
|
||||||
* NB: The default collator (opened using NULL) is different from the collator
|
|
||||||
* for the root locale (opened with "", "und", or "root"). The former depends
|
|
||||||
* on the environment (useful at initdb time) and the latter does not.
|
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
default_icu_locale(void)
|
default_icu_locale(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_ICU
|
#ifdef USE_ICU
|
||||||
UCollator *collator;
|
return pg_strdup(uloc_getDefault());
|
||||||
UErrorCode status;
|
|
||||||
const char *valid_locale;
|
|
||||||
char *default_locale;
|
|
||||||
|
|
||||||
status = U_ZERO_ERROR;
|
|
||||||
collator = ucol_open(NULL, &status);
|
|
||||||
if (U_FAILURE(status))
|
|
||||||
pg_fatal("could not open collator for default locale: %s",
|
|
||||||
u_errorName(status));
|
|
||||||
|
|
||||||
status = U_ZERO_ERROR;
|
|
||||||
valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
|
|
||||||
&status);
|
|
||||||
if (U_FAILURE(status))
|
|
||||||
{
|
|
||||||
ucol_close(collator);
|
|
||||||
pg_fatal("could not determine default ICU locale");
|
|
||||||
}
|
|
||||||
|
|
||||||
default_locale = pg_strdup(valid_locale);
|
|
||||||
|
|
||||||
ucol_close(collator);
|
|
||||||
|
|
||||||
return default_locale;
|
|
||||||
#else
|
#else
|
||||||
pg_fatal("ICU is not supported in this build");
|
pg_fatal("ICU is not supported in this build");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user