Make language selection work better
This commit is contained in:
parent
70fc0b5c5c
commit
8a0c8bd8d3
@ -50,10 +50,10 @@ class Utils {
|
||||
* @deprecated
|
||||
*/
|
||||
public static function print_header($title = '') {
|
||||
global $lang;
|
||||
global $html_lang;
|
||||
|
||||
echo '<!DOCTYPE html>
|
||||
<html lang="' . $lang . '">
|
||||
<html lang="' . $html_lang . '">
|
||||
<head>
|
||||
<meta charset="utf-8" />';
|
||||
|
||||
@ -72,7 +72,7 @@ class Utils {
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/jquery-1.11.1.min.js"></script>
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/bootstrap-datepicker.js"></script>
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/locales/bootstrap-datepicker.' . $lang . '.js"></script>
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/locales/bootstrap-datepicker.' . $html_lang . '.js"></script>
|
||||
<script type="text/javascript" src="' . self::get_server_name() . 'js/core.js"></script>';
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/nav/nav.js")) {
|
||||
echo '<script src="/nav/nav.js" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav -->';
|
||||
|
@ -19,59 +19,61 @@
|
||||
|
||||
asort($ALLOWED_LANGUAGES);
|
||||
|
||||
if (isset($_POST['lang']) && is_string($_POST['lang']) && in_array($_POST['lang'], array_keys($ALLOWED_LANGUAGES)) ) {
|
||||
$mlocale = $_POST['lang'] ;
|
||||
setcookie('lang' , $_POST['lang'], time()+60*5, '/');
|
||||
} elseif ( isset($_COOKIE['lang']) && is_string($_COOKIE['lang']) && in_array($_COOKIE['lang'], array_keys($ALLOWED_LANGUAGES)) ) {
|
||||
$mlocale = $_COOKIE['lang'] ;
|
||||
if (isset($_POST['lang']) && is_string($_POST['lang']) && in_array($_POST['lang'], array_keys($ALLOWED_LANGUAGES))) {
|
||||
$mlocale = $_POST['lang'];
|
||||
$_SESSION['lang'] = $_POST['lang'];
|
||||
} elseif (isset($_SESSION['lang']) && is_string($_SESSION['lang']) && in_array($_SESSION['lang'], array_keys($ALLOWED_LANGUAGES))) {
|
||||
$mlocale = $_SESSION['lang'];
|
||||
} else {
|
||||
|
||||
$mlocale = LANGUE;
|
||||
// Replace config language by browser language if possible
|
||||
foreach ($ALLOWED_LANGUAGES as $k => $v ) {
|
||||
if (substr($k,0,2)==substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)) {
|
||||
foreach ($ALLOWED_LANGUAGES as $k => $v) {
|
||||
if (substr($k, 0, 2) == substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)) {
|
||||
$mlocale = $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$locale = $mlocale . '.utf8';//unix format
|
||||
if (strtoupper(substr(PHP_OS,0,3))=='WIN'){
|
||||
putenv("LC_ALL=$mlocale"); //Windows env. needed to switch between languages
|
||||
switch ($mlocale){
|
||||
case 'fr_FR' : $locale = "fra";break; //$locale in windows locale format, needed to use php function that handle text : strftime()
|
||||
case 'en_GB' : $locale = "english";break; //see http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx
|
||||
case 'de_DE' : $locale = "deu";break;
|
||||
case 'es_ES' : $locale = "esp";break;
|
||||
}
|
||||
}
|
||||
|
||||
putenv('LANGUAGE=');//sert à quoi?
|
||||
setlocale(LC_ALL, $locale);
|
||||
setlocale(LC_TIME, $locale);
|
||||
setlocale(5, $locale); // 5 = LC_MESSAGES (but LC_MESSAGES is not always present)
|
||||
|
||||
/* Tell PHP which locale to use */
|
||||
$domain = 'Studs';
|
||||
bindtextdomain($domain, 'locale');
|
||||
$locale = $mlocale . '.utf8'; //unix format
|
||||
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
|
||||
putenv("LC_ALL=$mlocale"); //Windows env. needed to switch between languages
|
||||
switch ($mlocale) {
|
||||
case 'fr_FR' :
|
||||
$locale = "fra";
|
||||
break; //$locale in windows locale format, needed to use php function that handle text : strftime()
|
||||
case 'en_GB' :
|
||||
$locale = "english";
|
||||
break; //see http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx
|
||||
case 'de_DE' :
|
||||
$locale = "deu";
|
||||
break;
|
||||
case 'es_ES' :
|
||||
$locale = "esp";
|
||||
break;
|
||||
}
|
||||
}
|
||||
putenv('LANG=' . $locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
bindtextdomain($domain, ROOT_DIR . 'locale');
|
||||
bind_textdomain_codeset($domain, 'UTF-8');
|
||||
textdomain($domain);
|
||||
|
||||
/* temp, for compatibility :*/
|
||||
$a = explode('_', $mlocale);
|
||||
$_SESSION['langue'] = strtoupper($a[0]);
|
||||
|
||||
/* <html lang="$lang"> */
|
||||
$lang = ($_SESSION['langue']!='') ? strtolower($_SESSION['langue']) : 'fr';
|
||||
|
||||
/* <html lang="$html_lang"> */
|
||||
$html_lang = substr($locale, 0, 2);
|
||||
|
||||
/* Date Format */
|
||||
$date_format['txt_full'] = _('%A, den %e. %B %Y'); //summary in choix_date.php and removal date in choix_(date|autre).php
|
||||
$date_format['txt_short'] = _('%A %e %B %Y'); // radio title
|
||||
$date_format['txt_day'] = _('%a %e');
|
||||
$date_format['txt_date'] = _('%Y-%m-%d');
|
||||
if (strtoupper(substr(PHP_OS,0,3))=='WIN'){ //%e can't be used on Windows platform, use %#d instead
|
||||
foreach($date_format as $k => $v) {
|
||||
$date_format[$k] = preg_replace('#(?<!%)((?:%%)*)%e#','\1%#d', $v); //replace %e by %#d for windows
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { //%e can't be used on Windows platform, use %#d instead
|
||||
foreach ($date_format as $k => $v) {
|
||||
$date_format[$k] = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $v); //replace %e by %#d for windows
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ $smarty->assign('SERVER_URL', Utils::get_server_name());
|
||||
$smarty->assign('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
|
||||
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
|
||||
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
|
||||
$smarty->assign('lang', $lang);
|
||||
$smarty->assign('html_lang', $html_lang);
|
||||
$smarty->assign('langs', $ALLOWED_LANGUAGES);
|
||||
$smarty->assign('date_format', $date_format);
|
||||
|
||||
|
@ -57,12 +57,12 @@ function bandeau_titre($titre)
|
||||
|
||||
function liste_lang()
|
||||
{
|
||||
global $ALLOWED_LANGUAGES; global $lang;
|
||||
global $ALLOWED_LANGUAGES; global $html_lang;
|
||||
|
||||
$str = '';
|
||||
|
||||
foreach ($ALLOWED_LANGUAGES as $k => $v ) {
|
||||
if (substr($k,0,2)==$lang) {
|
||||
if (substr($k,0,2)==$html_lang) {
|
||||
$str .= '<option lang="'.substr($k,0,2).'" selected value="' . $k . '">' . $v . '</option>' . "\n" ;
|
||||
} else {
|
||||
$str .= '<option lang="'.substr($k,0,2).'" value="' . $k . '">' . $v . '</option>' . "\n" ;
|
||||
|
@ -232,7 +232,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
|
||||
<p>' . _("To make a generic poll you need to propose at least two choices between differents subjects.") . '</p>
|
||||
<p>' . _("You can add or remove additional choices with the buttons") . ' <span class="glyphicon glyphicon-minus text-info"></span><span class="sr-only">' . _("Remove") . '</span> <span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">' . _("Add") . '</span></p>';
|
||||
if ($config['user_can_add_img_or_link']) {
|
||||
echo ' <p>' . _("It's possible to propose links or images by using ") . '<a href="http://' . $lang . '.wikipedia.org/wiki/Markdown">' . _("the Markdown syntax") . '</a>.</p>';
|
||||
echo ' <p>' . _("It's possible to propose links or images by using ") . '<a href="http://' . $html_lang . '.wikipedia.org/wiki/Markdown">' . _("the Markdown syntax") . '</a>.</p>';
|
||||
}
|
||||
echo ' </div>' . "\n";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{$lang}">
|
||||
<html lang="{$html_lang}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<script type="text/javascript" src="{'js/jquery-1.11.1.min.js'|resource}"></script>
|
||||
<script type="text/javascript" src="{'js/bootstrap.min.js'|resource}"></script>
|
||||
<script type="text/javascript" src="{'js/bootstrap-datepicker.js'|resource}"></script>
|
||||
<script type="text/javascript" src="{"js/locales/bootstrap-datepicker.$lang.js"|resource}"></script>
|
||||
<script type="text/javascript" src="{"js/locales/bootstrap-datepicker.$html_lang.js"|resource}"></script>
|
||||
<script type="text/javascript" src="{'js/core.js'|resource}"></script>
|
||||
|
||||
{if !empty($nav_js)}
|
||||
|
@ -4,7 +4,7 @@
|
||||
<div class="input-group input-group-sm pull-right col-md-2 col-xs-4">
|
||||
<select name="lang" class="form-control" title="{_("Select the language")}" >
|
||||
{foreach $langs as $lang_key=>$lang_value}
|
||||
<option lang="{substr($lang_key, 0, 2)}" {if substr($lang_key, 0, 2)==$lang}selected{/if} value="{$lang_key|html}">{$lang_value|html}</option>
|
||||
<option lang="{substr($lang_key, 0, 2)}" {if substr($lang_key, 0, 2)==$html_lang}selected{/if} value="{$lang_key|html}">{$lang_value|html}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<span class="input-group-btn">
|
||||
|
Loading…
Reference in New Issue
Block a user