📄 language.php
字号:
return null; } else { return $this->_paths; } }
/**
* Getter for PDF Font Name
*
* @access public
* @return string name of pdf font to be used * @since 1.5
*/
function getPdfFontName() {
return $this->_metadata['pdffontname'];
}
/**
* Getter for Windows locale code page
*
* @access public
* @return string windows locale encoding * @since 1.5
*/
function getWinCP() {
return $this->_metadata['wincodepage'];
}
/**
* Getter for backward compatible language name
*
* @access public
* @return string backward compatible name * @since 1.5
*/
function getBackwardLang() {
return $this->_metadata['backwardlang'];
}
/**
* Get for the language tag (as defined in RFC 3066)
*
* @access public
* @return string The language tag * @since 1.5
*/
function getTag() {
return $this->_metadata['tag'];
}
/**
* Get locale property
*
* @access public
* @return string The locale property * @since 1.5
*/
function getLocale()
{
$locales = explode(',', $this->_metadata['locale']);
for($i = 0; $i < count($locales); $i++ ) {
$locale = $locales[$i];
$locale = trim($locale);
$locales[$i] = $locale;
}
//return implode(',', $locales);
return $locales;
}
/**
* Get the RTL property
*
* @access public
* @return boolean True is it an RTL language * @since 1.5
*/
function isRTL() {
return $this->_metadata['rtl'];
}
/**
* Set the Debug property
*
* @access public * @return boolean Previous value * @since 1.5
*/
function setDebug($debug) { $previous = $this->_debug;
$this->_debug = $debug; return $previous;
}
/**
* Get the Debug property
*
* @access public
* @return boolean True is in debug mode * @since 1.5
*/
function getDebug() {
return $this->_debug;
} /** * Get the default language code * * @access public * @return string Language code * @since 1.5 */ function getDefault() { return $this->_default; } /** * Set the default language code * * @access public * @return string Previous value * @since 1.5 */ function setDefault($lang) { $previous = $this->_default; $this->_default = $lang; return $previous; }
/**
* Get the list of orphaned strings if being tracked
*
* @access public
* @return boolean True is in debug mode * @since 1.5
*/
function getOrphans() {
return $this->_orphans;
} /** * Get the list of used strings * * Used strings are those strings requested and found either as a string or a constant * * @access public * @return array Used strings * @since 1.5 */ function getUsed() { return $this->_used; }
/**
* Determines is a key exists
*
* @access public
* @param key $key The key to check
* @return boolean True, if the key exists * @since 1.5
*/
function hasKey($key) {
return isset ($this->_strings[strtoupper($key)]);
}
/**
* Returns a associative array holding the metadata
*
* @access public
* @param string The name of the language
* @return mixed If $lang exists return key/value pair with the language metadata,
* otherwise return NULL * @since 1.5
*/
function getMetadata($lang)
{
$path = JLanguage::getLanguagePath(JPATH_BASE, $lang);
$file = $lang.'.xml';
$result = null;
if(is_file($path.DS.$file)) {
$result = JLanguage::_parseXMLLanguageFile($path.DS.$file);
}
return $result;
}
/**
* Returns a list of known languages for an area
*
* @access public
* @param string $basePath The basepath to use
* @return array key/value pair with the language file and real name * @since 1.5
*/
function getKnownLanguages($basePath = JPATH_BASE)
{
$dir = JLanguage::getLanguagePath($basePath);
$knownLanguages = JLanguage::_parseLanguageFiles($dir);
return $knownLanguages;
}
/**
* Get the path to a language
*
* @access public
* @param string $basePath The basepath to use
* @param string $language The language tag
* @return string language related path or null * @since 1.5
*/
function getLanguagePath($basePath = JPATH_BASE, $language = null )
{
$dir = $basePath.DS.'language';
if (!empty($language)) {
$dir .= DS.$language;
}
return $dir;
} /** * Set the language attributes to the given language * * Once called, the language still needs to be loaded using JLanguage::load() * * @access public * @param string $lang Language code * @return string Previous value * @since 1.5 */ function setLanguage($lang) {
$previous = $this->_lang; $this->_lang = $lang; $this->_metadata = $this->getMetadata($this->_lang); //set locale based on the language tag //TODO : add function to display locale setting in configuration $locale = setlocale(LC_ALL, $this->getLocale()); return $previous; }
/**
* Searches for language directories within a certain base dir
*
* @access public
* @param string $dir directory of files
* @return array Array holding the found languages as filename => real name pairs * @since 1.5
*/
function _parseLanguageFiles($dir = null)
{
jimport('joomla.filesystem.folder');
$languages = array ();
$subdirs = JFolder::folders($dir);
foreach ($subdirs as $path) {
$langs = JLanguage::_parseXMLLanguageFiles($dir.DS.$path);
$languages = array_merge($languages, $langs);
}
return $languages;
}
/**
* Parses XML files for language information
*
* @access public
* @param string $dir Directory of files
* @return array Array holding the found languages as filename => metadata array * @since 1.5
*/
function _parseXMLLanguageFiles($dir = null)
{
if ($dir == null) {
return null;
}
$languages = array ();
jimport('joomla.filesystem.folder');
$files = JFolder::files($dir, '^([-_A-Za-z]*)\.xml$');
foreach ($files as $file) {
if ($content = file_get_contents($dir.DS.$file)) {
if ($metadata = JLanguage::_parseXMLLanguageFile($dir.DS.$file)) {
$lang = str_replace('.xml', '', $file);
$languages[$lang] = $metadata;
}
}
}
return $languages;
}
/**
* Parse XML file for language information
*
* @access public
* @param string $path Path to the xml files
* @return array Array holding the found metadata as a key => value pair * @since 1.5
*/
function _parseXMLLanguageFile($path)
{
jimport('joomla.factory');
$xml = & JFactory::getXMLParser('Simple');
if (!$xml->loadFile($path)) {
return null;
}
// Check that it's am metadata file
if ($xml->document->name() != 'metafile') {
return null;
}
$metadata = array ();
//if ($xml->document->attributes('type') == 'language') {
foreach ($xml->document->metadata[0]->children() as $child) {
$metadata[$child->name()] = $child->data();
}
//}
return $metadata;
}
}
/**
* @package Joomla.Framework
* @subpackage I18N
* @static
* @since 1.5
*/
class JLanguageHelper
{
/**
* Builds a list of the system languages which can be used in a select option
*
* @access public
* @param string Client key for the area
* @param string Base path to use
* @param array An array of arrays ( text, value, selected ) * @since 1.5
*/
function createLanguageList($actualLanguage, $basePath = JPATH_BASE, $caching = false)
{
$list = array ();
// cache activation
$langs = JLanguage::getKnownLanguages($basePath);
foreach ($langs as $lang => $metadata)
{
$option = array ();
$option['text'] = $metadata['name'];
$option['value'] = $lang;
if ($lang == $actualLanguage) {
$option['selected'] = 'selected="selected"';
}
$list[] = $option;
}
return $list;
}
/**
* Tries to detect the language
*
* @access public * @return string locale * @since 1.5
*/
function detectLanguage()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$systemLangs = JLanguage::getKnownLanguages();
$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 (strtolower($browserLang) == strtolower(substr($metadata['tag'], 0, strlen($browserLang)))) {
return $systemLang;
} elseif ($primary_browserLang == substr($metadata['tag'], 0, 2)) {
$primaryDetectedLang = $systemLang;
}
}
if (isset($primaryDetectedLang)) {
return $primaryDetectedLang;
}
}
}
return 'en-GB';
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -