MODX is a PHP based, open-source CMS. It has built-in support for backend localization, but doesn’t offer frontend localization out of the box. Lingua is a package known for displaying a lexicon switcher on the frontend. It was made to support multilingual websites.
In this blog, I will illustrate how Lingua works.
There are several extras, or packages, that were developed to provide localization for MODX, the most popular one is Babel. The problem with Babel, is that it requires a context for each language where resources can be duplicated for each.
While this process might be helpful in some cases, it’s lengthy and unmaintainable for large CMSs with many resources and multiple language implementations. In order to estimate how much work is needed to implement translation using contexts, multiply the number of translatable resources in your CMS (resources and Template Variables) by the number of target languages.
Lingua avoids contexts by implementing its own tables for translations. Lingua was based on the translation package, but since translation is still in beta, Lingua has headed in a different direction.
How Lingua Works
If you implement multiple translations of your resources then you will need a language switcher on the frontend.
To be able to use Lingua, you need to:
- Add one setting to your context setting:
modRequest.class => LinguaRequest
- Lingua custom manager page is provided for you to select which languages (translations) will be used.
Lingua has its own set of predefined languages, but you can add any language as needed.
- For the switcher to show up on the frontend, the Lingua.selector has to be used to show lexicon switcher.
- Lingua clones resource content and all defined Template Variables (TVs), but doesn’t support custom TVs created out of the MODX TV database as mentioned in this documentation. So the process is down to providing translation of each resource from CMP.
- Apart from mix ups with contexts, Lingua saves translations in its own Lingua tables, where site content and template variables are translated into targeted languages.
The outlined parts of the illustration above hold the translated values of site content and template variables, so it is very important not to embed translatable elements into chunks or hard code strings in snippets because they will not be translated. Lingua doesn’t support translatable chunks at this time.
MODX globalization and localization can be implemented in several ways, which one best suits you is based on your needs. Lingua comes in handy when it comes to medium to large CMSs that adopt MODX official development best practices.