One of the holy grails of web development is internationalization (usually shortened to i18n), especially as the industry matures and needs to cover several different markets and countries. Often you would like to have the same website translated into different languages, and that’s the subject of this chapter.
So while this is a pretty simple objective, we do face some challenges on how to properly design the architecture of your web application while using Smarty. We have two different types of requirements for this:
We will go over the first requirement over the next few sections. You should be able to extend it pretty easily to be able to override any of the default translated templates with a customized one later on.
The gold standard for the i18n community, as far as UNIX (and consequently PHP) is concerned, is the use of the Gettext project. This is a set of GNU tools designed to help translate text strings on the fly, from one language to another.
Gettext works by extracting text strings from source code files, and storing them into message catalogs. These catalog files are stored into a directory structure that is standardized, and the translated string is looked up at run time. If the translated text string is not found, or doesn’t have a translation available yet, the original one will be used instead.
So here’s an overview of the workflow:
messages.po
by default.messages.po
file to translate the text strings into another language.messages.po
into a binary file, called messages.mo
by default, that the Gettext extension will understand and use.We will go over the details of using Gettext with PHP over the next few sections.
18.191.88.249