2

I have module mod_mymodule and it has the same translations as component com_mycomponent. I don't want to duplicate these same files and use only one file.

I load form from com_mycomponent to mod_mymodule and it has fields with labels like: COM_MYCOMPONENT_TEST. In joomla_root/language/en-EN/en-EN.com_mycomponent.ini I have translation to this.

I want to load joomla_root/language/en-EN/en-EN.com_mycomponent.ini to module. I also tried to add JFactory::getLanguage()->load('com_ritcatalogue'); in mod_mymodule.php. Not working. I also tried to load translations in module manifest file mod_mymodule.xml

<languages folder="language">
    <language tag="en-EN">en-EN/en-EN.com_ritcatalogue.ini</language>
    <language tag="en-EN">en-EN/en-EN.com_ritcatalogue.sys.ini</language>
</languages>

But my module only displays COM_MYCOMPONENT_TEST

5
  • 1
    Did you try docs.joomla.org/Loading_extra_language_files, the example actually is loading component language files in module... Commented Dec 18, 2014 at 10:46
  • Works. I use $lang->getTag() as $language_tag. But what if translation to this language does not exist? It should load en-EN translation. Actually doesn't load anything
    – turson
    Commented Dec 18, 2014 at 10:54
  • 1
    Haven't done it myself, but I think the normal solution was to load the English translation first, and then try to load the current language. If no translation exists, nothing happens. If one exists, it overrides the english strings. Don't know if J!3 has a more sophisticated way to do this... Commented Dec 18, 2014 at 11:00
  • First load en-EN then $lang->getTag(). It loads first translation if there is no the second one. Thank you.
    – turson
    Commented Dec 19, 2014 at 8:21
  • So did you solve your problem? If so you might want to answer your own question using your working code as an example. Commented Dec 19, 2014 at 10:03

1 Answer 1

3

I found a solution:

$lang = JFactory::getLanguage();
$lang->load('com_mycomponent', JPATH_SITE, 'en-GB', true);
$lang->load('com_mycomponent', JPATH_SITE, $lang->getTag(), true);

First we load main translation (in my case it's en-GB), then load active language. If there is no active language translation, Joomla display main translation.

List of language tags: https://community.joomla.org/translations/joomla-3-translations.html

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.