hgettext-0.1.10: Bindings to libintl.h (gettext, bindtextdomain)

Distribution.Simple.I18N.GetText

Description

This library extends the Distribution with internationalization support.

It performs two functions:

  • compiles and installs PO files to the specified directory
  • tells the application where files were installed to make it able to bind them to the code

Each PO file will be placed to the {datadir}/locale/{loc}/LC_MESSAGES/{domain}.mo where:

datadir
Usually prefix/share but could be different, depends on system.
loc
Locale name (language code, two characters). This module supposes, that each PO file has a base name set to the proper locale, e.g. de.po is the German translation of the program, so this file will be placed under {datadir}/locale/de directory
domain
Program domain. A unique identifier of single translational unit (program). By default domain will be set to the package name, but its name could be configured in the .cabal file.

The module defines following .cabal fields:

x-gettext-domain-name
Name of the domain. One ofmore alphanumeric characters separated by hyphens or underlines. When not set, package name will be used.
x-gettext-po-files
List of files with translations. Could be used a limited form of wildcards, e.g.: x-gettext-po-files: po/*.po
x-gettext-domain-def
Name of the macro, in which domain name will be passed to the program. Default value is __MESSAGE_CATALOG_DOMAIN__
x-gettext-msg-cat-def
Name of the macro, in which path to the message catalog will be passed to the program. Default value is __MESSAGE_CATALOG_DIR__

The last two parameters are used to send configuration data to the code during its compilation. The most common usage example is:

 ...
 prepareI18N = do
    setLocale LC_ALL (Just "") 
    bindTextDomain __MESSAGE_CATALOG_DOMAIN__ (Just __MESSAGE_CATALOG_DIR__)
    textDomain __MESSAGE_CATALOG_DOMAIN__

 main = do
    prepareI18N
    ...

 ...

NOTE: files, passed in the x-gettext-po-files are not automatically added to the source distribution, so they should be also added to the extra-source-files parameter, along with translation template file (usually message.pot)

WARNING: sometimes, when only configuration targets changes, code will not recompile, thus you should execute cabal clean to cleanup the build and restart it again from the configuration. This is temporary bug, it will be fixed in next releases.

Synopsis

Documentation

installGetTextHooksSource

Arguments

:: UserHooks

initial user hooks

-> UserHooks

patched user hooks

Installs hooks, used by GetText module to install PO files to the system. Previous won't be disabled

gettextDefaultMain :: IO ()Source

Default main function, same as

 defaultMainWithHooks $ installGetTextHooks simpleUserHooks