Merge pull request #2044 from fabrixxm/issue_1249

User language setting is a setting and now is between settings in settings page
This commit is contained in:
Tobias Diekershoff 2015-11-08 15:04:01 +01:00
commit b7507a8f22
28 changed files with 752 additions and 988 deletions

View File

@ -27,7 +27,6 @@ function nav(&$a) {
$a->page['nav'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$langselector' => lang_selector(),
'$sitelocation' => $nav_info['sitelocation'],
'$nav' => $nav_info['nav'],
'$banner' => $nav_info['banner'],

View File

@ -161,3 +161,26 @@ function string_plural_select_default($n) {
return ($n != 1);
}}
/**
* Return installed languages as associative array
* [
* lang => lang,
* ...
* ]
*/
function get_avaiable_languages() {
$lang_choices = array();
$langs = glob('view/*/strings.php'); /**/
if(is_array($langs) && count($langs)) {
if(! in_array('view/en/strings.php',$langs))
$langs[] = 'view/en/';
asort($langs);
foreach($langs as $l) {
$t = explode("/",$l);
$lang_choices[$t[1]] = $t[1];
}
}
return $lang_choices;
}

View File

@ -1738,50 +1738,6 @@ function unamp($s) {
}}
if(! function_exists('lang_selector')) {
/**
* get html for language selector
* @global string $lang
* @return string
* @template lang_selector.tpl
*/
function lang_selector() {
global $lang;
$langs = glob('view/*/strings.php');
$lang_options = array();
$selected = "";
if(is_array($langs) && count($langs)) {
$langs[] = '';
if(! in_array('view/en/strings.php',$langs))
$langs[] = 'view/en/';
asort($langs);
foreach($langs as $l) {
if($l == '') {
$lang_options[""] = t('default');
continue;
}
$ll = substr($l,5);
$ll = substr($ll,0,strrpos($ll,'/'));
$selected = (($ll === $lang && (x($_SESSION, 'language'))) ? $ll : $selected);
$lang_options[$ll]=$ll;
}
}
$tpl = get_markup_template("lang_selector.tpl");
$o = replace_macros($tpl, array(
'$title' => t('Select an alternate language'),
'$langs' => array($lang_options, $selected),
));
return $o;
}}
if(! function_exists('return_bytes')) {
/**
* return number of bytes in size (K, M, G)

View File

@ -102,13 +102,13 @@ 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(array_key_exists('system_language',$_POST)) {
if(strlen($_POST['system_language']))
$_SESSION['language'] = $_POST['system_language'];
else
unset($_SESSION['language']);
if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) {
// we didn't loaded user data yet, but we need user language
$r = q("SELECT language FROM user WHERE uid=%d", intval($_SESSION['uid']));
$_SESSION['language'] = $lang;
if (count($r)>0) $_SESSION['language'] = $r[0]['language'];
}
if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
$lang = $_SESSION['language'];
load_translation_table($lang);

View File

@ -603,18 +603,7 @@ function admin_page_site_post(&$a){
function admin_page_site(&$a) {
/* Installed langs */
$lang_choices = array();
$langs = glob('view/*/strings.php'); /**/
if(is_array($langs) && count($langs)) {
if(! in_array('view/en/strings.php',$langs))
$langs[] = 'view/en/';
asort($langs);
foreach($langs as $l) {
$t = explode("/",$l);
$lang_choices[$t[1]] = $t[1];
}
}
$lang_choices = get_avaiable_languages();
if (strlen(get_config('system','directory_submit_url')) AND
!strlen(get_config('system','directory'))) {

View File

@ -13,7 +13,6 @@ function navigation_content(&$a) {
$tpl = get_markup_template('navigation.tpl');
return replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$langselector' => lang_selector(),
'$sitelocation' => $nav_info['sitelocation'],
'$nav' => $nav_info['nav'],
'$banner' => $nav_info['banner'],

View File

@ -386,6 +386,8 @@ function settings_post(&$a) {
$username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
$email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
$timezone = ((x($_POST,'timezone')) ? notags(trim($_POST['timezone'])) : '');
$language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
$defloc = ((x($_POST,'defloc')) ? notags(trim($_POST['defloc'])) : '');
$openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
$maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
@ -532,7 +534,15 @@ function settings_post(&$a) {
}
}
$r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s', `def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d, `unkmail` = %d, `cntunkmail` = %d WHERE `uid` = %d",
$r = q("UPDATE `user` SET `username` = '%s', `email` = '%s',
`openid` = '%s', `timezone` = '%s',
`allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s',
`notify-flags` = %d, `page-flags` = %d, `default-location` = '%s',
`allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s',
`def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d,
`unkmail` = %d, `cntunkmail` = %d, `language` = '%s'
WHERE `uid` = %d",
dbesc($username),
dbesc($email),
dbesc($openid),
@ -554,11 +564,15 @@ function settings_post(&$a) {
intval($blocktags),
intval($unkmail),
intval($cntunkmail),
dbesc($language),
intval(local_user())
);
if($r)
info( t('Settings updated.') . EOL);
// clear session language
unset($_SESSION['language']);
$r = q("UPDATE `profile`
SET `publish` = %d,
`name` = '%s',
@ -985,6 +999,7 @@ function settings_content(&$a) {
$email = $a->user['email'];
$nickname = $a->user['nickname'];
$timezone = $a->user['timezone'];
$language = $a->user['language'];
$notify = $a->user['notify-flags'];
$defloc = $a->user['default-location'];
$openid = $a->user['openid'];
@ -1168,6 +1183,8 @@ function settings_content(&$a) {
else
$public_post_link = '&public=1';
/* Installed langs */
$lang_choices = get_avaiable_languages();
$o .= replace_macros($stpl, array(
'$ptitle' => t('Account Settings'),
@ -1190,6 +1207,7 @@ function settings_content(&$a) {
'$username' => array('username', t('Full Name:'), $username,''),
'$email' => array('email', t('Email Address:'), $email, '', '', '', 'email'),
'$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''),
'$language' => array('language', t('Your Language:'), $language, t('Set the language we use to show you friendica interface and to send you emails'), $lang_choices),
'$defloc' => array('defloc', t('Default Post Location:'), $defloc, ''),
'$allowloc' => array('allow_location', t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''),

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" >lang</div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v|escape:'html'}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -27,6 +27,7 @@
{{include file="field_input.tpl" field=$email}}
{{include file="field_password.tpl" field=$password4}}
{{include file="field_custom.tpl" field=$timezone}}
{{include file="field_select.tpl" field=$language}}
{{include file="field_input.tpl" field=$defloc}}
{{include file="field_checkbox.tpl" field=$allowloc}}

View File

@ -3394,11 +3394,6 @@ aside input[type='text'] {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0px;
left: 16px;
}
#group-members {
margin-top: 20px;
@ -3576,20 +3571,6 @@ aside input[type='text'] {
text-decoration: underline;
}
#lang-select-icon {
cursor: pointer;
position: fixed;
left: 0px;
top: 0px;
opacity: 0.2;
filter:alpha(opacity=20);
}
#lang-select-icon:hover {
opacity: 1;
filter:alpha(opacity=100);
}
.notif-image {
height: 80px;
width: 80px;
@ -3601,7 +3582,6 @@ aside input[type='text'] {
}
/**
* Plugins settings
*/

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -27,6 +27,7 @@
{{include file="field_input.tpl" field=$email}}
{{include file="field_password.tpl" field=$password4}}
{{include file="field_custom.tpl" field=$timezone}}
{{include file="field_select.tpl" field=$language}}
{{include file="field_input.tpl" field=$defloc}}
{{include file="field_checkbox.tpl" field=$allowloc}}

View File

@ -125,8 +125,6 @@ nav #nav-notifications-linkmenu.on .icon.s22.notify,nav #nav-notifications-linkm
#notify-update{background-position:-60px 0px;}
#home-update{background-position:-90px 0px;}
#intro-update{background-position:-120px 0px;}
#lang-select-icon{cursor:pointer;position:fixed;left:28px;bottom:6px;z-index:10;}
#language-selector{position:fixed;bottom:2px;left:52px;z-index:10;}
.menu-popup{position:absolute;display:none;background:white;color:#2e2f2e;margin:0px;padding:0px;font-size:small;line-height:1.2;border:3px solid #88a9d2;-o-border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;-ms-border-radius:5px;border-radius:5px;z-index:100000;-moz-box-shadow:5px 5px 5px 0px #111111;-o-box-shadow:5px 5px 5px 0px #111111;-webkit-box-shadow:5px 5px 5px 0px #111111;-ms-box-shadow:5px 5px 5px 0px #111111;box-shadow:5px 5px 5px 0px #111111;}.menu-popup a{display:block;color:#2e2f2e;padding:5px 10px;text-decoration:none;}.menu-popup a:hover{color:#eeeecc;background-color:#88a9d2;}
.menu-popup .menu-sep{border-top:1px solid #4e4f4e;}
.menu-popup li{float:none;overflow:auto;height:auto;display:block;}.menu-popup li img{float:left;width:16px;height:16px;padding-right:5px;}

View File

@ -798,19 +798,7 @@ nav #nav-notifications-linkmenu {
#intro-update {
background-position: -120px 0px;
}
#lang-select-icon {
cursor: pointer;
position: fixed;
left: 28px;
bottom: 6px;
z-index: 10;
}
#language-selector {
position: fixed;
bottom: 2px;
left: 52px;
z-index: 10;
}
.menu-popup {
position: absolute;
display: none;

View File

@ -125,8 +125,6 @@ nav #nav-notifications-linkmenu.on .icon.s22.notify,nav #nav-notifications-linkm
#notify-update{background-position:-60px 0px;}
#home-update{background-position:-90px 0px;}
#intro-update{background-position:-120px 0px;}
#lang-select-icon{cursor:pointer;position:fixed;left:28px;bottom:6px;z-index:10;}
#language-selector{position:fixed;bottom:2px;left:52px;z-index:10;}
.menu-popup{position:absolute;display:none;background:white;color:#111111;margin:0px;padding:0px;font-size:small;line-height:1.2;border:3px solid #3465a4;-o-border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;-ms-border-radius:5px;border-radius:5px;z-index:100000;-moz-box-shadow:5px 5px 5px 0px #111111;-o-box-shadow:5px 5px 5px 0px #111111;-webkit-box-shadow:5px 5px 5px 0px #111111;-ms-box-shadow:5px 5px 5px 0px #111111;box-shadow:5px 5px 5px 0px #111111;}.menu-popup a{display:block;color:#111111;padding:5px 10px;text-decoration:none;}.menu-popup a:hover{color:#eeeeec;background-color:#3465a4;}
.menu-popup .menu-sep{border-top:1px solid #4e4f4e;}
.menu-popup li{float:none;overflow:auto;height:auto;display:block;}.menu-popup li img{float:left;width:16px;height:16px;padding-right:5px;}

View File

@ -799,19 +799,7 @@ nav #nav-notifications-linkmenu {
#intro-update {
background-position: -120px 0px;
}
#lang-select-icon {
cursor: pointer;
position: fixed;
left: 28px;
bottom: 6px;
z-index: 10;
}
#language-selector {
position: fixed;
bottom: 2px;
left: 52px;
z-index: 10;
}
.menu-popup {
position: absolute;
display: none;

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -2713,12 +2713,6 @@ aside input[type='text'] {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0px;
left: 16px;
}
#group-members {
margin-top: 20px;
padding: 10px;
@ -2888,19 +2882,6 @@ aside input[type='text'] {
text-decoration: underline;
}
#lang-select-icon {
cursor: pointer;
position: absolute;
left: 0px;
top: 0px;
opacity: 0.2;
filter:alpha(opacity=20);
}
#lang-select-icon:hover {
opacity: 1;
filter:alpha(opacity=100);
}
.notif-image {
height: 80px;

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -2493,11 +2493,6 @@ aside input[type='text'] {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0px;
left: 16px;
}
#group-members {
margin-top: 20px;
@ -2668,19 +2663,6 @@ aside input[type='text'] {
text-decoration: underline;
}
#lang-select-icon {
cursor: pointer;
position: absolute;
left: 0px;
top: 0px;
opacity: 0.2;
filter:alpha(opacity=20);
}
#lang-select-icon:hover {
opacity: 1;
filter:alpha(opacity=100);
}
.notif-image {
height: 80px;

View File

@ -3389,11 +3389,6 @@ aside input[type='text'] {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0px;
left: 16px;
}
#group-members {
margin-top: 20px;
@ -3570,20 +3565,6 @@ aside input[type='text'] {
text-decoration: underline;
}
#lang-select-icon {
cursor: pointer;
position: fixed;
left: 0px;
top: 0px;
opacity: 0.2;
filter:alpha(opacity=20);
}
#lang-select-icon:hover {
opacity: 1;
filter:alpha(opacity=100);
}
.notif-image {
height: 80px;
width: 80px;

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -27,6 +27,7 @@
{{include file="field_input.tpl" field=$email}}
{{include file="field_password.tpl" field=$password4}}
{{include file="field_custom.tpl" field=$timezone}}
{{include file="field_select.tpl" field=$language}}
{{include file="field_input.tpl" field=$defloc}}
{{include file="field_checkbox.tpl" field=$allowloc}}

View File

@ -3159,12 +3159,6 @@ aside input[type='text'] {
margin-bottom: 15px;
}
#language-selector {
position: absolute;
top: 0px;
left: 16px;
}
#group-members {
margin-top: 20px;
padding: 10px;
@ -3351,19 +3345,6 @@ aside input[type='text'] {
text-decoration: underline;
}
#lang-select-icon {
cursor: pointer;
position: absolute;
left: 0px;
top: 0px;
opacity: 0.2;
filter:alpha(opacity=20);
}
#lang-select-icon:hover {
opacity: 1;
filter:alpha(opacity=100);
}
.notif-image {
height: 80px;

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -575,19 +575,7 @@ ul#user-menu-popup li a.nav-sep {
background-position: 0px 0px;
}
#lang-select-icon {
bottom: 5px;
cursor: pointer;
left: 25px;
position: fixed;
z-index: 10;
}
#language-selector {
position: fixed;
bottom: 2px;
left: 55px;
z-index: 10;
}
/* =================== */
/* = System Messages = */

View File

@ -1,11 +0,0 @@
<div id="lang-select-icon" class="icon s22 language" title="{{$title}}" onclick="openClose('language-selector');" ></div>
<div id="language-selector" style="display: none;" >
<form action="#" method="post" >
<select name="system_language" onchange="this.form.submit();" >
{{foreach $langs.0 as $v=>$l}}
<option value="{{$v}}" {{if $v==$langs.1}}selected="selected"{{/if}}>{{$l}}</option>
{{/foreach}}
</select>
</form>
</div>

View File

@ -388,18 +388,7 @@ ul#user-menu-popup li a.nav-sep { border-top: 1px solid #989898; border-style:in
#intro-update { background-position: 0px -84px; }
#home-update { background-position: 0px 0px; }
#lang-select-icon {
cursor: pointer;
position: absolute;
left: 5px;
top: 5px;
}
#language-selector {
position: absolute;
top: 0;
left: 16px;
}
/* =================== */
/* = System Messages = */