]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Windows: Make NLS require UCRT and gettext-runtime >= 0.23.1
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 2 Jan 2025 11:35:48 +0000 (13:35 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 2 Jan 2025 13:42:13 +0000 (15:42 +0200)
Also remove the recently-added workaround from tuklib_gettext.h.
Requiring a new enough gettext-runtime is cleaner. I guess it's
mostly MSYS2 where xz is built with translation support, so once
MSYS2 has Gettext >= 0.23.1, this requirement shouldn't be a problem
in practice.

(cherry picked from commit 16821252c504071f5c2012e415e59cbf5fb79820)

CMakeLists.txt
configure.ac
src/common/tuklib_gettext.h

index e08635739f9a4c3b510d0d75e2cc66ec2be4f862..b473f90f15f17af6dedcab8a72498c938cc6f24d 100644 (file)
@@ -359,6 +359,35 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
                             "disabled by passing -DENABLE_NLS=OFF to cmake.")
         endif()
 
+        if(ENABLE_NLS AND WIN32)
+            # The command line tools use UTF-8 on native Windows.
+            # Non-ASCII characters display correctly only when
+            # using UCRT and gettext-runtime >= 0.23.1.
+            check_c_source_compiles(
+                    "#define WIN32_LEAN_AND_MEAN
+                    #include <windows.h>
+                    #include <libintl.h>
+
+                    #ifndef _UCRT
+                    #error \"Not UCRT\"
+                    #endif
+
+                    #if LIBINTL_VERSION < 0x001701
+                    #error \"gettext-runtime < 0.23.1\"
+                    #endif
+
+                    int main(void) { return 0; }
+                "
+                USING_UCRT_AND_RECENT_GETTEXT)
+            if(NOT USING_UCRT_AND_RECENT_GETTEXT)
+                message(FATAL_ERROR "Native language support (NLS) was enabled "
+                                    "but it requires UCRT and "
+                                    "gettext-runtime >= 0.23.1. To build with "
+                                    "MSVCRT or old gettext-runtime, "
+                                    "set ENABLE_NLS=OFF.")
+            endif()
+        endif()
+
         # Warn if NLS is enabled but translated man pages are missing.
         if(UNIX AND ENABLE_NLS AND
                 NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po4a/man")
index 08c9fcd89a7239e03f98532f92bfd4aee662c1b9..de2951b96efef7a10b6b60896a44dda19e2ff06f 100644 (file)
@@ -811,6 +811,35 @@ AM_GNU_GETTEXT_REQUIRE_VERSION([0.19.6])
 AM_GNU_GETTEXT_VERSION([0.19.6])
 AM_GNU_GETTEXT([external])
 
+# The command line tools use UTF-8 on native Windows. Non-ASCII characters
+# display correctly only when using UCRT and gettext-runtime >= 0.23.1.
+AS_CASE([$USE_NLS-$host_os],
+       [yes-mingw*], [
+               AC_MSG_CHECKING([for UCRT and gettext-runtime >= 0.23.1])
+               AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
+                       #define WIN32_LEAN_AND_MEAN
+                       #include <windows.h>
+                       #include <libintl.h>
+
+                       #ifndef _UCRT
+                       #error "Not UCRT"
+                       #endif
+
+                       #if LIBINTL_VERSION < 0x001701
+                       #error "gettext-runtime < 0.23.1"
+                       #endif
+               ]])], [
+                       AC_MSG_RESULT([yes])
+               ], [
+                       AC_MSG_RESULT([no])
+                       AC_MSG_ERROR([
+    Translation support (--enable-nls) on native Windows requires
+    UCRT and gettext-runtime >= 0.23.1. Use --disable-nls to build
+    with MSVCRT or old gettext-runtime.])
+               ])
+       ]
+)
+
 
 ###############################################################################
 # Checks for header files.
index 008cf491eedd905c614f71f220aad570af3add02..3ef5cb7292b59b57756d4abfc7dcec4fb808b005 100644 (file)
 #endif
 
 #if TUKLIB_GETTEXT
-#      if defined(_WIN32) && !defined(__CYGWIN__)
-               // <libintl.h> from gettext-runtime redirects setlocale()
-               // to libintl_setlocale(). As of gettext 0.22.5 (and probably
-               // 0.23), libintl_setlocale(LC_ALL, "") doesn't set the locale
-               // to UTF-8 if UTF-8 code page has been set in the application
-               // manifest. For example, one may get "fi_FI" when native
-               // setlocale() would result in "Finnish_Finland.utf8". The
-               // lack of ".utf8" (or equivalent) suffix results in garbled
-               // non-ASCII chars in translatated messages and also affects
-               // functions like mbrtowc() which depend on LC_CTYPE.
-               //
-               // Workaround the problem by not using libintl_setlocale()
-               // for now. Notes:
-               //
-               // (1) libintl_setlocale() reads LC_* environment variables
-               //     but native setlocale() doesn't. The loss of this
-               //     feature doesn't matter too much because, on Windows,
-               //     libintl still reads the env vars LANGUAGE, LC_ALL,
-               //     LC_MESSAGES, and LANG when translating messages in
-               //     the LC_MESSAGES category (other categories are very
-               //     rarely used for translations). As of Gettext commit
-               //     e18edc579 and Gnulib commit 9e301775ff:
-               //
-               //     libintl_gettext()
-               //      `-- libintl_dcgettext()
-               //           `-- libintl_dcigettext()
-               //                `-- guess_category_value()
-               //                     |-- gl_locale_name_posix()
-               //                     |    `-- gl_locale_name_posix_unsafe()
-               //                     |         `-- gl_locale_name_environ()
-               //                     |              |-- getenv("LC_ALL")
-               //                     |              |-- getenv("LC_MESSAGES")
-               //                     |              `-- getenv("LANG")
-               //                     `-- getenv("LANGUAGE")
-               //
-               // (2) If locale is changed, libintl_setlocale() marks cached
-               //     translations as invalid. bindtextdomain(), which we
-               //     call immediately after setlocale(), does the same
-               //     invalidation too. Thus it doesn't matter in the
-               //     tuklib_gettext_init() macro. It could matter if the
-               //     application calls setlocale() elsewhere though (but
-               //     then it's not guaranteed that such code even includes
-               //     <libint.h> in addition to <locale.h>).
-               //
-               // This macro is checked by <libintl.h> since Gettext 0.18.2
-               // (2012-12-08). When this is defined, setlocale() isn't
-               // overridden.
-               //
-               // FIXME: Remove this hack when it's no longer needed.
-#              define GNULIB_defined_setlocale 1
-#      endif
 #      include <libintl.h>
 #      define tuklib_gettext_init(package, localedir) \
                do { \