Source code for file /joomla/language/language.php
Documentation is available at language.php
* @version $Id: language.php 13297 2009-10-24 01:29:37Z ian $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Languages/translation handler class
* @package Joomla.Framework
* Debug language, If true, highlights if string isn't found
* The default language is used when a language file in the requested language does not exist.
* An array of orphaned text
* Array holding the language metadata
* List of language files that have been loaded
* An array of used text, used during debugging
* Constructor activating the default information of the language
* Returns a reference to a language object
* This method must be invoked as:
* <pre> $browser = &JLanguage::getInstance([$lang);</pre>
* @param string $lang The language to use.
* @return JLanguage The Language object.
$reference =
& $instance;
* Translate function, mimics the php gettext (alias _) function
* @param string $string The string to translate
* @param boolean $jsSafe Make the result javascript safe
* @return string The translation of the string
function _($string, $jsSafe =
false)
//$key = str_replace( ' ', '_', strtoupper( trim( $string ) ) );echo '<br />'.$key;
// Store debug information
$caller =
$this->_getCallerInfo();
$this->_used[$key] =
array();
$this->_used[$key][] =
$caller;
// Store debug information
$caller =
$this->_getCallerInfo();
$this->_used[$key] =
array();
$this->_used[$key][] =
$caller;
$caller =
$this->_getCallerInfo();
$caller['string'] =
$string;
$string =
'??'.
$string.
'??';
* This method processes a string and replaces all accented UTF-8 characters by unaccented
* @param string $string The string to transliterate
* @return string The transliteration of the string
array('/ß/','/&(..)lig;/', '/&([aouAOU])uml;/','/&(.)[^;]*;/'),
array('ss',"$1","$1".
'e',"$1"),
* Check if a language exists
* This is a simple, quick check for the directory that should contain language files for the given user.
* @param string $lang Language to check
* @param string $basePath Optional path to check
* @return boolean True if the language exists
function exists($lang, $basePath =
JPATH_BASE)
// Return false if no language was specified
$path =
$basePath.
DS.
'language'.
DS.
$lang;
// Return previous check results if it exists
if ( isset
($paths[$path]) )
// Check if the language exists
jimport('joomla.filesystem.folder');
* Loads a single language file and appends the results to the existing strings
* @param string $extension The extension for which a language file should be loaded
* @param string $basePath The basepath to use
* @param string $lang The language to load, default null for the current language
* @param boolean $reload Flag that will force a language to be reloaded if set to true
* @return boolean True, if the file has successfully loaded.
function load( $extension =
'joomla', $basePath =
JPATH_BASE, $lang =
null, $reload =
false )
if ( !strlen( $extension ) ) {
$filename =
( $extension ==
'joomla' ) ?
$lang :
$lang .
'.' .
$extension ;
$filename =
$path.
DS.
$filename.
'.ini';
if (isset
( $this->_paths[$extension][$filename] ) &&
! $reload )
// Strings for this file have already been loaded
// Load the language file
$result =
$this->_load( $filename, $extension );
// Check if there was a problem with loading the file
// No strings, which probably means that the language file does not exist
$filename =
( $extension ==
'joomla' ) ?
$this->_default :
$this->_default .
'.' .
$extension ;
$filename =
$path.
DS.
$filename.
'.ini';
$result =
$this->_load( $filename, $extension, false );
* This method will not note the successful loading of a file - use load() instead
* @param string The name of the file
* @param string The name of the extension
* @return boolean True if new strings have been added to the language
function _load( $filename, $extension =
'unknown', $overwrite =
true )
//Take off BOM if present in the ini file
if ( $content[0] ==
"\xEF" &&
$content[1] ==
"\xBB" &&
$content[2] ==
"\xBF" )
$content =
substr( $content, 3 );
$registry->loadINI($content);
$newStrings =
$registry->toArray( );
// Record the result of loading the extension's file.
if ( ! isset
($this->_paths[$extension])) {
$this->_paths[$extension] =
array();
$this->_paths[$extension][$filename] =
$result;
* Get a matadata language property
* @param string $property The name of the property
* @param mixed $default The default value
* @return mixed The value of the property
function get($property, $default =
null)
* Determine who called JLanguage or JText
* @return array Caller information
function _getCallerInfo()
// Try to determine the source if none was provided
// Search through the backtrace to our caller
while ($continue &&
next($backtrace))
$class =
@ $step['class'];
// We're looking for something outside of language.php
if ($class !=
'JLanguage' &&
$class !=
'JText') {
$info['function'] =
@ $step['function'];
$info['step'] =
prev($backtrace);
// Determine the file and name of the file
$info['file'] =
@ $step['file'];
$info['line'] =
@ $step['line'];
* @return string Official name element of the language
* Get a list of language files that have been loaded
* @param string $extension An option extension name
if ( isset
($this->_paths[$extension]) )
return $this->_paths[$extension];
* Getter for PDF Font Name
* @return string name of pdf font to be used
* Getter for Windows locale code page
* @return string windows locale encoding
* Getter for backward compatible language name
* @return string backward compatible name
* Get for the language tag (as defined in RFC 3066)
* @return string The language tag
* @return string The locale property
for($i =
0; $i <
count($locales); $i++
) {
//return implode(',', $locales);
* @return boolean True is it an RTL language
* @return boolean Previous value
* @return boolean True is in debug mode
* Get the default language code
* @return string Language code
* Set the default language code
* @return string Previous value
* Get the list of orphaned strings if being tracked
* @return array Orphaned text
* Get the list of used strings
* Used strings are those strings requested and found either as a string or a constant
* @return array Used strings
* Determines is a key exists
* @param key $key The key to check
* @return boolean True, if the key exists
* Returns a associative array holding the metadata
* @param string The name of the language
* @return mixed If $lang exists return key/value pair with the language metadata,
* Returns a list of known languages for an area
* @param string $basePath The basepath to use
* @return array key/value pair with the language file and real name
* Get the path to a language
* @param string $basePath The basepath to use
* @param string $language The language tag
* @return string language related path or null
$dir =
$basePath.
DS.
'language';
* Set the language attributes to the given language
* Once called, the language still needs to be loaded using JLanguage::load()
* @param string $lang Language code
* @return string Previous value
$previous =
$this->_lang;
//set locale based on the language tag
//TODO : add function to display locale setting in configuration
* Searches for language directories within a certain base dir
* @param string $dir directory of files
* @return array Array holding the found languages as filename => real name pairs
jimport('joomla.filesystem.folder');
foreach ($subdirs as $path) {
* Parses XML files for language information
* @param string $dir Directory of files
* @return array Array holding the found languages as filename => metadata array
jimport('joomla.filesystem.folder');
foreach ($files as $file) {
$languages[$lang] =
$metadata;
* Parse XML file for language information
* @param string $path Path to the xml files
* @return array Array holding the found metadata as a key => value pair
if (!$xml ||
!$xml->loadFile($path)) {
// Check that it's am metadata file
if (!$xml->document ||
$xml->document->name() !=
'metafile') {
//if ($xml->document->attributes('type') == 'language') {
foreach ($xml->document->metadata[0]->children() as $child) {
$metadata[$child->name()] =
$child->data();