I was looking for localization options and noticed that not only there is no localization functionality yet, there does not even seem to be any way to get to the basic localization data like decimal and thousands separator, date and time format, currency symbol and such.
So first I’d like to ask whether there is any plans for it.
I wrote a small test to call setlocale()
from standard C library and checked that it does not have effect on output of format!
. Which I consider to be good, because that way it can be used for writing machine-readable data while it is not really sufficient for user output where more parameters are needed.
If there is indeed no plan yet, I would like to try to come up with some prototype over next couple of days/weeks. I have managed internationalization and localization in both previous and this job and wrote some infrastructure (in C++) in both cases, so I would create a flexible formatting API based on the needs I encountered (like formatting dimensional quantities with minimum and maximum precision and switching between units and such).
I also already checked the available C interface and the standardized part of libc is really poor, because locale can only be set globally and must be set globally to be able to get to the information. In GNU libc there are functions to set it per-thread, so safe implementation is possible there. And Windows have native functions that take locale parameter, but they don’t use the standard locale identifiers like everybody else, so it will be somewhat difficult. Or I could collect the data from CLDR instead, which would mean largeish blob of data (directly or via ICU), but it could have data the standard C library does not and it would run on systems that don’t ship those data like Windows Embedded (formerly CE) or Android (Android has locale data in Java only). Perhaps as optional feature.
I suppose this can be easily prototyped as stand-alone library, so that’s how I’ll start.
Oh, and I should note that I have seen the suggestion to implement l20n-based translation system, but that does not touch locales and locale-aware value formatting, only translation. And to be honest I think it’s too advanced for it’s own good.