0

I'm creating a module but I need it to be multilingual. I know that I can create field params, duplicate the module, and set different values for these params based on the languague but I would like to know if there's any way to use Language Constant like we do with components.

3

Yes, you set them up in a similar way to components.

In your module directory create a folder language, and then a subfolder for the language within that, and into that subfolder put your language INI file(s). If your module is called mod_example then:

Inside language/en-GB/en-GB.mod_example.ini put

MOD_EXAMPLE_ONE="one"

Inside language/es-ES/es-ES.mod_example.ini put

MOD_EXAMPLE_ONE="uno"

Inside your module xml file include the language folder within a <languages> section (updated from within a <files> section based on the comment from Sharky below):

<languages folder="language">
    <language tag="en-GB">en-GB/en-GB.mod_example.ini</language>
    <language tag="es-ES">es-ES/es-ES.mod_example.ini</language>
</languages>

Then in your module you can use language strings in the usual way:

echo JText::_("MOD_EXAMPLE_ONE");
| improve this answer | |
  • Thank you very much because I was actually doing some sort of work around without knowing I could use this. – Thiago Guimarães May 30 at 10:30
  • 1
    Installing language files to extension directory (using <files> tag) is the old and not recommended way. It breaks on multilingual sites. Language files should be installed to global language directory using <languages> tag. – Sharky May 31 at 21:02
  • 1
    @Sharky thanks for the advice - I've updated the answer accordingly. Is there a Joomla document which I can reference which says that the old way is deprecated? I tried it on my own multilingual site and it worked ok. – Robbie Jackson Jun 1 at 13:06
  • 1
    Sorry, I might have misled you. This works fine with modules. Looks like the issue is specific to libraries (joomla.stackexchange.com/q/26486/12652). Though I would still recommend using the global language folder since that's the first place Joomla! looks in. – Sharky Jun 1 at 14:22
  • Thank you both of you. The first solution Robbie prposed is working nicely anyway. Thank you once again. – Thiago Guimarães Jun 1 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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