summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-07 18:05:33 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-07 18:05:33 -0400
commit55ee906ba36cf66c3a390c98dde75e241de26e65 (patch)
treeed4e5419bb6254c97d63d6a5cab5ab74536201a0 /app/Model
parentaac11a609c58ec8356e1ca479da456876034b06c (diff)
Added support for language LDAP attribute
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Config.php170
-rw-r--r--app/Model/Language.php178
-rw-r--r--app/Model/Timezone.php56
-rw-r--r--app/Model/UserNotification.php2
4 files changed, 237 insertions, 169 deletions
diff --git a/app/Model/Config.php b/app/Model/Config.php
index 0c363fb0..1b14efa1 100644
--- a/app/Model/Config.php
+++ b/app/Model/Config.php
@@ -2,7 +2,6 @@
namespace Kanboard\Model;
-use Kanboard\Core\Translator;
use Kanboard\Core\Security\Token;
/**
@@ -14,162 +13,7 @@ use Kanboard\Core\Security\Token;
class Config extends Setting
{
/**
- * Get available timezones
- *
- * @access public
- * @param boolean $prepend Prepend a default value
- * @return array
- */
- public function getTimezones($prepend = false)
- {
- $timezones = timezone_identifiers_list();
- $listing = array_combine(array_values($timezones), $timezones);
-
- if ($prepend) {
- return array('' => t('Application default')) + $listing;
- }
-
- return $listing;
- }
-
- /**
- * Get current timezone
- *
- * @access public
- * @return string
- */
- public function getCurrentTimezone()
- {
- if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
- return $this->sessionStorage->user['timezone'];
- }
-
- return $this->get('application_timezone', 'UTC');
- }
-
- /**
- * Set timezone
- *
- * @access public
- */
- public function setupTimezone()
- {
- date_default_timezone_set($this->getCurrentTimezone());
- }
-
- /**
- * Get available languages
- *
- * @access public
- * @param boolean $prepend Prepend a default value
- * @return array
- */
- public function getLanguages($prepend = false)
- {
- // Sorted by value
- $languages = array(
- 'id_ID' => 'Bahasa Indonesia',
- 'bs_BA' => 'Bosanski',
- 'cs_CZ' => 'Čeština',
- 'da_DK' => 'Dansk',
- 'de_DE' => 'Deutsch',
- 'en_US' => 'English',
- 'es_ES' => 'Español',
- 'fr_FR' => 'Français',
- 'el_GR' => 'Grec',
- 'it_IT' => 'Italiano',
- 'hu_HU' => 'Magyar',
- 'my_MY' => 'Melayu',
- 'nl_NL' => 'Nederlands',
- 'nb_NO' => 'Norsk',
- 'pl_PL' => 'Polski',
- 'pt_PT' => 'Português',
- 'pt_BR' => 'Português (Brasil)',
- 'ru_RU' => 'Русский',
- 'sr_Latn_RS' => 'Srpski',
- 'fi_FI' => 'Suomi',
- 'sv_SE' => 'Svenska',
- 'tr_TR' => 'Türkçe',
- 'ko_KR' => '한국어',
- 'zh_CN' => '中文(简体)',
- 'ja_JP' => '日本語',
- 'th_TH' => 'ไทย',
- );
-
- if ($prepend) {
- return array('' => t('Application default')) + $languages;
- }
-
- return $languages;
- }
-
- /**
- * Get javascript language code
- *
- * @access public
- * @return string
- */
- public function getJsLanguageCode()
- {
- $languages = array(
- 'cs_CZ' => 'cs',
- 'da_DK' => 'da',
- 'de_DE' => 'de',
- 'en_US' => 'en',
- 'es_ES' => 'es',
- 'fr_FR' => 'fr',
- 'it_IT' => 'it',
- 'hu_HU' => 'hu',
- 'nl_NL' => 'nl',
- 'nb_NO' => 'nb',
- 'pl_PL' => 'pl',
- 'pt_PT' => 'pt',
- 'pt_BR' => 'pt-br',
- 'ru_RU' => 'ru',
- 'sr_Latn_RS' => 'sr',
- 'fi_FI' => 'fi',
- 'sv_SE' => 'sv',
- 'tr_TR' => 'tr',
- 'ko_KR' => 'ko',
- 'zh_CN' => 'zh-cn',
- 'ja_JP' => 'ja',
- 'th_TH' => 'th',
- 'id_ID' => 'id',
- 'el_GR' => 'el',
- );
-
- $lang = $this->getCurrentLanguage();
-
- return isset($languages[$lang]) ? $languages[$lang] : 'en';
- }
-
- /**
- * Get current language
- *
- * @access public
- * @return string
- */
- public function getCurrentLanguage()
- {
- if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) {
- return $this->sessionStorage->user['language'];
- }
-
- return $this->get('application_language', 'en_US');
- }
-
- /**
- * Load translations
- *
- * @access public
- */
- public function setupTranslations()
- {
- Translator::load($this->getCurrentLanguage());
- }
-
- /**
- * Get a config variable from the session or the database
+ * Get a config variable with in-memory caching
*
* @access public
* @param string $name Parameter name
@@ -183,16 +27,6 @@ class Config extends Setting
}
/**
- * Reload settings in the session and the translations
- *
- * @access public
- */
- public function reload()
- {
- $this->setupTranslations();
- }
-
- /**
* Optimize the Sqlite database
*
* @access public
@@ -200,7 +34,7 @@ class Config extends Setting
*/
public function optimizeDatabase()
{
- return $this->db->getconnection()->exec('VACUUM');
+ return $this->db->getConnection()->exec('VACUUM');
}
/**
diff --git a/app/Model/Language.php b/app/Model/Language.php
new file mode 100644
index 00000000..441771e0
--- /dev/null
+++ b/app/Model/Language.php
@@ -0,0 +1,178 @@
+<?php
+
+namespace Kanboard\Model;
+
+use Kanboard\Core\Translator;
+
+/**
+ * Class Language
+ *
+ * @package Kanboard\Model
+ * @author Frederic Guillot
+ */
+class Language extends Base
+{
+ /**
+ * Get all language codes
+ *
+ * @static
+ * @access public
+ * @return string[]
+ */
+ public static function getCodes()
+ {
+ return array(
+ 'id_ID',
+ 'bs_BA',
+ 'cs_CZ',
+ 'da_DK',
+ 'de_DE',
+ 'en_US',
+ 'es_ES',
+ 'fr_FR',
+ 'el_GR',
+ 'it_IT',
+ 'hu_HU',
+ 'my_MY',
+ 'nl_NL',
+ 'nb_NO',
+ 'pl_PL',
+ 'pt_PT',
+ 'pt_BR',
+ 'ru_RU',
+ 'sr_Latn_RS',
+ 'fi_FI',
+ 'sv_SE',
+ 'tr_TR',
+ 'ko_KR',
+ 'zh_CN',
+ 'ja_JP',
+ 'th_TH',
+ );
+ }
+
+ /**
+ * Find language code
+ *
+ * @static
+ * @access public
+ * @param string $code
+ * @return string
+ */
+ public static function findCode($code)
+ {
+ $code = str_replace('-', '_', $code);
+ return in_array($code, self::getCodes()) ? $code : '';
+ }
+
+ /**
+ * Get available languages
+ *
+ * @access public
+ * @param boolean $prepend Prepend a default value
+ * @return array
+ */
+ public function getLanguages($prepend = false)
+ {
+ // Sorted by value
+ $languages = array(
+ 'id_ID' => 'Bahasa Indonesia',
+ 'bs_BA' => 'Bosanski',
+ 'cs_CZ' => 'Čeština',
+ 'da_DK' => 'Dansk',
+ 'de_DE' => 'Deutsch',
+ 'en_US' => 'English',
+ 'es_ES' => 'Español',
+ 'fr_FR' => 'Français',
+ 'el_GR' => 'Grec',
+ 'it_IT' => 'Italiano',
+ 'hu_HU' => 'Magyar',
+ 'my_MY' => 'Melayu',
+ 'nl_NL' => 'Nederlands',
+ 'nb_NO' => 'Norsk',
+ 'pl_PL' => 'Polski',
+ 'pt_PT' => 'Português',
+ 'pt_BR' => 'Português (Brasil)',
+ 'ru_RU' => 'Русский',
+ 'sr_Latn_RS' => 'Srpski',
+ 'fi_FI' => 'Suomi',
+ 'sv_SE' => 'Svenska',
+ 'tr_TR' => 'Türkçe',
+ 'ko_KR' => '한국어',
+ 'zh_CN' => '中文(简体)',
+ 'ja_JP' => '日本語',
+ 'th_TH' => 'ไทย',
+ );
+
+ if ($prepend) {
+ return array('' => t('Application default')) + $languages;
+ }
+
+ return $languages;
+ }
+
+ /**
+ * Get javascript language code
+ *
+ * @access public
+ * @return string
+ */
+ public function getJsLanguageCode()
+ {
+ $languages = array(
+ 'cs_CZ' => 'cs',
+ 'da_DK' => 'da',
+ 'de_DE' => 'de',
+ 'en_US' => 'en',
+ 'es_ES' => 'es',
+ 'fr_FR' => 'fr',
+ 'it_IT' => 'it',
+ 'hu_HU' => 'hu',
+ 'nl_NL' => 'nl',
+ 'nb_NO' => 'nb',
+ 'pl_PL' => 'pl',
+ 'pt_PT' => 'pt',
+ 'pt_BR' => 'pt-br',
+ 'ru_RU' => 'ru',
+ 'sr_Latn_RS' => 'sr',
+ 'fi_FI' => 'fi',
+ 'sv_SE' => 'sv',
+ 'tr_TR' => 'tr',
+ 'ko_KR' => 'ko',
+ 'zh_CN' => 'zh-cn',
+ 'ja_JP' => 'ja',
+ 'th_TH' => 'th',
+ 'id_ID' => 'id',
+ 'el_GR' => 'el',
+ );
+
+ $lang = $this->getCurrentLanguage();
+
+ return isset($languages[$lang]) ? $languages[$lang] : 'en';
+ }
+
+ /**
+ * Get current language
+ *
+ * @access public
+ * @return string
+ */
+ public function getCurrentLanguage()
+ {
+ if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) {
+ return $this->sessionStorage->user['language'];
+ }
+
+ return $this->config->get('application_language', 'en_US');
+ }
+
+ /**
+ * Load translations for the current language
+ *
+ * @access public
+ */
+ public function loadCurrentLanguage()
+ {
+ Translator::load($this->getCurrentLanguage());
+ }
+}
diff --git a/app/Model/Timezone.php b/app/Model/Timezone.php
new file mode 100644
index 00000000..c6b33736
--- /dev/null
+++ b/app/Model/Timezone.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Kanboard\Model;
+
+/**
+ * Class Timezone
+ *
+ * @package Kanboard\Model
+ * @author Frederic Guillot
+ */
+class Timezone extends Base
+{
+ /**
+ * Get available timezones
+ *
+ * @access public
+ * @param boolean $prepend Prepend a default value
+ * @return array
+ */
+ public function getTimezones($prepend = false)
+ {
+ $timezones = timezone_identifiers_list();
+ $listing = array_combine(array_values($timezones), $timezones);
+
+ if ($prepend) {
+ return array('' => t('Application default')) + $listing;
+ }
+
+ return $listing;
+ }
+
+ /**
+ * Get current timezone
+ *
+ * @access public
+ * @return string
+ */
+ public function getCurrentTimezone()
+ {
+ if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
+ return $this->sessionStorage->user['timezone'];
+ }
+
+ return $this->config->get('application_timezone', 'UTC');
+ }
+
+ /**
+ * Set timezone
+ *
+ * @access public
+ */
+ public function setCurrentTimezone()
+ {
+ date_default_timezone_set($this->getCurrentTimezone());
+ }
+}
diff --git a/app/Model/UserNotification.php b/app/Model/UserNotification.php
index 7795da2e..fcd1761b 100644
--- a/app/Model/UserNotification.php
+++ b/app/Model/UserNotification.php
@@ -54,7 +54,7 @@ class UserNotification extends Base
}
// Restore locales
- $this->config->setupTranslations();
+ $this->language->loadCurrentLanguage();
}
/**