bugGNU gettext - Bugs: bug #54479, libintl_setlocale(LC_ALL,...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #54479: libintl_setlocale(LC_ALL, "") fails under some locales in macOS

Submitter:  Dapeng Gao <dpgao>
Submitted:  Thu 09 Aug 2018 01:33:27 PM UTC
   
 
Category:  End-user / runtime Severity:  3 - Normal
Item Group:  None Status:  Fix Released
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed

Jump to the original submission

Sun 15 Sep 2019 11:41:10 PM UTC, comment #6: 

An improvement was added on 2019-05-20:
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=661c55d6c287e1e6122e0ec03668ec859b6d806a

It will be contained in gettext-0.21.

Bruno Haible <haible>
Group administrator
Thu 09 May 2019 07:31:05 PM UTC, comment #5: 

The fix is contained in the gettext-0.20 release.

Bruno Haible <haible>
Group administrator
Sun 16 Sep 2018 09:01:42 AM UTC, comment #4: 

I did not use the patch from https://lists.gnu.org/archive/html/bug-gettext/2018-08/msg00017.html because

1) It introduces code that makes libintl_setlocale succeed although some of its inner mechanics failed. In other words, it sweeps all kinds of failures under the rug. It is better to signal failure outright and without delay, and to treat only specific failures like success.

2) The failed call was setlocale (LC_ALL, "UTF-8"), apparently because macOS supports "UTF-8" as a locale name only for LC_CTYPE but not for LC_ALL. I find it better to make libintl_setlocale succeed (the best we can), rather than fail.

Bruno Haible <haible>
Group administrator
Sun 16 Sep 2018 01:30:11 AM UTC, comment #3: 

With the new code, your test program main.c produces the output

C
C/UTF-8/C/C/C/C

and this output to stderr:

Warning: Failed to set locale category LC_NUMERIC to en_HK.
Warning: Failed to set locale category LC_TIME to en_HK.
Warning: Failed to set locale category LC_COLLATE to en_HK.
Warning: Failed to set locale category LC_MONETARY to en_HK.
Warning: Failed to set locale category LC_MESSAGES to en_HK.

Which can be seen as a hint that you should complain to Apple because they don't support in libc a locale that can be set in the System Preferences dialog :)

Bruno Haible <haible>
Group administrator
Sun 16 Sep 2018 01:11:52 AM UTC, comment #2: 
Bruno Haible <haible>
Group administrator
Thu 09 Aug 2018 02:17:57 PM UTC, comment #1: 

After reading the code I think the problem arises on line 855 of `setlocale.c', where a call like `setlocale_unixlike (LC_ALL, "UTF-8")' will fail on macOS. This is because

a) The call on line 645, which is `setlocale(LC_ALL, "UTF-8")', will fail (I have tested this).
b) `setlocale_unixlike' makes an incorrect assumption about the format of the `locale' string, so further attempts to recover will also fail.

Shall we perhaps change `setlocale_unixlike' to better handle this?

Dapeng Gao <dpgao>
Thu 09 Aug 2018 01:33:27 PM UTC, original submission:  

When the system region and language in macOS are set to certain combinations (e.g. Region = Hong Kong, Language = English), the output of the `locale' command will appear as follows:

LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

In such cases, `libintl_setlocale(LC_ALL, "")' incorrectly returns NULL instead of setting the correct locale, as the system `setlocale' function would do.

The attached file will reproduce the bug. Commenting out `#include <libintl.h>' produces the correct output:

C
C/UTF-8/C/C/C/C

Dapeng Gao <dpgao>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #44756:  main.c added by dpgao (183B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by dpgao (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-01-04 haible StatusFixed Fix Released
    2018-09-16 haible StatusNone Fixed
        Assigned toNone haible
        Open/ClosedOpen Closed
    2018-08-09 dpgao Attached File- Added main.c, #44756

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code