Project

General

Profile

Feature #17565 » 6228_language.diff

Administrator Admin, 2007-09-22 16:49

View differences:

t3lib/class.t3lib_befunc.php (Revision 110)
return $sysLanguages;
}
/**
*
* Note: doesn't respect the q=-rating by now. Should perhaps be implemented
*
* @param boolean Include lang-variants as en-us or de-de?
* @return array All languages accepted by the user's browser, in order in which they appear in _SERVER[HTTP_ACCEPT_LANGUAGES]
*/
function getBrowserAcceptLanguages($includeSubLanguages = false) {
$langs_tmp = t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE');
$tmp_arr = t3lib_div::trimExplode(',', $langs_tmp, true);
$langs = array();
foreach ($tmp_arr as $langstring) {
if (strpos($langstring, ';') > 0) {
$lang = substr($langstring, 0, strpos($langstring, ';'));
} else {
$lang = $langstring;
}
if (strlen($lang) > 0) {
if (!$includeSubLanguages && substr_count($lang, '-') > 0) {
$lang = substr($lang, 0, 2);
}
if (!in_array($lang, $langs)) {
$langs[] = $lang;
}
}
}
return $langs;
}
/**
* Returns the available backend-languages (checks for the language-keys in typo3conf/l10n/
*
* @return array The available languages
*/
function getAvailableBELanguages() {
global $LANG;
$lang = array();
$theLanguages = t3lib_div::trimExplode('|',TYPO3_languages);
foreach($theLanguages as $val) {
if ($val != 'default' && !@is_dir(PATH_typo3conf.'l10n/'.$val)) {
continue;
}
$lang[$val] = $LANG->sL('LLL:EXT:setup/mod/locallang.xml:lang_'.$val);
}
return $lang;
}
/**
* Returns a page record (of page with $id) with an extra field "_thePath" set to the record path IF the WHERE clause, $perms_clause, selects the record. Thus is works as an access check that returns a page record if access was granted, otherwise not.
t3lib/class.t3lib_div.php (Revision 110)
function uniqueArray($valueArray) {
return array_unique($valueArray);
}
/**
* Returns the key of a value in a given array.
*
* @param array Array containing the values
* @param string Value to search for and if found return its key.
* @return string/int The key of the value in the array
*/
function getArrayKeyForValue($array,$cmpValue) {
foreach ($array as $k=>$v) {
if ($v == $cmpValue) {
return $k;
}
}
}
/**
* Removes the value $cmpValue from the $array if found there. Returns the modified array
typo3/index.php (Revision 110)
* @return string HTML output
*/
function makeLoginForm() {
global $LANG, $LOCAL_LANG, $TYPO3_CONF_VARS;
// output the language-selector-menu
$lang = t3lib_BEfunc::getAvailableBELanguages();
asort($lang);
$content .= '<div class="langselect" style="text-align:right;"><select name="lang" style="margin-top:10px;" onChange="document.location.href = \''.t3lib_div::getIndpEnv('SCRIPT_NAME').'?lang=\'+this.options[this.options.selectedIndex].value">'.chr(10);
foreach ($lang as $k=>$l) {
$content .= '<option value="'.$k.'"'.($LANG->lang==$k ? ' selected="selected"' : '').'>'.$l.'</option>'.chr(10);
}
$content.='</select></div>';
typo3/template.php (Revision 110)
// ******************************************************
require_once(PATH_typo3.'sysext/lang/lang.php');
$LANG = t3lib_div::makeInstance('language');
$LANG->init($BE_USER->uc['lang']);
if ($BE_USER->uid) {
$LANG->init($BE_USER->uc['lang']);
} elseif (t3lib_div::_GP('lang') != '' && strpos(TYPO3_languages, t3lib_div::_GP('lang')) !== false) {
$LANG->init(t3lib_div::_GP('lang'));
} else {
$langs = t3lib_BEfunc::getBrowserAcceptLanguages();
$LANG->init($langs);
}
typo3/sysext/lang/lang.php (Revision 110)
* @return void
*/
function init($lang,$altPath='') {
if (!is_array($lang)) {
$lang = array($lang);
}
// Initialize the conversion object:
$this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
......
// Finding the requested language in this list based on the $lang key being inputted to this function.
$ls = explode('|',$this->langSplit);
while(list($i,$v)=each($ls)) {
if ($v==$lang) { // Language is found. Configure it:
$this->langSplitIndex=$i; // The index of the language as found in the TYPO3_languages list
$this->lang = $lang; // The current language key
foreach ($lang as $l) {
if ($l == 'en') {
$l = 'default';
}
// if this language is not available, proceed with the next
if ($l != 'default' && !@is_dir(PATH_typo3conf.'l10n/'.$l)) {
continue;
}
if (in_array($l, $ls)) { // Language is found. Configure it:
$this->langSplitIndex=t3lib_div::getArrayKeyForValue($ls, $l); // The index of the language as found in the TYPO3_languages list
$this->lang = $l; // The current language key
if ($this->helpUrlArray[$this->lang]) $this->typo3_help_url=$this->helpUrlArray[$this->lang]; // The help URL if different from the default.
if ($this->charSetArray[$this->lang]) $this->charSet=$this->charSetArray[$this->lang]; // The charset if different from the default.
break;
}
}
(3-3/3)