manpagez: man pages & more
info bison
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9 Parser Internationalization

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 in GNU gettext utilities. 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.

  1. Into the directory containing the GNU Autoconf macros used by the package —often called ‘m4’— copy the ‘bison-i18n.m4’ file installed by Bison under ‘share/aclocal/bison-i18n.m4’ in Bison’s installation directory. For example:
    cp /usr/local/share/aclocal/bison-i18n.m4 m4/bison-i18n.m4
  2. In the top-level ‘’, after the AM_GNU_GETTEXT invocation, 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_LOCALEDIR variable, and it defines the source-language symbol YYENABLE_NLS to enable translations in the Bison-generated parser.
  3. In the main function 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 bindtextdomain (PACKAGE, LOCALEDIR) that your package already has. Here we rely on ‘BISON_LOCALEDIR’ to be defined as a string through the ‘Makefile’.

  4. In the ‘’ that controls the compilation of the main function, make ‘BISON_LOCALEDIR’ available as a C preprocessor macro, either in ‘DEFS’ or in ‘AM_CPPFLAGS’. For example:


  5. Finally, invoke the command autoreconf to generate the build infrastructure.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on December 1, 2013 using texi2html 5.0.

© 2000-2017
Individual documents may contain additional copyright information.