Actions

API15

JLanguage/

From Joomla! Documentation

< API15:JLanguage
Revision as of 12:38, 25 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Translate function, mimics the php gettext (alias _) function

[Edit Descripton]

Description:JLanguage/

Syntax

_($string, $jsSafe=false)
Parameter Name Default Value Description
$string $string The string to translate
$jsSafe false $jsSafe Make the result javascript safe

Returns

string The translation of the string

Defined in

libraries/joomla/language/language.php

Importing

jimport( 'joomla.language.language' );

Source Body

function _($string, $jsSafe = false)
{
        //$key = str_replace( ' ', '_', strtoupper( trim( $string ) ) );echo '<br />'.$key;
        $key = strtoupper($string);
        $key = substr($key, 0, 1) == '_' ? substr($key, 1) : $key;
 
        if (isset ($this->_strings[$key]))
        {
                $string = $this->_debug ? "&bull;".$this->_strings[$key]."&bull;" : $this->_strings[$key];
 
                // Store debug information
                if ( $this->_debug )
                {
                        $caller = $this->_getCallerInfo();
 
                        if ( ! array_key_exists($key, $this->_used ) ) {
                                $this->_used[$key] = array();
                        }
 
                        $this->_used[$key][] = $caller;
                }
 
        }
        else
        {
                if (defined($string))
                {
                        $string = $this->_debug ? '!!'.constant($string).'!!' : constant($string);
 
                        // Store debug information
                        if ( $this->_debug )
                        {
                                $caller = $this->_getCallerInfo();
 
                                if ( ! array_key_exists($key, $this->_used ) ) {
                                        $this->_used[$key] = array();
                                }
 
                                $this->_used[$key][] = $caller;
                        }
                }
                else
                {
                        if ($this->_debug)
                        {
                                $caller = $this->_getCallerInfo();
                                $caller['string'] = $string;
 
                                if ( ! array_key_exists($key, $this->_orphans ) ) {
                                        $this->_orphans[$key] = array();
                                }
 
                                $this->_orphans[$key][] = $caller;
 
                                $string = '??'.$string.'??';
                        }
                }
        }
 
        if ($jsSafe) {
                $string = addslashes($string);
        }
 
        return $string;
}

[Edit See Also] SeeAlso:JLanguage/

Examples

<CodeExamplesForm />