Selecting the Language Used by an Extra

Several methods for seeing the language you prefer in a MODX extra


In this article, we'll look at a trick for selecting the language used by a MODX extra package.

MODX logo

Preferred Language

Most extras have lexicon files for different languages, and will use a System Setting like manager_language as a default but what if there's no file for your language? If there's no language file for your preferred language, and you select that language in the extra's properties, the MODX lexicon class will give you English, but maybe that's not what you'd prefer. There are several solutions you can use to see the lexicon strings in your preferred language.


Creating a Language File

The most helpful solution is to create your own translation in your preferred language and submit it to the author of the extra. You can simply create a directory named for the two-letter language code for your language in the core/components/componentname/lexicon/ directory. Copy the language file(s) from the language nearby that you're most comfortable with into that directory and translate the strings. Be careful not to delete any of the quotation marks around the language strings or the semicolon at the end of each line. If you do, you'll get a PHP error when your language is loaded.

This method takes some work, but you'll get the satisfaction of knowing you've contributed to MODX.


Lexicon Management

If there aren't very many strings you need to translate, you can find the lexicon strings for an extra by going to System (gear icon) Lexicons. Select the namespace of the extra (almost always a lowercase version of the extra's name) in the input field at the top of the grid. Double-click on the value field and edit the lexicon strings. This method will survive any updates to MODX or the extra. When you're finished, check the topic input file (next to the namespace field) to see if there are other language topics used by the extra. If so, edit those strings too.


Tricking MODX into Delivering Another Language

Let's say that your native language is French but there are no French language files. Since you live in Alsace-Lorraine, you prefer German over English. You don't want to change the manager language from French to German because French is your first choice, but you'd like to see the extra's messages in German rather then English (and the extra *does* have German lexicon files).

You can often change the language used by an extra by changing the language property of a snippet or plugin, but that may not affect messages in the chunks or template used. It can also be undone if you change a default property and then upgrade the extra. If the extra has a language property, you can create a property set or put the language property in the snippet tag, but if there are multiple snippets or a plugin, that's kind of a hassle.

Here's another way that will make a permanent change. In this case the manager language is fr, so you see the Manager's messages in French, but not those of the extra.

Go to core/components/componentName/lexicon/ (where componentName is the name of the extra).

Create a fr (lowercase) directory under the lexicon/ directory. Copy any files you find in the de directory to the fr directory. Now MODX will serve those German lexicon strings thinking that they are French.


Coming Up

In the next article, will see the first of a series of articles on passing data between two snippets.



Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)



Comments (0)


Please login to comment.

  (Login)