Locale-MakePhrase
view release on metacpan or search on metacpan
lib/Locale/MakePhrase.pm view on Meta::CPAN
);
my $mp = new Locale::MakePhrase(
language => 'en_AU',
backing_store => $bs,
);
...
my $color_count = 1;
print $mp->translate("Please select [_1] colors.",$color_count);
Output:
Please select a colour.
Notice that a) the word 'color' has been localised to Australian
English, and b) that the argument has influenced the resultant output
text to take into account the display of the singular version.
=head1 DESCRIPTION
This aim of these modules are to implement run-time evaluation of an
input phrase, including program arguments, and have it generate a
suitable output phrase, in the language and encoding specified by the
user of the application.
Since this problem has been around for some time, there are a number
of sources of useful information available on the web, which describes
why this problem is hard to solve. The problem with most existing
solutions is that each design suffers some form of limitation, often
due to the designer thinking that there are enough commonalities
between all/some langugaes that these commonalities can be factored
into a various rules which can be implemented in programming code.
However, each language has it own history and evolution. Thus it is
pointless to compare two different languages unless they have a common
history and a common character set.
I<Before> continuing to read this document, you really should read the
following info on the L<Locale::Maketext> Perl module:
http://search.cpan.org/~sburke/Locale-Maketext-1.08/lib/Locale/Maketext.pod
and at the slides presented here:
http://www.autrijus.org/webl10n/
The L<Locale::MakePhrase> modules are based on a design similar to the
L<Locale::Maketext> module, except that this new implementation has
taken a different approach, that being...
Since it is possible (and quite likely) that the application will need
to be able to understand the language rules of any specific language,
we want to use a run-time evaluation of the rules that a linguist
would use to convert one language to another. Thus we have coined the
term I<linguistic rules> as a means to describe this technique. These
rules are used to decide which piece of text is displayed, for a given
input text and arguments.
=head1 REQUIREMENTS
The L<Locale::MakePhrase> module was initially designed to meet the
requirements of a web application (as opposed to a desktop
application), which may display many languages in the HTML form at any
given instance.
Its design is modelled on a similar design of using language lexicons,
which is in use in the existing L<Locale::Maketext> Perl module. The
reason for building a new module is because:
=over 2
=item *
We wanted to completely abstract the language rule capability, to be
programming language agnostic so that we could re-implement this
module in other programming languages.
=item *
We needed run-time evaluation of the rules, since the translations
may be updated at any time; new rules may be added whenever there is
some ambigutiy in the existing phrase. Also, we didn't want to
re-start the application whenever we updated a rule.
=item *
We would like to support various types of storage mechanisms for the
translations. The origonal design constraint prefered the use of a
PostgreSQL database to hold the translations - most existing language
translation systems use flat files.
=item *
We want to store/manipulate the current text phrase, only encoded in
UTF-8 (ie: we dont want to store the text in a locale-specific
encoding). This allows us to output text to any other character set.
=back
As an example of application usage, it is possible for a Hebrew
speaking user to be logged into a web-form which contains Japanese
data. As such they will see:
=over 2
=item *
Menus and tooltips will be translated into the users' language (ie: Hebrew).
=item *
Titles will be in the language of the dataset (ie: Japanese).
=item *
Some of the data was in Latin character set (ie: English).
=item *
If the user prefered to see the page as RTL rather than LTR, the page
was altered to reflect this preference.
( run in 1.730 second using v1.01-cache-2.11-cpan-98e64b0badf )