Fall back to parsing environment variables if setlocale reports C
ICU4X currently has code for obtaining system locale settings by calling POSIX setlocale with the null pointer as the second argument.
However, this always says C unless the application has first initialized the libc localization subsystem by calling setlocale(LC_ALL, ""). It is not OK for ICU4X to perform that call, because that call is permitted only when the process has a single thread, so performing that call must be the responsibility of the application before spawning additional threads.
ICU4C solves this by parsing the environment variables that setlocale(LC_ALL, "") causes libc to parse on its own if setlocale with the second argument set to the null pointer returns C.
I suggest that ICU4X does the same:
- If
setlocalefor the category of interest with the null pointer as the second argument return the null pointer,C, orPOSIX, parse the environment variable for the category andLC_ALLgiving them the right precedence. - If those don't exist or says
CorPOSIX(possibly with some suffix likeC.UTF-8), reporten-US-posix.
CC @Finchiedev @robertbastian