As sites and system grow and scale, the need for internationalization and localization (i18n and L10n respectively) of content becomes a necessary task. There’s not much to it on the surface, you need to be able to serve up the same content in different languages. This includes abstracting out words and phrases of content into variables that can then be populated with the the proper local text. Take for example, this very basic homepage:
This is all well and good (especially the part about not using FrontPage or Dreamweaver ;) but what if someone from Spain that only speaks Spanish comes to your site? Sure, you could expect them to run it through Google Translate, but then you’d draw scrutiny from guys like Justin Davis that know how to take UX seriously.
To solve this quandary, we will need to first create a class that will hold our textual content. We will index the data by some arbitrary variable names as well as the language codes that are are going to support. We will use that we can use when we want to recall the data. First, let’s build out our class with our variables:
Feel free to send corrections if Google Translate didn’t handle that correctly ;) Now that we have our class with the translations, we can update your HTML to utilize it:
That’s all there is to it! Keep in mind this is a very rudimentary example and probably lose maintainability after 10 or so strings. At that point you may want to move the language information off to a database.