Skip to content

Commit

Permalink
New method for retrieving the strings from the store. Fixes #11692
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and wilsonge committed Sep 3, 2016
1 parent d6c8ea8 commit 45164a4
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions libraries/joomla/language/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function _($string, $jsSafe = false, $interpretBackSlashes = true,

if ($script)
{
self::$strings[$string] = $lang->_($string, $jsSafe, $interpretBackSlashes);
static::$strings[$string] = $lang->_($string, $jsSafe, $interpretBackSlashes);

return $string;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ private static function passSprintf(&$string, $jsSafe = false, $interpretBackSla
{
foreach ($string_parts as $i => $str)
{
self::$strings[$str] = $string_parts[$i];
static::$strings[$str] = $string_parts[$i];
}
}

Expand All @@ -155,14 +155,12 @@ private static function passSprintf(&$string, $jsSafe = false, $interpretBackSla
*/
public static function alt($string, $alt, $jsSafe = false, $interpretBackSlashes = true, $script = false)
{
$lang = JFactory::getLanguage();

if ($lang->hasKey($string . '_' . $alt))
if (JFactory::getLanguage()->hasKey($string . '_' . $alt))
{
$string .= '_' . $alt;
}

return self::_($string, $jsSafe, $interpretBackSlashes, $script);
return static::_($string, $jsSafe, $interpretBackSlashes, $script);
}

/**
Expand Down Expand Up @@ -242,7 +240,7 @@ public static function plural($string, $n)

if (array_key_exists('script', $args[$count - 1]) && $args[$count - 1]['script'])
{
self::$strings[$key] = call_user_func_array('sprintf', $args);
static::$strings[$key] = call_user_func_array('sprintf', $args);

return $key;
}
Expand Down Expand Up @@ -296,7 +294,7 @@ public static function sprintf($string)

if (array_key_exists('script', $args[$count - 1]) && $args[$count - 1]['script'])
{
self::$strings[$string] = call_user_func_array('sprintf', $args);
static::$strings[$string] = call_user_func_array('sprintf', $args);

return $string;
}
Expand Down Expand Up @@ -362,6 +360,20 @@ public static function printf($string)
*/
public static function script($string = null, $jsSafe = false, $interpretBackSlashes = true)
{
if ($string === null)
{
JLog::add(
sprintf(
'As of __DEPLOY_VERSION__, passing a null value for the first argument of %1$s() is deprecated and will not be supported in 4.0.'
. ' Use the %2$s::getScriptStrings() method to get the strings from the JavaScript language store instead.',
__METHOD__,
__CLASS__
),
JLog::WARNING,
'deprecated'
);
}

if (is_array($jsSafe))
{
if (array_key_exists('interpretBackSlashes', $jsSafe))
Expand All @@ -383,12 +395,24 @@ public static function script($string = null, $jsSafe = false, $interpretBackSla
if ($string !== null)
{
// Normalize the key and translate the string.
self::$strings[strtoupper($string)] = JFactory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);
static::$strings[strtoupper($string)] = JFactory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);

// Load core.js dependency
JHtml::_('behavior.core');
}

return self::$strings;
return static::getScriptStrings();
}

/**
* Get the strings that have been loaded to the JavaScript language store.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getScriptStrings()
{
return static::$strings;
}
}

0 comments on commit 45164a4

Please sign in to comment.