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.
1 Answer
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");
-
Thank you very much because I was actually doing some sort of work around without knowing I could use this. May 30, 2020 at 10:30
-
1Installing 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.– SharkyMay 31, 2020 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. Jun 1, 2020 at 13:06
-
1Sorry, 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.– SharkyJun 1, 2020 at 14:22
-
Thank you both of you. The first solution Robbie prposed is working nicely anyway. Thank you once again. Jun 1, 2020 at 15:25