Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed en_EN #896

Merged
merged 1 commit into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions Modules/user/user_model.php
Expand Up @@ -174,6 +174,7 @@ public function emon_session_start()
$_SESSION['write'] = 1;
//$_SESSION['admin'] = $userData->admin; // Admin mode requires user to login manualy
$_SESSION['lang'] = $userData->language;
$_SESSION['timezone'] = $userData->timezone;
if (isset($userData->startingpage)) $_SESSION['startingpage'] = $userData->startingpage;
// There is a chance that an attacker has stolen the login token, so we store
// the fact that the user was logged in via RememberMe (instead of login form)
Expand All @@ -193,6 +194,7 @@ public function emon_session_start()
if (isset($_SESSION['write'])) $session['write'] = $_SESSION['write']; else $session['write'] = 0;
if (isset($_SESSION['userid'])) $session['userid'] = $_SESSION['userid']; else $session['userid'] = 0;
if (isset($_SESSION['lang'])) $session['lang'] = $_SESSION['lang']; else $session['lang'] = '';
if (isset($_SESSION['timezone'])) $session['timezone'] = $_SESSION['timezone']; else $session['timezone'] = '';
if (isset($_SESSION['startingpage'])) $session['startingpage'] = $_SESSION['startingpage']; else $session['startingpage'] = '';
if (isset($_SESSION['username'])) $session['username'] = $_SESSION['username']; else $session['username'] = 'REMEMBER_ME';
if (isset($_SESSION['cookielogin'])) $session['cookielogin'] = $_SESSION['cookielogin']; else $session['cookielogin'] = 0;
Expand Down Expand Up @@ -340,13 +342,13 @@ public function login($username, $password, $remembermecheck)

// 28/04/17: Changed explicitly stated fields to load all with * in order to access startingpage
// without cuasing an error if it has not yet been created in the database.
if (!$stmt = $this->mysqli->prepare("SELECT id,password,salt,apikey_write,admin,language,startingpage,email_verified FROM users WHERE username=?")) {
if (!$stmt = $this->mysqli->prepare("SELECT id,password,salt,apikey_write,admin,language,startingpage,email_verified,timezone FROM users WHERE username=?")) {
return array('success'=>false, 'message'=>_("Database error, you may need to run database update"));
}
$stmt->bind_param("s",$username);
$stmt->execute();

$stmt->bind_result($userData_id,$userData_password,$userData_salt,$userData_apikey_write,$userData_admin,$userData_language,$userData_startingpage,$email_verified);
$stmt->bind_result($userData_id,$userData_password,$userData_salt,$userData_apikey_write,$userData_admin,$userData_language,$userData_startingpage,$email_verified,$userData_timezone);
$result = $stmt->fetch();
$stmt->close();

Expand All @@ -372,6 +374,7 @@ public function login($username, $password, $remembermecheck)
$_SESSION['write'] = 1;
$_SESSION['admin'] = $userData_admin;
$_SESSION['lang'] = $userData_language;
$_SESSION['timezone'] = $userData_timezone;
$_SESSION['startingpage'] = $userData_startingpage;

if ($this->enable_rememberme) {
Expand Down Expand Up @@ -711,8 +714,12 @@ public function get($userid)

public function set($userid,$data)
{
global $default_language;
$default_locale = !empty($default_language) ? $default_language : 'en_GB';
$default_timezone = 'Europe/London';
Copy link
Contributor Author

@emrysr emrysr Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a good idea to put $default_timezone in settings.php too?

// Validation
$userid = (int) $userid;
if(!$data || $userid < 1) return array('success'=>false, 'message'=>_("Error updating user info"));

$gravatar = preg_replace('/[^\w\s-.@]/','',$data->gravatar);
$name = preg_replace('/[^\p{N}\p{L}_\s-.]/u','',$data->name);
Expand All @@ -721,10 +728,10 @@ public function set($userid,$data)
$bio = preg_replace('/[^\p{N}\p{L}_\s-.]/u','',$data->bio);
$language = preg_replace('/[^\w\s-.]/','',$data->language);
$tags = isset($data->tags) == false ? '' : preg_replace('/[^{}",:\w\s-.]/','', $data->tags);

$startingpage = preg_replace('/[^\p{N}\p{L}_\s-?#=\/]/u','',$data->startingpage);

$_SESSION['lang'] = $language;
$_SESSION['lang'] = !empty($language) ? $language : $default_locale;
$_SESSION['timezone'] = !empty($timezone) ? $timezone : $default_timezone;
Copy link
Contributor Author

@emrysr emrysr Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if these session variables are used by anything ... any ideas where this might be useful?


$stmt = $this->mysqli->prepare("UPDATE users SET gravatar = ?, name = ?, location = ?, timezone = ?, language = ?, bio = ?, startingpage = ?, tags = ? WHERE id = ?");
$stmt->bind_param("ssssssssi", $gravatar, $name, $location, $timezone, $language, $bio, $startingpage, $tags, $userid);
Expand Down
3 changes: 3 additions & 0 deletions default.emonpi.settings.php
Expand Up @@ -76,6 +76,9 @@


//5 #### User Interface settings
// gettext translations are found under each Module's locale directory
$default_language = 'en_GB';

// Theme location (folder located under Theme/, and must have the same structure as the basic one)
$theme = "basic";
// Theme colour options: "standard", "blue", "sun"
Expand Down
3 changes: 3 additions & 0 deletions default.settings.php
Expand Up @@ -77,6 +77,9 @@


//5 #### User Interface settings
// gettext translations are found under each Module's locale directory
$default_language = 'en_GB';

// Theme location (folder located under Theme/, and must have the same structure as the basic one)
$theme = "basic";
// Theme colour options: "standard", "blue", "sun"
Expand Down
6 changes: 3 additions & 3 deletions docs/gettext.md
Expand Up @@ -83,11 +83,11 @@ To generate the locale for the default character set, run the following:

$ sudo /etc/init.d/apache2 restart

To enable a language as a default for emonCMS you need to edit `locale.php` line 88
To enable a language as a default for emonCMS you need to edit the `$default_language` variable in `settings.php` line 81

$ default : $lang='en_US';
`$default_language = 'en_GB';`

*Note: currently not all Emoncms strings have been translated*
*Note: currently not all Emoncms strings have been translated, please contribue if you're able*


This short guide is based on the following useful tutorials and QA:
Expand Down
65 changes: 32 additions & 33 deletions locale.php
Expand Up @@ -49,47 +49,45 @@ function lang_http_accept()
$splits = array();

if (preg_match($pattern, $lang, $splits)) {
$a = $splits["primarytag"];
if (isset($splits["subtag"]) && $splits["subtag"]<> "") $a = $a."_".$splits["subtag"];
$langs[]=$a;
$langs[] = !empty($splits['subtag']) ? $splits["primarytag"] . "_" . $splits['subtag'] : $splits["primarytag"];
} else {
// No match
}
}
return $langs;
}

/***
* take the first value from the given list and save it as the user's language
* only takes supported language values.
* @param array $language - array returned by lang_http_accept() - without the quantify values
* @todo possibly fall back to second or third choices if available?
*/
function set_lang($language)
{
// set the first browser selected language
// TODO: iterate to find a suitable available language

// Chrome returns different HTTP_ACCEPT_LANGUAGE code than firefox!!!
// Firefox Chrome
// -------------------
// en_EN en
// es_ES es
// ... so translation system does not work in Chrome!!!
// lets try to fix quickly

if (isset($language[0]))
{
$lang=$language[0];

switch($lang) {
case 'cy': $lang='cy_GB'; break;
case 'da': $lang='da_DK'; break;
case 'en': $lang='en_EN'; break;
case 'es': $lang='es_ES'; break;
case 'fr': $lang='fr_FR'; break;
case 'it': $lang='it_IT'; break;
case 'nl': $lang='nl_NL'; break;
//case 'nl': $lang='nl_BE'; break; //to do??
default : $lang='en_EN';
}

set_lang_by_user($lang);
global $default_language;
// DEFAULT - from settings.php (if not in file use 'en_GB')
$default = !empty($default_language) ? $default_language : 'en_GB';
$firstChoice = !empty($language[0]) ? filter_var($language[0], FILTER_SANITIZE_STRING) : $default;
$supported_languages = array(
'cy' => 'cy_GB',
'da' => 'da_DK',
'es' => 'es_ES',
'fr' => 'fr_FR',
'it' => 'it_IT',
'nl' => 'nl_NL',
'en' => 'en_GB'
);
// if given language is a key or value in the above list use it
if (isset($supported_languages[$firstChoice])) { // key check
$lang = $supported_languages[$firstChoice];
} elseif (in_array($firstChoice, $supported_languages)) { // value check
$lang = $firstChoice;
} else {
$lang = $default; // not found use default
}

set_lang_by_user($lang);
}

function set_lang_by_user($lang)
Expand All @@ -101,9 +99,10 @@ function set_lang_by_user($lang)
function set_emoncms_lang($lang)
{
// If no language defined use the language browser
if ($lang == '')
if ($lang == '') {
set_lang(lang_http_accept());
else
} else {
set_lang_by_user($lang);
}
}