1 /* Message translation utilities.
2 Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 #ifdef HAVE_LANGINFO_CODESET
30 /* Opening quotation mark for diagnostics. */
31 const char *open_quote
= "'";
33 /* Closing quotation mark for diagnostics. */
34 const char *close_quote
= "'";
36 /* The name of the locale encoding. */
37 const char *locale_encoding
= NULL
;
39 /* Whether the locale is using UTF-8. */
40 bool locale_utf8
= false;
44 /* Initialize the translation library for GCC. This performs the
45 appropriate sequence of calls - setlocale, bindtextdomain,
46 textdomain. LC_CTYPE determines the character set used by the
47 terminal, so it has be set to output messages correctly. */
50 gcc_init_libintl (void)
52 #ifdef HAVE_LC_MESSAGES
53 setlocale (LC_CTYPE
, "");
54 setlocale (LC_MESSAGES
, "");
56 setlocale (LC_ALL
, "");
59 (void) bindtextdomain ("gcc", LOCALEDIR
);
60 (void) textdomain ("gcc");
62 /* Opening quotation mark. */
65 /* Closing quotation mark. */
68 #if defined HAVE_LANGINFO_CODESET
69 locale_encoding
= nl_langinfo (CODESET
);
70 if (locale_encoding
!= NULL
71 && (!strcasecmp (locale_encoding
, "utf-8")
72 || !strcasecmp (locale_encoding
, "utf8")))
76 if (!strcmp (open_quote
, "`") && !strcmp (close_quote
, "'"))
78 /* Untranslated quotes that it may be possible to replace with
79 U+2018 and U+2019; but otherwise use "'" instead of "`" as
82 #if defined HAVE_LANGINFO_CODESET
85 open_quote
= "\xe2\x80\x98";
86 close_quote
= "\xe2\x80\x99";
92 #if defined HAVE_WCHAR_H && defined HAVE_WORKING_MBSTOWCS && defined HAVE_WCSWIDTH
95 /* Returns the width in columns of MSGSTR, which came from gettext.
96 This is for indenting subsequent output. */
99 gcc_gettext_width (const char *msgstr
)
101 size_t nwcs
= mbstowcs (0, msgstr
, 0);
102 wchar_t *wmsgstr
= XALLOCAVEC (wchar_t, nwcs
+ 1);
104 mbstowcs (wmsgstr
, msgstr
, nwcs
+ 1);
105 return wcswidth (wmsgstr
, nwcs
);
108 #else /* no wcswidth */
110 /* We don't have any way of knowing how wide the string is. Guess
111 the length of the string. */
114 gcc_gettext_width (const char *msgstr
)
116 return strlen (msgstr
);
121 #endif /* ENABLE_NLS */
126 fake_ngettext (const char *singular
, const char *plural
, unsigned long n
)
136 /* Return the indent for successive lines, using the width of
137 the STR. STR must have been translated already. The string
138 must be freed by the caller. */
141 get_spaces (const char *str
)
143 size_t len
= gcc_gettext_width (str
);
144 char *spaces
= XNEWVEC(char, len
+ 1);
145 memset (spaces
, ' ', len
);