Dynamic Web Translation Using Petal::I18N

Andrew Rodland, Developer

http://cleverdomain.org/yapc07/

So what's with the lab coat?

I work at "HBS Labs". Sometimes people walk in and ask "Is this where I give the blood sample?"

But by night...

Okay, so what's this about?

Why Translate?

Really the question here is, what's the point of the exercise? Why go to the effort? So explain how I got here.

Techniques

AKA: "Why do it this way?"

Why MVC?

Don't Repeat Yourself is one good technique. Separation of Concerns is another. Keep separate things separate, so you can change one thing without spilling problems over into another area.

"What the MVC-for-the-web crowd are really trying to achieve is a clear separation of concerns. Put your database code in one place, your application code in another, your presentation code in a third place. That way, you can chop and change different elements at will, hopefully without affecting the other parts (depending on how well your concerns are separated, of course). This is common sense and good practice."

-- Andy B. Wardley

The Tools: Catalyst

Okay, so this is the stuff I'm using to do it.

Catalyst (cont.)

Catalyst itself isn't that big -- its real power is its love of CPAN. It's designed so that you can take almost any module and hook it into your app. And someone else probably already did it and released that on CPAN.

Don't actually need Catalyst here -- any system powerful enough to let you bring your own View will do.

Petal

Petal = Template Attribute Language

Petal (cont.)

I18n short for "internationalization".

This one's a little more critical to the process, just because there's a shortage of ZPT implementations in the world.

Gettext

Petal::I18N uses Gnu Gettext, which is the standard for providing localized text strings.

Dynamic Translation

Dynamic Translation (cont.)

Such as English.

Dynamic Translation (cont.)

And Spanish.

Dynamic Translation: Code Changes

Dynamic Translation: Tagging

<p i18n:translate="">This will be translated.</p>

<img src="pony.jpg" i18n:attributes="alt" alt="So will this." />

Dynamic Translation: String Extraction.

I18NFool uses msgmerge internally.

Dynamic Translation: Human Translation

Dynamic Translation: Human Translation (contd.)

Dynamic Translation: Wrapping up.

Load the site

PlatinumTel Prepaid Wireless

Dynamic Translation: The Pros

Dynamic Translation: The Cons

On the topic of slowness, bring up the Uniforum talk. Dynamic translation limited me to under 10 hits/sec on a fairly beefy machine.

The Alternative

Dynamic Ahead-of-Time Translation

Ahead of Time Translation: Code Changes

Ahead of Time: Still the Same

Ahead of Time: Template Generation

Ahead of Time: The Pros

With the fully dynamic technique, the translated templates are only available live on the web -- so online testing is required to make sure they came out right.

Ahead of Time: The Cons

Overall Results

Thank You

Questions?

Internationalization Pitfalls

The Obvious One

Character Encodings

Bonus: Something Cool

I said that the cool thing about Catalyst is CPAN. Well here's a cool "Found on CPAN."

Thank You

Questions?

Sample Code

Check this location in the near future for some example code for each of the steps.

http://cleverdomain.org/yapc07/