3

How can i create a language constant instead of a classic text?

I tried it so:

$langConstant = strtoupper(str_replace (' ', '', $this->fieldsClass->getFieldName($oneExtraField)));
$langConstant = str_replace('-', '', $langConstant);

I try to reproduce my content from override file so, but i see only constant code:

echo JText::_("TPL_CTM_F_$langConstant");
or
echo JText::_("TPL_CTM_F_" . $langConstant);

How can i reproduce it as language constant?

6

The Language constant that youre trying to build will work if the final, full constant is defined in your language file. In other words, if you set $langConstant = 'XYZ', then TPL_CTM_F_XYZ must exist in the language file that you are using.

All of these will work, (knowing that JYES and JNO are found in a language file)

echo JText::_("JYES");
echo JText::_("JNO");

$variable = 'JYES';
echo JText::_($variable);

$yes = strtoupper('yes');
$constructed = 'J'.$yes;
echo JText::_($constructed);

echo JText::_('J'.strtoupper('yes'));

You define Language strings in the language folder of your component. These are typically located in \language\en-GB from the root of your site, or within the components folder (where 'en-GB' is your language). That language file is loaded with your component and the rest is taken care of by Joomla.

See Creating a Language File and Specification of Language Files. If you need a language string from other than your component, see how to do at Loading Extra Language Files.

Additionally, in the Administrator, you can add and maintain language strings using the Language Manager.

| improve this answer | |

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.