Source code for file /joomla/i18n/language.php
Documentation is available at language.php
* @version $Id: language.php 6762 2007-03-03 08:37:41Z tcp $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 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
* @package Joomla.Framework
* Translates a string into the current language
* @param string $string The string to translate
* @param boolean $jsSafe Make the result javascript safe
function _($string, $jsSafe =
false)
return $lang->_($string, $jsSafe);
* Passes a string thru an sprintf
* @param format The format string
* @param mixed Mixed number of arguments for the sprintf function
$args[0] =
$lang->_($args[0]);
* Passes a string thru an printf
* @param format The format string
* @param mixed Mixed number of arguments for the sprintf function
$args[0] =
$lang->_($args[0]);
* 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
* Identifying string of the language
* 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;
* Translator 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;
$string =
"??".
$string.
"??";
* 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
* @return boolean True if the language exists
static $languages =
array();
// Return false if no language was specified
// Return previous check results if it exists
if ( isset
($languages[$lang]) )
return $languages[$lang];
// Check if the language exists
jimport('joomla.filesystem.folder');
return $languages[$lang];
* Loads a single language file and appends the results to the existing strings
* @param string $prefix The prefix
* @param string $basePath The basepath to use
* @return boolean True, if the file has successfully loaded.
function load( $prefix =
'', $basePath =
JPATH_BASE )
$filename =
empty( $prefix ) ?
$this->_lang :
$this->_lang .
'.' .
$prefix ;
$filename =
$path.
DS.
$filename.
'.ini';
if (isset
( $paths[$filename] ))
// Strings for this file have already been loaded
// Load the language file
$newStrings =
$this->_load( $filename );
// Check if there was a problem with loading the file
if ( $newStrings ===
false ) {
// No strings, which probably means that the language file does not exist
$filename =
empty( $prefix ) ?
$this->_default :
$this->_default .
'.' .
$prefix ;
$filename =
$path.
DS.
$filename.
'.ini';
$newStrings =
$this->_load( $filename );
// Merge the new strings into the strings array
$paths[$filename] =
true;
* Loads a language file and returns the parsed values
* @param string The name of the file
* @return mixed Array of parsed values if successful, boolean False if failed
function _load( $filename )
$registry->loadINI($content);
return $registry->toArray( );
* 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)
* @param string $value An optional value
* @return string Official name element of the language
* 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
function isRTL($value =
null) {
* @return boolean True is in debug mode
* Get the default language code
* @return string Language code
* Set the default language code
* Get the list of orphaned strings if being tracked
* @return boolean True is in debug mode
* 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
//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 INI type of files for language information
* @param string $dir Directory of files
* @return array Array holding the found languages as filename => real name pairs
jimport('joomla.filesystem.folder');
foreach ($files as $file) {
$langContent =
JParameter::parse($content, false, true);
if (isset
($langContent['__NAME'])) {
$name =
$langContent['__NAME'];
$languages[$lang] =
$name;
* 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->loadFile($path)) {
// Check that it's am metadata file
if ($xml->document->name() !=
'metafile') {
//if ($xml->document->attributes('type') == 'language') {
foreach ($xml->document->metadata[0]->children() as $child) {
$metadata[$child->name()] =
$child->data();
* @package Joomla.Framework
* Builds a list of the system languages which can be used in a select option
* @param string Client key for the area
* @param string Base path to use
* @param array An array of arrays ( text, value, selected )
$langs =
$cache->call('JLanguage::getKnownLanguages', $basePath);
foreach ($langs as $lang =>
$metadata) {
$option['text'] =
$metadata['name'];
$option['value'] =
$lang;
if ($lang ==
$actualLanguage) {
$option['selected'] =
'selected="selected"';
* Tries to detect the language
if (isset
($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$browserLangs =
explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
foreach ($browserLangs as $browserLang)
// slice out the part before ; on first step, the part before - on second, place into array
$browserLang =
substr( $browserLang, 0, strcspn( $browserLang, ';' ) );
$primary_browserLang =
substr( $browserLang, 0, 2 );
foreach($systemLangs as $systemLang =>
$metadata)
if($primary_browserLang ==
substr( $metadata['tag'], 0, 2 )) {