git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Jonathan Nieder" <jrnieder@gmail.com>,
	"Marcin Cieslak" <saper@saper.info>,
	"Jens Lehmann" <Jens.Lehmann@web.de>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH/RFC 07/17] gettext.c: work around us not using setlocale(LC_CTYPE, "")
Date: Mon, 30 Aug 2010 21:28:13 +0000	[thread overview]
Message-ID: <1283203703-26923-8-git-send-email-avarab@gmail.com> (raw)
In-Reply-To: <1283203703-26923-1-git-send-email-avarab@gmail.com>

Change the gettext setup code to arrange for messages to be emitted in
the user's requested encoding, but avoid setting LC_CTYPE from the
environment for the whole program.

In 107880a I removed our use of setlocale(LC_CTYPE, "") because of a
bug in the GNU C Library [1]. Even if it wasn't for that bug we
wouldn't want to use LC_CTYPE at this point, because it'd require
auditing all the code that uses C functions whose semantics are
modified by LC_CTYPE.

But only setting LC_MESSAGES as we do creates a problem, since we
declare the encoding of our PO files[2] the gettext implementation
will try to recode it to the user's locale, but without LC_CTYPE it'll
emit something like this on 'git init'

    Bj? til t?ma Git lind ? /hl/agh/.git/

Gettext knows about the encoding of our PO file, but we haven't told
it about the user's encoding, so all the non-US-ASCII characters get
encoded to question marks.

But we're in luck! We can set LC_CTYPE from the environment only while
we call nl_langinfo and bind_textdomain_codeset. That suffices to tell
gettext what encoding it should emit in, so it'll now say:

    Bjó til tóma Git lind í /hl/agh/.git/

And the equivalent ISO-8859-1 string will be emitted under a
ISO-8859-1 locale.

With this change way we get the advantages of setting LC_CTYPE (talk
to the user in his language/encoding), without the drawbacks (changed
semantics for C functions we rely on).

In the long term we should probably see about getting that bug in
glibc fixed, and audit our code so it won't fall apart under a non-C
locale.

1. http://sourceware.org/bugzilla/show_bug.cgi?id=6530
2. E.g. "Content-Type: text/plain; charset=UTF-8\n" in po/is.po

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 gettext.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/gettext.c b/gettext.c
index db99742..8644098 100644
--- a/gettext.c
+++ b/gettext.c
@@ -1,11 +1,13 @@
 #include "exec_cmd.h"
 #include <locale.h>
 #include <libintl.h>
+#include <langinfo.h>
 #include <stdlib.h>
 
 extern void git_setup_gettext(void) {
 	char *podir;
 	char *envdir = getenv("GIT_TEXTDOMAINDIR");
+	char *charset;
 
 	if (envdir) {
 		(void)bindtextdomain("git", envdir);
@@ -17,5 +19,9 @@ extern void git_setup_gettext(void) {
 	}
 
 	(void)setlocale(LC_MESSAGES, "");
+	(void)setlocale(LC_CTYPE, "");
+	charset = nl_langinfo(CODESET);
+	(void)bind_textdomain_codeset("git", charset);
+	(void)setlocale(LC_CTYPE, "C");
 	(void)textdomain("git");
 }
-- 
1.7.2.2.536.g3f548

  parent reply	other threads:[~2010-08-30 21:30 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-30 21:28 [PATCH/RFC 00/17] Begin gettextizing Git Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 01/17] Makefile: A variable for options used by xgettext(1) calls Ævar Arnfjörð Bjarmason
2010-08-31 14:51   ` Jonathan Nieder
2010-08-31 16:36     ` Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 02/17] Makefile: provide a --msgid-bugs-address to xgettext(1) Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 03/17] Makefile: tell xgettext(1) that our source is in UTF-8 Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 04/17] builtin.h: Include gettext.h Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 05/17] gettext: make the simple parts of git-init localizable Ævar Arnfjörð Bjarmason
2010-08-31 15:03   ` Jonathan Nieder
2010-08-31 15:37     ` Ævar Arnfjörð Bjarmason
2010-08-31 15:44       ` Jonathan Nieder
2010-08-31 16:05         ` Ævar Arnfjörð Bjarmason
2010-08-31 16:09           ` Jonathan Nieder
2010-08-31 16:27           ` Junio C Hamano
2010-08-30 21:28 ` [PATCH/RFC 06/17] gettext: localize the main git-init message Ævar Arnfjörð Bjarmason
2010-08-31 15:10   ` Jonathan Nieder
2010-08-31 15:39     ` Ævar Arnfjörð Bjarmason
2010-08-31 15:48       ` Jonathan Nieder
2010-08-30 21:28 ` Ævar Arnfjörð Bjarmason [this message]
2010-08-31 15:18   ` [PATCH/RFC 07/17] gettext.c: work around us not using setlocale(LC_CTYPE, "") Jonathan Nieder
2010-08-31 15:37     ` Marcin Cieslak
2010-08-31 15:49       ` Jonathan Nieder
2010-08-31 16:51     ` Ævar Arnfjörð Bjarmason
2010-08-31 22:45       ` Jonathan Nieder
2010-08-31 22:58         ` Erik Faye-Lund
2010-08-30 21:28 ` [PATCH/RFC 08/17] gettext tests: test if $VERSION exists before using it Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 09/17] gettext tests: update test/is.po to match t/t0200/test.c Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 10/17] gettext tests: add detection for is_IS.ISO-8859-1 locale Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 11/17] gettext tests: test message re-encoding under Shell Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 12/17] gettext tests: test re-encoding with a UTF-8 msgid " Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 13/17] gettext tests: mark a test message as not needing translation Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 14/17] po/is.po: msgmerge and add Language: header Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 15/17] po/is.po: add Icelandic translation Ævar Arnfjörð Bjarmason
2010-08-31 15:29   ` Jonathan Nieder
2010-08-31 17:01     ` Ævar Arnfjörð Bjarmason
2010-08-31 19:14       ` Erik Faye-Lund
2010-08-31 19:32         ` Ævar Arnfjörð Bjarmason
2010-08-31 19:49           ` Erik Faye-Lund
2010-08-30 21:28 ` [PATCH/RFC 16/17] po/pl.po: add Polish translation Ævar Arnfjörð Bjarmason
2010-08-30 21:28 ` [PATCH/RFC 17/17] gettext tests: test message re-encoding under C Ævar Arnfjörð Bjarmason
2010-08-30 21:42 ` [PATCH/RFC 00/17] Begin gettextizing Git Junio C Hamano
2010-08-31  9:02   ` [PATCH] gettext: Make NO_GETTEXT=YesPlease the default in releases Ævar Arnfjörð Bjarmason
2010-08-31 17:18   ` [PATCH/RFC 00/17] Begin gettextizing Git Ævar Arnfjörð Bjarmason
2010-08-31 18:08     ` Jonathan Nieder
2010-08-31 18:24       ` Ævar Arnfjörð Bjarmason
2010-08-31 19:22         ` Jonathan Nieder
2010-08-31 19:35           ` Ævar Arnfjörð Bjarmason
2010-08-31 19:42             ` Jonathan Nieder
2010-08-31 11:08 ` Peter Krefting
2010-08-31 11:42   ` Ævar Arnfjörð Bjarmason
2010-08-31 11:48     ` Peter Krefting
2010-08-31 12:02     ` Matthieu Moy
2010-08-31 12:43       ` Ævar Arnfjörð Bjarmason
2010-08-31 15:32 ` Jonathan Nieder
2010-08-31 16:05   ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283203703-26923-8-git-send-email-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=saper@saper.info \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).