From 1477c30cdf251863ed8eb3e1f1136262a9814130 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Sun, 6 Mar 2022 12:30:17 +0000 Subject: [PATCH 1/2] Avoid producing ? in locales with too few characters. Previously, if the locale used a character encoding without all characters, then 'gettext' could produce '?' characters. Avoid character encoding concerns by always using UTF-8. * libguile/gettext.c (scm_gettext): Use scm_to_utf8_string and scm_from_utf8_string for msgids. (scm_ngettext): Likewise. (scm_bindtextdomain): Set the character encoding to UTF-8. --- libguile/gettext.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libguile/gettext.c b/libguile/gettext.c index b9af4d313..bf54def7f 100644 --- a/libguile/gettext.c +++ b/libguile/gettext.c @@ -1,5 +1,7 @@ /* Copyright 2004,2006,2018 Free Software Foundation, Inc. + Copyright 2022 + Maxime Devos This file is part of Guile. @@ -100,7 +102,7 @@ SCM_DEFINE (scm_gettext, "gettext", 1, 2, 0, scm_dynwind_begin (0); - c_msgid = scm_to_locale_string (msgid); + c_msgid = scm_to_utf8_string (msgid); scm_dynwind_free (c_msgid); if (SCM_UNBNDP (domain)) @@ -133,7 +135,7 @@ SCM_DEFINE (scm_gettext, "gettext", 1, 2, 0, if (c_result == c_msgid) result = msgid; else - result = scm_from_locale_string (c_result); + result = scm_from_utf8_string (c_result); scm_dynwind_end (); return result; @@ -158,10 +160,10 @@ SCM_DEFINE (scm_ngettext, "ngettext", 3, 2, 0, scm_dynwind_begin (0); - c_msgid = scm_to_locale_string (msgid); + c_msgid = scm_to_utf8_string (msgid); scm_dynwind_free (c_msgid); - c_msgid_plural = scm_to_locale_string (msgid_plural); + c_msgid_plural = scm_to_utf8_string (msgid_plural); scm_dynwind_free (c_msgid_plural); c_n = scm_to_ulong (n); @@ -199,7 +201,7 @@ SCM_DEFINE (scm_ngettext, "ngettext", 3, 2, 0, else if (c_result == c_msgid_plural) result = msgid_plural; else - result = scm_from_locale_string (c_result); + result = scm_from_utf8_string (c_result); scm_dynwind_end (); return result; @@ -272,6 +274,10 @@ SCM_DEFINE (scm_bindtextdomain, "bindtextdomain", 1, 1, 0, else result = SCM_BOOL_F; + c_result = bind_textdomain_codeset (c_domain, "UTF-8"); + if (c_result == NULL) + SCM_SYSERROR; + scm_dynwind_end (); return result; } base-commit: 24b30130ca75653bdbacea84ce0443608379d630 -- 2.30.2