libintl-perl

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

contains a full-fledged example for an internationalized Perl package,
including a working Makefile.  The README of that subdirectory
explains all necessary steps.

However, if you are on a recent GNU/Linux system or similar (cygwin
should also do), chances are that you can get the following example to
run:

	#! /usr/local/bin/perl -w

	use strict;

	# This assumes that the textdomain 'libc' is available on your
	# system.  Try "locate libc.mo" or "locate libc.gmo" (or
	# "find / -type f -name libc.mo" if locate is not available on
	# your system).
	#
	# By the way, the "use Locale::TextDomain (TEXTDOMAIN) is the 
	# equivalent of
	#
	#      textdomain ("TEXTDOMAIN");
	#
	# in C or similar languages.
	use Locale::TextDomain ('libc');

	# The locale category LC_MESSAGES is not exported by the POSIX
	# module on older Perl versions.  
	use Locale::Messages qw (LC_MESSAGES);

	use POSIX ('setlocale');

	# Set the locale according to our environment.
	setlocale (LC_MESSAGES, '');

	# This makes the assumption that your system libc defines a 
	# message "No such file or directory".  Check the exact
	# spelling on your system with something like 
	# "ls NON-EXISTANT".
	# Note the double underscore in front of the string.  This is
	# really a function call to the function __() that is
	# automagically imported by Locale::TextDomain into your
	# namespace.  This function takes its argument, looks up a
	# translation for it, and returns that, or the unmodified
	# string in case of failure.
	print __"No such file or directory", ".\n";

	__END__

Now run the command "locale -a" or "nlsinfo" to get a list of
available locales on your system.  Try the section "Finding locales"
in "perldoc perllocale" if you have problems.

If, for example, the locale "fr_FR" is available on your system, set
the environment variable LANG to that value, for a POSIX shell

     LANG=fr_FR
     export LANG

for the C shell

     setenv LANG fr_FR

and run your little Perl script.  It should tell you what the error
message for "No such file or directory" is in French, or whatever
language you chose.  Not a real example, because we have "stolen" a
message from a system catalog.  But it should give you the general
idea, especially if you are already familiar with gettext in C.

If you still see the English message, this does not necessarily mean a
failure, since the string is maybe not translated on your system (try
"locate libc.mo" to get a list of available translations).  Even for
the translations listed there, that particular message might be
missing.  Try a common locale like "de_DE" or "fr_FR" that are usually
fully translated then.

Your next steps should be "perldoc Locale::TextDomain", and then study
the example in the subdirectory "sample" of this distribution.

Have fun with libintl-perl!

Guido Flohr



( run in 0.713 second using v1.01-cache-2.11-cpan-39bf76dae61 )