It seems like setlocale()
in C (at least on Linux) only works if the locale you’re trying to set it to is one of those listed in the output of locale -a
. Is this really true?
The reason I ask to confirm is that it seems like a potentially unpleasant restriction.
- For example, my fairly standard Ubuntu installation only outputs English and C/Posix locales for
locale -a
. Yet in Java, by contrast, the list of available locales does not seem constrained by what’s installed in the OS (many languages’ and countries’ locales are available).
It seems like setlocale()
in C (at least on Linux) only works if the locale you’re trying to set it to is one of those listed in the output of locale -a
. Is this really true?
The reason I ask to confirm is that it seems like a potentially unpleasant restriction.
- For example, my fairly standard Ubuntu installation only outputs English and C/Posix locales for
locale -a
. Yet in Java, by contrast, the list of available locales does not seem constrained by what’s installed in the OS (many languages’ and countries’ locales are available).
1 Answer
Reset to default 1This is because locale -a
merely lists the locales installed on the system. On Debian/Ubuntu based systems for example it looks for them under /usr/lib/locale
. If a locale does not exist on the system, then you won't be able to use it, neither via setlocale()
nor via any other means.
locale-all
to install all locales. So it is up the administrator to choose the locales to install. it is not a limitation of C, but an old problem about disk usage – Giacomo Catenazzi Commented 22 hours ago