Skip to content

MODX Globalization Using Lingua

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.

Lingua’s Background

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:

  1. Add one setting to your context setting:
[php] modRequest.class => LinguaRequest
[/php]
  1. Lingua custom manager page is provided for you to select which languages (translations) will be used.

MODX Globalization Using Lingua - 1

Lingua has its own set of predefined languages, but you can add any language as needed.

  1. For the switcher to show up on the frontend, the Lingua.selector has to be used to show lexicon switcher.

MODX Globalization Using Lingua - 2

  1. 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.

MODX Globalization Using Lingua - 3

  1. 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.

MODX Globalization Using Lingua - 4

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.

Conclusion

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.