A Bison-generated parser can print diagnostics, including error and tracing messages. By default, they appear in English. However, Bison also supports outputting diagnostics in the user's native language. To make this work, the user should set the usual environment variables. See The User's View. For example, the shell command ‘export LC_ALL=fr_CA.UTF-8’ might set the user's locale to French Canadian using the UTF-8 encoding. The exact set of available locales depends on the user's installation.
The maintainer of a package that uses a Bison-generated parser enables the internationalization of the parser's output through the following steps. Here we assume a package that uses GNU Autoconf and GNU Automake.
cp /usr/local/share/aclocal/bison-i18n.m4 m4/bison-i18n.m4
AM_GNU_GETTEXTinvocation, add an invocation of
BISON_I18N. This macro is defined in the file bison-i18n.m4 that you copied earlier. It causes ‘configure’ to find the value of the
BISON_LOCALEDIRvariable, and it defines the source-language symbol
YYENABLE_NLSto enable translations in the Bison-generated parser.
mainfunction of your program, designate the directory containing Bison's runtime message catalog, through a call to ‘bindtextdomain’ with domain name ‘bison-runtime’. For example:
bindtextdomain ("bison-runtime", BISON_LOCALEDIR);
Typically this appears after any other call
(PACKAGE, LOCALEDIR) that your package already has. Here we rely on
‘BISON_LOCALEDIR’ to be defined as a string through the
mainfunction, make ‘BISON_LOCALEDIR’ available as a C preprocessor macro, either in ‘DEFS’ or in ‘AM_CPPFLAGS’. For example:
DEFS = @DEFS@ -DBISON_LOCALEDIR='"$(BISON_LOCALEDIR)"'
AM_CPPFLAGS = -DBISON_LOCALEDIR='"$(BISON_LOCALEDIR)"'