I want to return a JText value from my helper.php file from my own module.
class modMyFormularHelper
{
public static function getValue()
{
$test = JText::_('MOD_MYFORMULAR_VALUE');
return $test;
}
For this I have a "de-DE.mod_myformular.ini" in the language folder. The problem is I only get MOD_MYFORMULAR_VALUE in the Frontend.
If I write the JText in the default.php from the tmpl-folder... This works fine!
So how can I get the language strings in the helper file? Thanks
You have two options. The first you already know, which is to migrate the JText::_(); method to the default.php file. The second is to manually load the language file inside the getValue() method like so:
JFactory::getLanguage()->load('mod_myformular', $basePath);
Although not required, you might need to set the second $basePath if the needed language file is in the back-end.
For this instance however, Since you are not performing any CRUD operations and as is the getValue() method will always return the same value; it makes more sense to simply render the language translation text inside your default.php file.
Just a precision to complete this good answer : it works if your language file is in the default language folder (/yourSite/language/).
But if you want to load the language files of your custom module, you'll have to help Joomla like this :
JFactory::getLanguage()->load('mod_myformular', JPATH_SITE.'/modules/mod_myformular');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.