i18n and HTML

A brief exploration

The problem

TRhIP is a website developed for the MGH Travel Clinic. It helps travelers prepare for a visit to their doctor before leaving on their journey.

TRhIP is available in multiple languages. I’m going to talk about my current solution to managing these translations and how I got there.

This discussion is about where I currently am with this project. If you have suggestions for ways to make it better, I’m all ears!

The complications

Some things that complicate matters:

  • Synchronization
  • Ages
  • Country names
  • Lists

Solutions

  • Multiple templates
  • Some kind of substitution thing…
  • … leading to Gettext

Multiple templates

The big problem with multiple templates is keeping the templates in sync when the structure changes.

If you're not really dealing with templates with various appearing and disappearing parts, you may be happy to have multiple copies of the same HTML file for serving up. Cf HTTP::AcceptLanguage and the way that Apache handles multiple language files.

Half-way substitution thing

These links are just in case people are interested in my home-rolled PO-like solution.

PO files

A standard part of Gettext. See here for some useful information on the format.

Lots of modules to work with PO files.

I opted for Locale::PO. Sort of.

Locale::Maketext / Locale::TextDomain ?

Locale::Maketext, though touted all over the web and in TPJ13, is problematic (can't easily send to translators that aren't Perl programmers, non-standard).

Locale::TextDomain is often listed as a better solution (or Locale::Maketext::Gettext) as it fits into the Gettext standard.

All suffer from the problem that they’re intended for translating strings within a program, not for templates to be served by the same program in different languages.

Code! (for using)

More code! (for making)

Back to the complications

Looking at our complications, what still remains?

  • Synchronization (fixed by PO and substitution)
  • Ages (fixed by PO and plural forms)
  • Country names (fixed by PO and context)
  • Lists

Lists

In particular, how to handle when people are travelling to multiple countries.

Initially, I used Text::Conjunct, but it doesn’t work well for Arabic and Chinese (spacing issues).

However, the Unicode CLDR has information on how to make an “and” list.

How can we use this information? The Locales module.

Locales

Annoyingly, though, the CLDR (and hence Locales) doesn’t have information for one of our target languages.

Also, I’m already using a ton of memory (each starman instance is using 5% of the server memory).

Locales makes that a lot larger, because of how much stuff it loads into memory.

So, let’s just simplify.

Code!

Questions?

Comments?

Suggestions?

per the talk description, I need to also mention Plack. I will also note HTML::FillInForm, Package::Alias, and Set::Tiny as interesting modules.

Also, if needed, files