-
-
04 Nov 2004 12:35:46 UTC
- Distribution: i18n
- Module version: 0.07
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (1)
- Testers (138 / 12 / 0)
- Kwalitee
Bus factor: 2- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (11.88KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Autrijus Tang
- Dependencies
- Locale::Maketext
- Locale::Maketext::Lexicon
- Locale::Maketext::Simple
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
i18n - Perl Internationalization Pragma
VERSION
This document describes version 0.07 of i18n, released November 4, 2004.
SYNOPSIS
In one-liners:
% export LANG=sp % perl -Mi18n=/path/to/po-files/ -le 'print ~~"Hello, world"'; Hola, mundo
In your module:
use i18n "/path/to/po-files"; my $place = ~~'world'; print ~~"Hello, $world";
DESCRIPTION
Internationalization (abbreviated
i18n
) is the process of designing an application so that it can be adapted to various languages and regions. The most basic task is to let your program know which strings are meant for human consumption and which strings are intended for the computer.Strings for humans need to get localized (translated to the language of the human using your program) and strings for computers must not get translated.
Syntax
The
i18n
module gives you a remarkably simple way to mark strings that are intended for humans. All you do is put two tilde signs (~~
) in front of every string that is intended to be translated. That's it. All the other details of localization are handled outside the program. Here are some examples:my $str1 = ~~'The time is now'; my $str2 = ~~"$str1 for having a cow"; my $str3 = ~~qq{Wow! $str2}; my $str4 = ~~<<END; How now. Brown cow. END
Think of the tilde signs as an indicator that you are looking for things that approximates the string in the user's language. To turn off the magic of
~~
lexically, just say:no i18n;
One nice thing about this particular markup, is that you can completely turn off internationalization, by simply removing the
use i18n;
statement. The~~
signs are actually valid Perl that just happen to not do anything in this context, and thus are constant-optimized away at compile time.Implementation
When you say:
my $string = ~~"Bob is your uncle";
then
$string
really is ani18n::string
object that is overloaded to stringify as a localized translation.Currently, the magic is just a thin wrapper on
Locale::Maketext::Simple
, which makes it equivalent to this call:my $string = loc("Bob is your uncle");
Similarly, this line:
my $string = ~~"$person is your uncle";
will be turned into this at runtime:
my $string = loc("[_1] is your uncle", $person);
CAVEATS
The authors of this module are not linguists. If you would like to help us define suitable
i18n
magic for your language, please send us an email.One thing we plan to do next is to provide collaborative, just-in-time lexicon creation tools. So Joe American could write his wonderful Perl script in English, with the appropriate
~~
notation, and 24 hours later it would "just work" in Swahili.SEE ALSO
Locale::Maketext::Simple, Locale::Maketext::Lexicon
AUTHORS
Autrijus Tang <autrijus@autrijus.org>, Brian Ingerson <INGY@cpan.org>.
COPYRIGHT
Copyright 2004 by Autrijus Tang <autrijus@autrijus.org>, Brian Ingerson <INGY@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install i18n, copy and paste the appropriate command in to your terminal.
cpanm i18n
perl -MCPAN -e shell install i18n
For more information on module installation, please visit the detailed CPAN module installation guide.