I work at "HBS Labs". Sometimes people walk in and ask "Is this where I give the blood sample?"
Really the question here is, what's the point of the exercise? Why go to the effort? So explain how I got here.
AKA: "Why do it this way?"
Just move on to the next one.
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.
-- Andy B. Wardley
Okay, so this is the stuff I'm using to do it.
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.
http://catalyst.perl.org
.
Petal = Template Attribute Language
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.
<table petal:condition="true: ponies"> <tr petal:repeat="pony ponies"> <td>${pony/name}</td> <td>${pony/age}</td> <td>${pony/color}</td> </tr> </table> <div petal:condition="false: ponies"> You don't have any ponies. How sad. </div>
Petal::I18N
.
Petal::I18N
uses Gnu Gettext, which is the standard for providing localized
text strings.
use Petal::I18N;
<p i18n:translate="">This will be translated.</p> <img src="pony.jpg" i18n:attributes="alt" alt="So will this." />
I18NFool uses msgmerge internally.
I18NFool
is a utility that scans HTML for these attributes and creates a
gettext database.
<p i18n:translate=""> <b i18n:translate="">Please wait</b> while we process your order. </p>
"Please wait"
"${1} while we process your order."
i18nfool-update
to compile the gettext file to a .mo
file.
On the topic of slowness, bring up the Uniforum talk. Dynamic translation limited me to under 10 hits/sec on a fairly beefy machine.
Petal::I18N
as before.
.po
file.
.mo
database.
Petal::I18N
isn't loaded into the site.
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.
Petal::I18N
is funny and eats variables if used offline, needs patch.
Catalyst::Plugin::I18N::Request
.
A user browsing in Spanish can go to /usario/busca?nombre=Pedro
and get dispatched
to the code for /user/search?name=Pedro
.