Browse Source

Adding user language selection

Alan Hardman 5 years ago
parent
commit
bb586a793e
10 changed files with 47 additions and 5 deletions
  1. 18 2
      app/controller/user.php
  2. 1 0
      app/dict/en.ini
  3. 1 0
      app/dict/es.ini
  4. 1 0
      app/dict/pt.ini
  5. 1 0
      app/dict/ru.ini
  6. 4 0
      app/model/user.php
  7. 11 0
      app/view/user/account.html
  8. 1 2
      db/14.12.11.sql
  9. 7 0
      db/14.12.21.sql
  10. 2 1
      db/database.sql

+ 18 - 2
app/controller/user.php

@@ -6,8 +6,17 @@ class User extends \Controller {
 
 	protected $_userId;
 
+	private $_languages;
+
 	public function __construct() {
 		$this->_userId = $this->_requireLogin();
+		$this->_languages = array(
+			"en" => \ISO::LC_en,
+			"en_GB" => \ISO::LC_en . " (Great Britain)",
+			"es" => \ISO::LC_es . " (Español)",
+			"pt" => \ISO::LC_pt . " (Português)",
+			"ru" => \ISO::LC_ru . " (Pу́сский Язы́к)",
+		);
 	}
 
 	public function index($f3, $params) {
@@ -97,9 +106,8 @@ class User extends \Controller {
 	public function account($f3, $params) {
 		$f3->set("title", "My Account");
 		$f3->set("menuitem", "user");
-
+		$f3->set("languages", $this->_languages);
 		$this->_loadThemes();
-
 		$this->_render("user/account.html");
 	}
 
@@ -156,6 +164,12 @@ class User extends \Controller {
 				$user->theme = $post["theme"];
 			}
 
+			if(empty($post["language"])) {
+				$user->language = null;
+			} else {
+				$user->language = $post["language"];
+			}
+
 			if(empty($error)) {
 				$f3->set("success", "Profile updated successfully.");
 			} else {
@@ -170,6 +184,8 @@ class User extends \Controller {
 
 		// Use new user values for page
 		$user->loadCurrent();
+
+		$f3->set("languages", $this->_languages);
 		$this->_loadThemes();
 
 		$this->_render("user/account.html");

+ 1 - 0
app/dict/en.ini

@@ -73,6 +73,7 @@ dict.issue_tree="Issue Tree"
 ; Account
 dict.name="Name"
 dict.theme="Theme"
+dict.language="Language"
 dict.task_color="Task Color"
 dict.avatar="Avatar"
 dict.edit_on_gravatar="Edit on Gravatar"

+ 1 - 0
app/dict/es.ini

@@ -74,6 +74,7 @@ dict.issue_tree="Árbol de peticiónes"
 dict.name="Nombre"
 dict.theme="Petición"
 dict.task_color="Mi color"
+dict.language="Idioma"
 dict.avatar="Imagen de mí"
 dict.edit_on_gravatar="Editar en Gravatar"
 dict.save="Guardar"

+ 1 - 0
app/dict/pt.ini

@@ -74,6 +74,7 @@ dict.issue_tree="Árvore de Problemas"
 dict.name="Nome"
 dict.theme="Estilo"
 dict.task_color="Cor Tarefa"
+dict.language="Língua"
 dict.avatar="Avatar"
 dict.edit_on_gravatar="Editar na Gravatar"
 dict.save="Salvar"

+ 1 - 0
app/dict/ru.ini

@@ -70,6 +70,7 @@ dict.assigned_issues="Назначеные Запросы"
 dict.name="Имя"
 dict.theme="Тема"
 dict.task_color="Цвет Задач"
+dict.language="Язык"
 dict.avatar="Аватар"
 dict.edit_on_gravatar="Редактировать из Gravatar"
 dict.save="Сохранить"

+ 4 - 0
app/model/user.php

@@ -19,6 +19,10 @@ class User extends \Model {
 			if($this->id) {
 				$f3->set("user", $this->cast());
 				$f3->set("user_obj", $this);
+				// Change default language if user has selected one
+				if($this->language) {
+					$f3->set("LANGUAGE", $f3->get("user.language"));
+				}
 			}
 		}
 		return $this;

+ 11 - 0
app/view/user/account.html

@@ -39,6 +39,17 @@
 							</div>
 						</div>
 						<div class="form-group">
+							<label for="npass" class="col-sm-2 control-label label-sm">{{ @dict.language }}</label>
+							<div class="col-sm-4 col-md-2 col-lg-2">
+								<select name="language" class="form-control input-sm">
+									<option value="">[ Default ]</option>
+									<repeat group="{{ @languages }}" key="{{ @key }}" value="{{ @item }}">
+										<option value="{{ @key }}" {{ (@user.language == @key) ? 'selected' : '' }}>{{ @item }}</option>
+									</repeat>
+								</select>
+							</div>
+						</div>
+						<div class="form-group">
 							<label for="npass" class="col-sm-2 control-label label-sm">{{ @dict.task_color }}</label>
 							<div class="col-sm-4 col-md-2 col-lg-2">
 								<input class="form-control input-sm" id="color" name="task_color" type="color" value="{{ @user.task_color ? '#' . @user.task_color : '' }}">

+ 1 - 2
db/14.12.11.sql

@@ -1,8 +1,7 @@
 # This database update occured after commit f7c42f23b8
 
 # Add Version checking to the database
-DROP TABLE IF EXISTS `config`;
-CREATE TABLE `config` (
+CREATE TABLE IF NOT EXISTS `config` (
   `id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
   `attribute` varchar(255)  NULL,
   `value` varchar(255)  NULL,

+ 7 - 0
db/14.12.21.sql

@@ -0,0 +1,7 @@
+# This database update occured after commit 58697b3b04
+
+# Add language field to users
+ALTER TABLE `user` ADD COLUMN `language` VARCHAR(5) NULL AFTER `theme`;
+
+# Update Version
+UPDATE `config` SET `value` = '14.12.21' WHERE `attribute` = 'version';

+ 2 - 1
db/database.sql

@@ -13,6 +13,7 @@ CREATE TABLE `user` (
 	`role` enum('user','admin','group') NOT NULL DEFAULT 'user',
 	`task_color` char(6) DEFAULT NULL,
 	`theme` varchar(64) DEFAULT NULL,
+	`language` varchar(5) DEFAULT NULL,
 	`avatar_filename` varchar(64) DEFAULT NULL,
 	`api_key` varchar(40) NULL,
 	`created_date` datetime NOT NULL,
@@ -271,4 +272,4 @@ CREATE TABLE `config` (
   UNIQUE KEY `attribute` (`attribute`)
 ) ;
 
-INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '14.12.11');
+INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '14.12.21');