Lessons from EAF

2. Handle multiple languages

When we built the ElseApps Framework we learnt a lot of lessons. This series of short articles discusses some of the key learnings from our framework development. I’m sure most of them will be lessons other developers have already learnt, but many of them weren’t in our vocabulary when we started into the project.

fw_stringeditorHaving worked on projects which attempted to retrofit multi-language handling, we decided it was sensible to incorporate this at the outset. In most of the multi-language projects we’ve been part of, text strings are stored in language files which are edited externally to the website: we decided it would be more user-friendly to provide editing within the web application itself.

Our PHP toolset was a willing partner in this exercise: Fat Free Framework provides a robust mechanism for loading language files, and we built our functionality on top of this. Fat Free – or F3 as it’s known – also allows nesting of language strings and supports the ICU project, which provides internationalisation of formats such as dates and times.

fw_emaileditorWe elected to store all our language resources in the database, which made integrated editing of text strings and email bodies straightforward. Clients love this feature, as it allows them to tweak all the displayed content within the framework, even if they’re only using a single language.

After editing, the framework compares the most recent timestamp in the language tables with a saved value from the previous rebuild and, if the former is greater than the latter, rebuilds the language resource for F3 to load. We expected this to be an expensive operation, but it turns out to be a trivial one-off performance hit.

fw_languageconfigurationWe also built in bulk load functionality so that a new language can readily be added by populating a spreadsheet from a resource such as Google Translate. Setting up to add a new language? That’s as easy as appending an additional value on the web application’s configuration page. In practice, it’s all quite seamless.

fw_languageselectorA first-time user’s initial language is based on locale, but alternatives can be selected from the index page and, once an account’s created, edited in the user’s preferences.

If a required phrase has not yet been translated into the user’s preferred language, the corresponding phrase in the website’s base language will be served up as a default when the page is rendered.

EAF’s multi-language handling has worked out well for us. In the next Lesson from EAF we’ll talk about why and how we chose to compile the framework’s styles and scripts.

Lessons from EAFF: 1 2 3 4 5 6 7 8