Currently, to translate any Javascript string, we use the combination of JText::script()
in PHP and Joomla.JText._()
in Javascript. However, it's common that we may want to include multiple strings to translate in Javascript. Currently, to do that, you have to write:
$language_strings = array('COM_EXAMPLE_STRING', 'COM_EXAMPLE_ANOTHER_STRING');
foreach($language_strings as $string) {
JText::script($string);
}
This could be easily simplified to this:
$language_strings = array('COM_EXAMPLE_STRING', 'COM_EXAMPLE_ANOTHER_STRING');
JText::script($language_strings);
This could be avoided, if the script function allowed arrays as input. A simple if (is_array($string))
and a loop could do this.
@dgrammatiko I intentionally omitted the other arguments, because providing an array of arrays doesn't necessarily simplify the input. Instead, you could just call the JText::script()
function with an array of strings and have the other two parameters apply for the whole array. That makes sense, because if you want some strings to have jsSafe: true
and others to have jsSafe: false
, you can just call JText::script()
once for every different set of strings.
Is it possible to do something simple like
function script($string, ...) {
if(is_array($string)) {
array_map($string, script);
}
}
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-12-20 13:50:58 |
Closed_By | ⇒ | rdeutz |
The proposed solution is half baked as the API has 3 arguments and the proposed one is ignoring the last 2. But it could be like:
My 2c