3

In Joomla 3.9.20, I created a custom front end template. Inside I have the language folder with various languages in this format.

For German (example):

/templates/mytemplate/de-DE/de-DE.tpl_mytemplate.ini

They all work, however for English the strings are not read

/templates/mytemplate/en-GB/en-GB.tpl_mytemplate.ini

I have to put my custom strings inside the language site root folder to make it work. My default language is it-IT.

Is this a bug?

To make things weirder, while using only the language folder inside mytemplate, if I remove a string for another language it defaults back to my custom English strings! So basically it works indirectly when using another language with missing definitions but not directly when in English.

0

1 Answer 1

5
+50

I was not able to duplicate your issue. I used the Joomla core Beez3 template to test this, where the template by default has the language files in main (Joomla root) Language folder and at the same time it has the same language files in the template language folder too.

Now, when a Joomla page is loaded then usually the last call is when the HtmlView loads the particular template:

HtmlView->loadTemplate()

Within this function the language files are loaded also (considering all of the possible/defined language paths of your Joomla application) and this call loads the languages (it is already a very sophisticated system in Joomla, I mean the process that this call pulls in):

// Load the language file for the template
$lang = \JFactory::getLanguage();
$lang->load('tpl_' . $template, JPATH_BASE, null, false, true)
    || $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", null, false, true);

In the above call you can see that the load() method tries to load the language from the main Language folder of Joomla, then from the template's language folder. It also gets obvious from the above two lines that Languages belongs to the main language folder first of all, then the extensions folder. So it looks safe to keep languages in the main language folder. But it is not a must (Joomla has great language debug system too if something goes wrong).

So what was my test to checking your issue?

It is simple: I renamed the beez3 English language files in the main language folder and changed one English language string in the English language file of beez3 template in the template's language folder. And when I loaded the page again the text constant (language constant) value was changed reflected on the page too. It means simply that the English language file was read from the language sub-folder of the template. but when I renamed back the language file in the main language folder then the text was set back on the page automatically.

To test this a little more (as an extra mile), I dumped the application global language object

use \Joomla\CMS\Factory;

$app = Factory::getApplication();
$lang = $app->getLanguage();

and checked the file paths of possible language files. At the case when I renamed the main language file of Beez3, a new path appeared in the language object's paths array; and yes you bet, it was the language path to the beez3 template language folder and English language file.

On the last part of your post about language fallback to English language strings, yes I can confirm that, but the same as above. If the Language object can find English language files for your template in the main language folder, then it will use that first, if not it will load the template language file and fall back to that.

About this function even the documents have some good info:

Another cool trick you can do is** to load arbitrary front-end and back-end language files of any component and language. For example, you may want to load the English language file and mix it with the user's current language. This means that untranslated strings will appear in English and not as untranslated keys. You can use something like this for the back-end language files:

$language = JFactory::getLanguage();
$language->load('com_yourcomponentname', JPATH_ADMINISTRATOR, 'en-GB', true);
$language->load('com_yourcomponentname', JPATH_ADMINISTRATOR, null, true);

And to load the front-end language files, using the same trick:

$language = JFactory::getLanguage();
$language->load('com_yourcomponentname', JPATH_SITE, 'en-GB', true);
$language->load('com_yourcomponentname', JPATH_SITE, null, true);

source: https://docs.joomla.org/Specification_of_language_files

And last but not least, you can also use a helpful Language class function to check whether there is a problematic language file in your system:

$langError = $lang->getErrorFiles();
var_dump($langError);

If I want to answer your main issue, there is something you have to find with your language files if it is not working, as it is given above (I do not have a clue from here why your language file is not read but I am sure it is a very small mistake somewhere)). Even though the language of your site is set to Italian, it-IT for example, the English language files are always loaded in Joomla.

1
  • 1
    The reason was that I was considering the template language folder like an override when it's not, the global language folder will still have priority over everything. So the solution was to delete the /language//en-GB/en-GB.tpl_mytemplate.ini which was only present in English when I created the template from the backend. I'll still give you best answer for the effort and some useful info! Commented Nov 10, 2020 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.