change language dynamically - bound to F8 key

pull/1/head
Friendika 2011-03-31 04:57:31 -07:00
parent 75ad3219e6
commit 08032e0453
6 changed files with 64 additions and 0 deletions

View File

@ -2669,3 +2669,23 @@ function extract_item_authors($arr,$uid) {
}
return array();
}}
if(! function_exists('lang_selector')) {
function lang_selector() {
global $lang;
$o .= '<div id="language-selector" style="display: none;" >';
$o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
$langs = glob('view/*/strings.php');
if(is_array($langs) && count($langs)) {
if(! in_array('view/en/strings.php',$langs))
$langs[] = 'view/en/';
foreach($langs as $l) {
$ll = substr($l,5);
$ll = substr($ll,0,strrpos($ll,'/'));
$selected = (($ll === $lang) ? ' selected="selected" ' : '');
$o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
}
}
$o .= '</select></form></div>';
return $o;
}}

View File

@ -26,6 +26,7 @@
var pr = 0;
var liking = 0;
var in_progress = false;
var langSelect = false;
$(document).ready(function() {
$.ajaxSetup({cache: false});
@ -45,6 +46,18 @@
$('#pause').html('');
}
}
// F8 - show/hide language selector
if(event.keyCode == '119') {
if(langSelect) {
langSelect = false;
$('#language-selector').hide();
}
else {
langSelect = true;
$('#language-selector').show();
}
}
// this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
// update: incompatible usage of onKeyDown vs onKeyPress
// if(event.keyCode == '36' && event.shiftKey == true) {

View File

@ -16,6 +16,7 @@ function nav(&$a) {
*/
$a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
$a->page['nav'] .= lang_selector();
/**
*

View File

@ -42,6 +42,11 @@ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
} else {
$lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}
if(x($_POST,'system_language'))
if(x($_SESSION,'language'))
$lang = $_SESSION['language'];
load_translation_table($lang);
@ -86,6 +91,19 @@ $a->init_pagehead();
session_start();
/**
* Language was set earlier, but we can over-ride it in the session.
* We have to do it here because the session was just now opened.
*/
if(x($_POST,'system_language'))
$_SESSION['language'] = $_POST['system_language'];
if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
$lang = $_SESSION['language'];
load_translation_table($lang);
}
/**
*
* For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.

View File

@ -2183,3 +2183,9 @@ a.mail-list-link {
.side-link {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0;
left: 0;
)

View File

@ -2205,3 +2205,9 @@ a.mail-list-link {
.side-link {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0;
left: 0;
)