Examples of localization in Perl using gettext and Locale::TextDomain, with fallback if Locale::Text
- by Jakub Narebski
The "On the state of i18n in Perl" blog post from 26 April 2009 recommends using Locale::TextDomain module from libintl-perl distribution for l10n / i18n in Perl. Besides I have to use gettext anyway, and gettext support in Locale::Messages / Locale::TextDomain is more natural than in gettext emulation in Locale::Maketext.
The subsection "15.5.18 Perl" in chapter "15 Other Programming Languages" in GNU gettext manual says:
Portability
The libintl-perl package is platform independent but is not part of the Perl core. The programmer is responsible for providing a dummy implementation of the required functions if the package is not installed on the target system.
However neither of two examples in examples/hello-perl in gettext sources (one using lower level Locale::Messages, one using higher level Locale::TextDomain) includes detecting if the package is installed on the target system, and providing dummy implementation if it is not.
What is complicating matter (with respect to detecting if package is installed or not) is the following fragment of Locale::TextDomain manpage:
SYNOPSIS
use Locale::TextDomain ('my-package', @locale_dirs);
use Locale::TextDomain qw (my-package);
USAGE
It is crucial to remember that you use Locale::TextDomain(3) as specified in the section "SYNOPSIS", that means you have to use it, not require it. The module behaves quite differently compared to other modules.
Could you please tell me how one should detect if libintl-perl is present on target system, and how to provide dummy fallthrough implementation if it is not installed? Or give examples of programs / modules which do this?