You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MOD_EXAMPLE_ARGS_EXAMPLE="Trying to use %s inside JavaScript"
Text::sprintf("MOD_EXAMPLE_ARGS_EXAMPLE", 12, array("script" => true));
// The last argument can take an array of options // [...] array('jsSafe'=>boolean, 'interpretBackSlashes'=>boolean, 'script'=>boolean) // [...] script is a boolean to indicate that the string will be push in the javascript language store.// See description of the Text::sprintf method$registeredStrings = Text::getScriptStrings();
// Output the array for debugging or custom processing >> all fine here the "MOD_EXAMPLE_ARGS_EXAMPLE" is listed.echo'<pre>' . var_export($registeredStrings, true) . '</pre>';
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->addInlineScript(" console.log(Joomla.Text) // not listed here const message = Joomla.Text._('MOD_EXAMPLE_ARGS_EXAMPLE') console.log(message) // results in printing out the constant")
Expected result
To pass a translation including a variable from PHP to JS.
Actual result
Language Constant is printed in console.
System information (as much as possible)
Joomla 5.2.2
Additional comments
I am currently working on the documentation and stumbled across this when I wanted to explain the use of the options based on the method description. To be honest, I read about this for the first time when researching the topic and I'm not quite sure whether this functionality still exists at all? It would make sense and based on the method description it would still exist - at least on the php side everything still works - the constant incl. variable is transferred to the array when queried with Text::getScriptStrings();. I would also like to document this in detail, as it is a good way to at least output php variables in translations that are used in JS.
The text was updated successfully, but these errors were encountered:
Steps to reproduce the issue
Create a language constant in an example project:
Expected result
To pass a translation including a variable from PHP to JS.
Actual result
Language Constant is printed in console.
System information (as much as possible)
Joomla 5.2.2
Additional comments
I am currently working on the documentation and stumbled across this when I wanted to explain the use of the options based on the method description. To be honest, I read about this for the first time when researching the topic and I'm not quite sure whether this functionality still exists at all? It would make sense and based on the method description it would still exist - at least on the php side everything still works - the constant incl. variable is transferred to the array when queried with
Text::getScriptStrings();
. I would also like to document this in detail, as it is a good way to at least output php variables in translations that are used in JS.The text was updated successfully, but these errors were encountered: