Website Translation using Perl and Catalyst
Wheaton, IL
October 10th, 2006
What did I do?
continued...
What did I do?
- And "translation-enabled" it.
continued...
What did I do?
- And "translation-enabled" it.
So why do you care?
- I did it in Perl, with Catalyst.
continued...
So why do you care?
- I did it in Perl, with Catalyst.
- Maybe you do web programming in Perl.
continued...
So why do you care?
- I did it in Perl, with Catalyst.
- Maybe you do web programming in Perl.
- Or maybe you want to know why you should do web programming in Perl.
But first, the tools
continued...
But first, the tools
continued...
But first, the tools
continued...
But first, the tools
continued...
But first, the tools
continued...
But first, the tools
- Our website's framework is Catalyst.
- http://catalystframework.org
- MVC web framework for Perl.
- Similar to Rails except you get:
- Maturity!
- CPAN!
- Perl community!
continued...
But first, the tools
- Our website's framework is Catalyst.
- http://catalystframework.org
- MVC web framework for Perl.
- Similar to Rails except you get:
- Maturity!
- CPAN!
- Perl community!
- And crazy flexibility.
What's all this MVC stuff anyway?
- Separates your application into layers:
continued...
What's all this MVC stuff anyway?
- Separates your application into layers:
continued...
What's all this MVC stuff anyway?
- Separates your application into layers:
- Model (Data)
- Controller (Business logic, Main program flow)
continued...
What's all this MVC stuff anyway?
- Separates your application into layers:
- Model (Data)
- Controller (Business logic, Main program flow)
- View (Presentation)
continued...
What's all this MVC stuff anyway?
- Separates your application into layers:
- Model (Data)
- Controller (Business logic, Main program flow)
- View (Presentation)
- Makes your applications easier to maintain.
"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 Wardley
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
continued...
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
continued...
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
continued...
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
continued...
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
- This is a good thing?
- Yes, because it enables lots of nifty things.
continued...
Petal
- Petal is a templating system for Perl.
- One of many views available for Catalyst.
- A clone of Zope's TAL.
- Insists on strict XML/XHTML.
- This is a good thing?
- Yes, because it enables lots of nifty things.
- One of which is Petal::I18N.
My App (finally!)
- We have an ordinary customer website.
- Lots of our customers speak Spanish.
- How do we serve them as well?
continued...
My App (finally!)
- We have an ordinary customer website.
- Lots of our customers speak Spanish.
- How do we serve them as well?
- Duplicate the entire site (sucks)
continued...
My App (finally!)
- We have an ordinary customer website.
- Lots of our customers speak Spanish.
- How do we serve them as well?
- Duplicate the entire site (sucks)
- Duplicate only "presentation" (still sucks)
continued...
My App (finally!)
- We have an ordinary customer website.
- Lots of our customers speak Spanish.
- How do we serve them as well?
- Duplicate the entire site (sucks)
- Duplicate only "presentation" (still sucks)
- Go dynamic (awesome!)
Okay, you got me. How does it work?
- All of our HTML is created in English
- Elements with text that should be translated are "tagged"
<p i18n:translate="">
This text will be translated on the fly!
</p>
continued...
Okay, you got me. How does it work?
- All of our HTML is created in English
- Elements with text that should be translated are "tagged"
<p i18n:translate="">
This text will be translated on the fly!
</p>
- When Petal parses the XML it notices this tag
continued...
Okay, you got me. How does it work?
- All of our HTML is created in English
- Elements with text that should be translated are "tagged"
<p i18n:translate="">
This text will be translated on the fly!
</p>
- When Petal parses the XML it notices this tag
- Then it extracts the strings
continued...
Okay, you got me. How does it work?
- All of our HTML is created in English
- Elements with text that should be translated are "tagged"
<p i18n:translate="">
This text will be translated on the fly!
</p>
- When Petal parses the XML it notices this tag
- Then it extracts the strings
- And looks them up in a database
continued...
Okay, you got me. How does it work?
- All of our HTML is created in English
- Elements with text that should be translated are "tagged"
<p i18n:translate="">
This text will be translated on the fly!
</p>
- When Petal parses the XML it notices this tag
- Then it extracts the strings
- And looks them up in a database
- Which happens to be a GNU Gettext file.
So what did I do?
- Well, not a lot actually.
- Added code to the site to keep track of the user's language.
continued...
So what did I do?
- Well, not a lot actually.
- Added code to the site to keep track of the user's language.
- Loaded images from language-specific directories.
continued...
So what did I do?
- Well, not a lot actually.
- Added code to the site to keep track of the user's language.
- Loaded images from language-specific directories.
- And told our Petal view to use Petal::I18N
So what did I do? (contd.)
- Wrote an application for translators.
- It finds all of the text that's been tagged for translation
- Sorts it out by page
- And shows the translators what needs to be done
continued...
So what did I do? (contd.)
- Wrote an application for translators.
- It finds all of the text that's been tagged for translation
- Sorts it out by page
- And shows the translators what needs to be done
continued...
So what did I do? (contd.)
- Wrote an application for translators.
- It finds all of the text that's been tagged for translation
- Sorts it out by page
- And shows the translators what needs to be done
- And changes are visible live in the testing environment.
So now our site is available in Spanish.
- Bringing translations live requires:
- Commit compiled gettext datbase to source control,
- Add language-specific images to source control,
- And go!
Okay, so what was cool about this?
- Our core app logic didn't change at all.
- Nothing was duplicated.
- I made my employer happy.
- But I didn't do a whole lot of work.
- And I saved a lot more work down the line.
- Now that's Laziness!
Thank you!