lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Actually on Linux, the LANG environment variable (or any other variables) are not necessarily set. In that case the effective locale depends on the default localization of system libraries used and installed on the system. If your system is installed with a native default locale in German, this will be the default locale in these libraries. There are various ways to configure these default system libraries (including alternatives) and the default library path they use. In absence of LANG (or whatever) there's no standard locale, and it could be anyone; most distributions of Linux however are installed using the "C" locale (which is a locale in basic English, with reduced transforms), some other distribute use the "POSIX" locale (with some differences, notably for date/time formats and timezones).
Not all Linux distributions aer installing the english locale files (and this is likely being the case with your German openSUSE distrib, if you've used a "minimal" installation in German). This is quite strange but all Linux installers should install a minimal locale for basic English (not necessarily all its variants for US, GB, CA, AU, NZ...) to offer maximum interoperability with "C" and "POSIX" locales, and correct interoperability with the "root" locale in CLDR, and with internet protocols (e.g. MIME, HTTP).

That basic locale may not contain all translations (e.g. month names or week day names, or advanced support for collation, and at least basic support of 7-bit US-ASCII, other bytes being sorted in binary order). But today modern distribs should all support locales using the UCS (in UTF-8) because it is required by default in many internet protocols and UTF-8 has completely surpassed ASCII and all other encodings. To support it, Unicode-compatible libraries are installed as well (such as ICU) and they will require the support of the CLDR "root" locale, from which "C" and "POSIX" locales should be based on, as well as the basic English locale and all English derivatives and locales for all other languages and scripts.

But note that Lua itself is a bit agnostic of the OS installation: it just uses standard C libraries, which themselves are using the "C" locale by default (independantly of environment variables, that may or may not be used, but depending on how you compiled Lua with the C compiler and how your configured its build file to link C libraries: so be careful about how you configure Lua makefiles, notably if you use static linking for C libraries: some of them are completely ignoring the runtime environment for their statically linked "C" locale data; this is not a defect but may be useful for security reasons or to increase stability, avoiding defects that may happen during system upgrades if an application is not prepared at all to support an unexpected change of localization data; but those same apps will need at least the additional support for the POSIX English locale if ever they use any Internet protocol, and many shell scripts and admin tools won't run correctly if there's no system support for the US English locale or at minimum the basic English locale at least for numeric formats and date/time formats in plain ASCII).

So my opinion if that your openSUSE system is broken, incorrectly installed. I don't think that a standard openSUSE installation removed such masic support, and it was done by incorrect manipulations made by the administrator (and I even wonder how such system can really boot correctly with producing lot of warnings or errors in system logs and without having sveral services crashing or not starting at all).

Le lun. 23 janv. 2023 à 12:05, Marc Balmer <marc@msys.ch> a écrit :


> Am 23.01.2023 um 11:22 schrieb Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>
>> When I output a number value, e.g. 42.0, it is normally output with a decimal point.
>
> The locale controls that.
>
> % lua
>> tonumber("42,0")
> nil
>> os.setlocale"de_DE"
> de_DE
>> tonumber("42,0")
> 42,0
>> tonumber("42.0")
> 42,0

Well, that is converting a string to a number.  I had the problem when Lua converts a number to a string, i.e. the other way round.

Lua uses *(localconv())->decimal_point to get a localized decimal point and insert it into the string.  Most Linux distributions return a point when the LANG environment variable is not set. But openSUSE Leap returns a comma if LANG is not set.  As soon as you set LANG, it will return whatever is configured in that locale.  So it uses a different default decimal limiter than most other Linux distributions, it seems.

The reason was actually a funny one (but took me quite some time to find out):

I store some numbers (representing coins of a certain currency) in a number array in PostgreSQL.  The syntax to do so in SQL is „{5.0, 2.0, 1.0}“. Now, when Lua gives you commas instead of points, you get „{5,0, 2,0, 1,0}“, so it will insert six numbers instead of three.