Language overrides in Joomla

Possibly one of the most common modifications made in modules and templates are language changes; Joomla includes support for multilingual sites right out of the box so it’s a great choice if your audience speaks a range of languages. Usually adding custom own text to a module or template involves making changes in their core language files. However, this method has some disadvantages; modifications can be lost after an update due to the language file being overwritten, and users who aren’t familiar with modifying language files may inadvertently use the wrong character encoding, causing all strings to display their default values or even the constant names.

Fortunately, Joomla already has an alternative solution built-in, and not only is it protected from overwriting from updates, but we don’t even need to leave the Joomla backend to make the changes!

The Language Override Joomla Feature

This alternative method is known as Language Overrides, and it’s available via the Language Manager in Joomla, and it will allow us to override language constants. Any Joomla user who’s modified a language file will know about constants, but if you’re fairly new to Joomla it might seem a bit confusing at first. Essentially, Joomla uses constants to store language strings; think of constants as placeholder labels that can be replaced with our own text. For example, the value of the COM_CONTENT_ARTICLE_HITS constant defines the text of the Hits label that’s seen on a basic Joomla article. By changing the value, we can change the text.

Adding a new override

To add a new override, open the manager by clicking on Extensions → Language Manager in the Joomla admin area main menu; here we can install new languages, set which language is installed in the frontend and backend of our Joomla installation, and edit core language details such as language tags, or custom site names. What we’re interested in though is the fourth option in the left menu, Overrides, which takes us to a page listing all of our current language overrides. In other words, it’s blank.

The first thing to do here is make sure that we are modifying the correct language; Joomla separates each languages overrides into their own file, so you may only view or modify one language’s overrides at a time. Which language you are modifying is defined by the Filter option in the left sidebar, where you can choose between modifying the frontend or backend of each installed language. So, if we want to modify constants that appear on our UK English website, such as the Article Hits or Read More texts, then we’ll select English (en-GB) – Site from the list.

Joomla language verrides manager

With the language selected, a quick click on the New button at the top of the screen will open the Edit Override page. This is where all the interesting modifications take place:

Creating new Joomla override

Next, we can enter the name of the constant we want to change, such as COM_CONTENT_ARTICLE_HITS, in the Language Constant field, then add the new label we want to use for this constant in the Text field:

Joomla language overrides

With that done, we can save the changes; now on the list of overrides we’ll see our new entry so we can modify again later if needed. These overrides are safe from being accidentally overwritten by updates as they are stored in their own file separate from the main language file; if the string we’re modifying is from the en-GB language file, then our modifications will be added to language/overrides/en-GB.override.ini.

Searching for Constant Strings

There is still one little issue with the method described above; how do we know what the name of a constant is? Each module, extension or template can have several unique constants, and the naming convention might not always be easy to decipher. Thankfully, the Edit Overrides page also includes a search function to make locating a constant’s name easy. The search bar is located on the right-hand side of the Edit Overrides page:

Editing Joomla override

By changing the Search For option, we can search for the name of a constant, or search for its value; that is, the text that is outputs:

Search language phrase in Joomla

For example, in many of our templates we have a string, “Leave a Comment”, that appears at the bottom of the page on a single K2 article, above the comments section. If you wanted to override this text, then you can enter the text of the string, “Leave a comment”, in the search bar, and it will return any constants with that string as a value, making it easy to find that the constant containing this string is K2_LEAVE_A_COMMENT. A useful thing about these searches is that as well as accurate results it will also return results that are similar to a given string, so you don’t need to have exact knowledge of the constant or content string to find what you need:

Joomla search results

And there’s a nice little feature to speed up changes; by clicking on a specific item in the list of search results it will automatically fill the Edit Override constant and text form fields, saving a few precious seconds!

Additional tips

This method of overriding text, and the core mechanics of its functionality, may be used is some additional ways:

  1. If we want to modify a large number of our stored overrides quickly, then instead of doing it via the admin panel we can modify the file containing the overrides just like a standard language file. As mentioned earlier, all overrides are stored in their respective language override file, located in language/overrides/.LANG_CODE.override.ini, where LANG_CODE is the language code i.e. en-GB, pl-PL, de-DE etc…
  2. Since we may override strings for both the frontend and backend, there’s nothing stopping us from modifying the admin panel’s labels to make them more intuitive for us or our clients.

Summary

The language override feature is another reason why Joomla is a great choice for people looking to create a full-featured multilingual website, and a huge benefit for Joomla users, who can store their language modifications safely and conveniently modify content directly in the admin panel. For this reason we recommend that users of our template and modules take advantage of it to easily modify strings and protect their content from being overwritten by updates.

Language overrides in Joomla 4.715 (94.29%) 14 votes
Share
This article was first published October 14th, 2015