NAME
Locale::Maketext::Gettext::Functions - Functional interface to Locale::Maketext::Gettext
SYNOPSIS
use Locale::Maketext::Gettext::Functions;
bindtextdomain(DOMAIN, LOCALEDIR);
textdomain(DOMAIN);
print __("Hello, world!");
DESCRIPTION
WARNING: This is still experimental. Use at your own risk. Tests and suggestions are welcome.
This is the functional interface to Locale::Maketext::Gettext (and Locale::Maketext).
The maketext
function attempts to translate a text string into the user's native language, by looking up the translation in a message catalog.
FUNCTIONS
- bindtextdomain(DOMAIN, LOCALEDIR)
-
Register a text domain with a locale directory. Returns
LOCALEDIR
itself. IfLOCALEDIR
is omitted, the registered locale directory ofDOMAIN
is returned. This method always success. - textdomain(DOMAIN)
-
Set the current text domain. Returns the
DOMAIN
itself. ifDOMAIN
is omitted, the current text domain is returned. This method always success. - maketext($key, @param...)
-
Attempts to translate a text string into the user's native language, by looking up the translation in a message catalog. Refer to Locale::Maketext(3) for the details on its c<maketext> method.
- __($key, @param...)
-
An synonym to
maketext()
. This is a shortcut tomaketext()
so that it is neater when you employ maketext to your existing project. - N_($key, @param...)
-
Return the original text untouched. This is to enable the text be catched with xgettext.
STORY
The idea is that: I finally realized that, no matter how hard I try, I can never get a never-failure maketext
. A wrapper like:
sub __ { return $LH->maketext(@_) };
always fails if $LH is not initialized yet. For this reason, maketext
can hardly be employed in error handlers to output graceful error messages in the natural language of the user. So, I have to write something like this:
sub __ {
$LH->MyPkg::L10N->get_handle if !defined $LH;
return $LH->maketext(@_);
}
But what if get_handle
itself fails? So, this becomes:
sub __ {
$LH->MyPkg::L10N->get_handle if !defined $LH;
$LH->_AUTO->get_handle if !defined $LH;
return $LH->maketext(@_);
}
package _AUTO;
use base qw(Locale::Maketext);
package _AUTO::i_default;
use base qw(Locale::Maketext);
%Lexicon = ( "_AUTO" );
Ya, this works. But, if I have always have to do this in my every application, why shouldn't I make a solution to the localization framework itself? This is a common problem to every localization projects. It should be solved at the localization framework level, but not at the applications level.
Another reason is that: Programmers should be able to use maketext
without the knowledge of object programming. A localization network should be neat and simple. It should lower down its barrier, be friendly to the beginners, in order to encourage localization and globalization. Apparently the current practice of Locale::Maketext
doesn't satisfy this request.
The third reason is: Since Locale::Maketext::Gettext(3) imports the lexicon from foreign sources, the class source file is left empty. It exists only to help the get_handle
method looking for a proper language handle. Then, why not make it disappear, and be generated whenever needed? Why bother the programmers to put an empty class source file there?
How neat can we be?
imacat, 2003-04-29
SEE ALSO
Locale::Maketext(3), Locale::Maketext::TPJ13(3), Locale::Maketext::Gettext(3), bindtextdomain(3), textdomain(3). Also, please refer to the official GNU gettext manual at http://www.gnu.org/manual/gettext/.
AUTHOR
imacat <imacat@mail.imacat.idv.tw>
COPYRIGHT
Copyright (c) 2003 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.