Source for file text.php
Documentation is available at text.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @package Joomla.Platform
protected static $strings =
array();
* Translates a string into the current language.
* <script>alert(Joomla.JText._('<?php echo JText::_("JDEFAULT", array("script"=>true));?>'));</script>
* will generate an alert message containing 'Default'
* <?php echo JText::_("JDEFAULT");?> it will generate a 'Default' string
* @param string $string The string to translate.
* @param mixed $jsSafe Boolean: Make the result javascript safe.
* @param boolean $interpretBackSlashes To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
* @param boolean $script To indicate that the string will be push in the javascript language store
* @return string The translated string or the key is $script is true
public static function _($string, $jsSafe =
false, $interpretBackSlashes =
true, $script =
false)
$interpretBackSlashes = (boolean)
$jsSafe['interpretBackSlashes'];
$script = (boolean)
$jsSafe['script'];
$jsSafe = (boolean)
$jsSafe['jsSafe'];
if (!(strpos($string, ',') ===
false))
foreach ($strs as $i =>
$str)
$strs[$i] =
$lang->_($str, $jsSafe, $interpretBackSlashes);
self::$strings[$str] =
$strs[$i];
$str =
array_shift($strs);
$str =
preg_replace('/\[\[%([0-9]+):[^\]]*\]\]/', '%\1$s', $str);
self::$strings[$string] =
$lang->_($string, $jsSafe, $interpretBackSlashes);
return $lang->_($string, $jsSafe, $interpretBackSlashes);
* Translates a string into the current language.
* <?php echo JText::alt("JALL","language");?> it will generate a 'All' string in English but a "Toutes" string in French
* <?php echo JText::alt("JALL","module");?> it will generate a 'All' string in English but a "Tous" string in French
* @param string $string The string to translate.
* @param string $alt The alternate option for global string
* @param mixed $jsSafe Boolean: Make the result javascript safe.
* @param boolean $interpretBackSlashes To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
* @param boolean $script To indicate that the string will be pushed in the javascript language store
* @return string The translated string or the key if $script is true
public static function alt($string, $alt, $jsSafe =
false, $interpretBackSlashes =
true, $script =
false)
$lang =
JFactory::getLanguage();
if ($lang->hasKey($string .
'_' .
$alt))
return self::_($string .
'_' .
$alt, $jsSafe, $interpretBackSlashes, $script);
return self::_($string, $jsSafe, $interpretBackSlashes, $script);
* Like JText::sprintf but tries to pluralise the string.
* Note that this method can take a mixed number of arguments as for the sprintf function.
* The last argument can take an array of options:
* array('jsSafe'=>boolean, 'interpretBackSlashes'=>boolean, 'script'=>boolean)
* jsSafe is a boolean to generate a javascript safe strings.
* interpretBackSlashes is a boolean to interpret backslashes \\->\, \n->new line, \t->tabulation.
* script is a boolean to indicate that the string will be push in the javascript language store.
* <script>alert(Joomla.JText._('<?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1, array("script"=>true));?>'));</script>
* will generate an alert message containing '1 plugin successfully disabled'
* <?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1);?> it will generate a '1 plugin successfully disabled' string
* @param string $string The format string.
* @param integer $n The number of items
* @return string The translated strings or the key if 'script' is true in the array of options
public static function plural($string, $n)
// Try the key from the language plural potential suffixes
$suffixes =
$lang->getPluralSuffixes((int)
$n);
foreach ($suffixes as $suffix)
$key =
$string .
'_' .
$suffix;
// Not found so revert to the original.
$key, array_key_exists('jsSafe', $args[$count -
1]) ?
$args[$count -
1]['jsSafe'] :
false,
array_key_exists('interpretBackSlashes', $args[$count -
1]) ?
$args[$count -
1]['interpretBackSlashes'] :
true
if (array_key_exists('script', $args[$count -
1]) &&
$args[$count -
1]['script'])
self::$strings[$key] =
call_user_func_array('sprintf', $args);
$args[0] =
$lang->_($key);
// Default to the normal sprintf handling.
$args[0] =
$lang->_($string);
* Passes a string thru a sprintf.
* Note that this method can take a mixed number of arguments as for the sprintf function.
* The last argument can take an array of options:
* array('jsSafe'=>boolean, 'interpretBackSlashes'=>boolean, 'script'=>boolean)
* jsSafe is a boolean to generate a javascript safe strings.
* interpretBackSlashes is a boolean to interpret backslashes \\->\, \n->new line, \t->tabulation.
* script is a boolean to indicate that the string will be push in the javascript language store.
* @param string $string The format string.
* @return string The translated strings or the key if 'script' is true in the array of options.
public static function sprintf($string)
$string, array_key_exists('jsSafe', $args[$count -
1]) ?
$args[$count -
1]['jsSafe'] :
false,
array_key_exists('interpretBackSlashes', $args[$count -
1]) ?
$args[$count -
1]['interpretBackSlashes'] :
true
if (array_key_exists('script', $args[$count -
1]) &&
$args[$count -
1]['script'])
self::$strings[$string] =
call_user_func_array('sprintf', $args);
$args[0] =
$lang->_($string);
$args[0] =
preg_replace('/\[\[%([0-9]+):[^\]]*\]\]/', '%\1$s', $args[0]);
* Passes a string thru an printf.
* Note that this method can take a mixed number of arguments as for the sprintf function.
* @param format $string The format string.
public static function printf($string)
$string, array_key_exists('jsSafe', $args[$count -
1]) ?
$args[$count -
1]['jsSafe'] :
false,
array_key_exists('interpretBackSlashes', $args[$count -
1]) ?
$args[$count -
1]['interpretBackSlashes'] :
true
$args[0] =
$lang->_($string);
* Translate a string into the current language and stores it in the JavaScript language store.
* @param string $string The JText key.
* @param boolean $jsSafe Ensure the output is JavaScript safe.
* @param boolean $interpretBackSlashes Interpret \t and \n.
public static function script($string =
null, $jsSafe =
false, $interpretBackSlashes =
true)
$interpretBackSlashes = (boolean)
$jsSafe['interpretBackSlashes'];
$jsSafe = (boolean)
$jsSafe['jsSafe'];
// Add the string to the array if not null.
// Normalize the key and translate the string.
self::$strings[strtoupper($string)] =
JFactory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);
Documentation generated on Tue, 19 Nov 2013 15:15:41 +0100 by phpDocumentor 1.4.3