The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Petal::I18N - Attempt at implementing ZPT I18N for Petal

SYNOPSIS

in your Perl code:

  use Petal;
  use Petal::TranslationService::h4x0r;

  # we want to internationalize to the h4x0rz 31337 l4nGu4g3z. w00t!
  my $translation_service = Petal::TranslationService::h4x0r->new();
  my $template = new Petal (
      file => 'silly_example.xhtml',
      translation_service => $ts,
  );

  print $template->process ();

in silly_example.xhtml

  <html><body>
    <!-- this is a mad example of romanized japanese, which we
         are going to turn into h4x0rz r0m4n|z3d J4paN33z -->

    <div i18n:translate="">
      Konichiwa, <span i18n:name="name">Buruno</span>-san,
      Kyoo wa o-genki desu ka?
    </div>
  </body></html>

... And you get something like:

  <html><body>
    <!-- this is a mad example of romanized japanese, which we
         are going to turn into h4x0rz r0m4n|z3d J4paN33z -->

    <div>K0N1cH1W4, <span>Buruno</span>-s4N, Ky00 w4 o-geNkI DesU kA?</div>
  </body></html>

HOW IT WORKS

You simply instanciate any kind of object and pass it when you construct the Petal object, as described in the synopsis.

As long as this object has an instance method called maketext ($stuff), it'll work.

At the moment there are two TranslationService objects shipped with the library:

Petal::TranslationService::h4x0r (rather useless - but kinda fun)
Petal::TranslationService::MOFile (works with .mo files produced by gettext)

So if you want to use a .mo file to translate your template, you just do:

   my $ts = Petal::TranslationService::MOFile->new ("/path/to/file.mo");

   my $t  = Petal->new ( file => '/path/to/template.xml',
                         translation_service => $ts );

   print $t->process (%args);

MORE INFORMATION

You can find the I18N specification at this address.

  L<http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ZPTInternationalizationSupport>

At the moment, Petal supports the following constructs:

xmlns:i18n="http://xml.zope.org/namespaces/i18n" - strips it
i18n:translate
i18n:domain
i18n:name
i18n:attribute

It does *NOT* (well, not yet) support i18n:source, i18n:target or i18n:data. Also note that namespace support is not implemented properly: you cannot change the prefix, so declaring

  xmlns:internationalization="http://xml.zope.org/namespaces/i18n"

will not work.

I18N HOWTO

... coming soon :-)