Commit e5663daad2f0576027d69b63f4e577ac3e77d31a
1 parent
0ea21be4
Allow for language to be chosen on login, setting a cookie that will be
used from then on. Language names are registered by a plugin. Allow for plugins to be ordered, so that language plugins can set themselves up early on, so that later plugins can translate text to the language. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5142 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
65 additions
and
3 deletions
lib/i18n/i18n.inc.php
| ... | ... | @@ -36,6 +36,11 @@ class KTi18n { |
| 36 | 36 | $this->aLangDirectories = $aLangDirectories; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + function addLanguage($sLang, $sLocation) { | |
| 40 | + $this->aLangDirectories[$sLang] = $sLocation; | |
| 41 | + $this->sFilename = null; | |
| 42 | + } | |
| 43 | + | |
| 39 | 44 | function _generateLanguage() { |
| 40 | 45 | if (!empty($this->sLang)) { |
| 41 | 46 | return; |
| ... | ... | @@ -44,8 +49,10 @@ class KTi18n { |
| 44 | 49 | if ($this->sLang === false) { |
| 45 | 50 | return; |
| 46 | 51 | } |
| 52 | + | |
| 47 | 53 | global $default; |
| 48 | 54 | $this->sLang = $default->defaultLanguage; |
| 55 | + return; | |
| 49 | 56 | } |
| 50 | 57 | |
| 51 | 58 | function _generateFilePath() { |
| ... | ... | @@ -62,6 +69,11 @@ class KTi18n { |
| 62 | 69 | $sLocation = $this->sPath; |
| 63 | 70 | } |
| 64 | 71 | |
| 72 | + if ($sLocation === "default") { | |
| 73 | + $this->sFilename = false; | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + | |
| 65 | 77 | $aTry = array( |
| 66 | 78 | sprintf("%s/%s/%s", $sLocation, $this->sLang, $this->sDomain), |
| 67 | 79 | sprintf("%s/%s", $sLocation, $this->sDomain), |
| ... | ... | @@ -110,6 +122,7 @@ class KTi18n { |
| 110 | 122 | if (empty($this->sFilename)) { |
| 111 | 123 | return $sContents; |
| 112 | 124 | } |
| 125 | + | |
| 113 | 126 | return KTUtil::arrayGet($this->aStrings, $sContents, $sContents); |
| 114 | 127 | return dcgettext($this->sDomain, $sContents, LC_MESSAGES); |
| 115 | 128 | } | ... | ... |
lib/i18n/i18nregistry.inc.php
| ... | ... | @@ -32,10 +32,11 @@ class KTi18nRegistry { |
| 32 | 32 | var $_ai18nDetails = array(); |
| 33 | 33 | var $_ai18nLangs = array(); |
| 34 | 34 | var $_ai18ns = array(); |
| 35 | + var $_aLanguages = array(); | |
| 35 | 36 | |
| 36 | 37 | function &getSingleton() { |
| 37 | 38 | if (!KTUtil::arrayGet($GLOBALS, 'oKTi18nRegistry')) { |
| 38 | - $GLOBALS['oKTi18nRegistry'] = new KTi18nRegistry; | |
| 39 | + $GLOBALS['oKTi18nRegistry'] =& new KTi18nRegistry; | |
| 39 | 40 | } |
| 40 | 41 | return $GLOBALS['oKTi18nRegistry']; |
| 41 | 42 | } |
| ... | ... | @@ -53,9 +54,21 @@ class KTi18nRegistry { |
| 53 | 54 | } else { |
| 54 | 55 | $aLang = $sLang; |
| 55 | 56 | } |
| 57 | + $oi18n =& KTUtil::arrayGet($this->_ai18ns, $sDomain); | |
| 58 | + | |
| 56 | 59 | foreach ($aLang as $sLang) { |
| 57 | 60 | $this->_ai18nLangs[$sDomain][$sLang] = $sDirectory; |
| 61 | + if (!empty($oi18n)) { | |
| 62 | + $oi18n->addLanguage($sLang, $sDirectory); | |
| 63 | + } | |
| 58 | 64 | } |
| 65 | + if (!empty($oi18n)) { | |
| 66 | + $this->_ai18ns[$sDomain] =& $oi18n; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + function registerLanguage($sLanguage, $sLanguageName) { | |
| 71 | + $this->_aLanguages[$sLanguage] = $sLanguageName; | |
| 59 | 72 | } |
| 60 | 73 | |
| 61 | 74 | function &geti18n($sDomain) { |
| ... | ... | @@ -72,5 +85,13 @@ class KTi18nRegistry { |
| 72 | 85 | $this->_ai18ns[$sDomain] =& $oi18n; |
| 73 | 86 | return $oi18n; |
| 74 | 87 | } |
| 88 | + | |
| 89 | + function &geti18nLanguages($sDomain) { | |
| 90 | + return $this->_ai18nLangs[$sDomain]; | |
| 91 | + } | |
| 92 | + | |
| 93 | + function &getLanguages() { | |
| 94 | + return $this->_aLanguages; | |
| 95 | + } | |
| 75 | 96 | } |
| 76 | 97 | ... | ... |
lib/plugins/plugin.inc.php
| ... | ... | @@ -31,6 +31,7 @@ class KTPlugin { |
| 31 | 31 | var $sFilename = null; |
| 32 | 32 | var $bAlwaysInclude = false; |
| 33 | 33 | var $iVersion = 0; |
| 34 | + var $iOrder = 0; | |
| 34 | 35 | |
| 35 | 36 | var $autoRegister = false; |
| 36 | 37 | |
| ... | ... | @@ -44,6 +45,7 @@ class KTPlugin { |
| 44 | 45 | var $_aDashlets = array(); |
| 45 | 46 | var $_ai18n = array(); |
| 46 | 47 | var $_ai18nLang = array(); |
| 48 | + var $_aLanguage = array(); | |
| 47 | 49 | |
| 48 | 50 | function KTPlugin($sFilename = null) { |
| 49 | 51 | $this->sFilename = $sFilename; |
| ... | ... | @@ -114,8 +116,14 @@ class KTPlugin { |
| 114 | 116 | } |
| 115 | 117 | |
| 116 | 118 | function registeri18nLang($sDomain, $sLang, $sPath) { |
| 117 | - $sPath = $this->_fixFilename($sPath); | |
| 118 | - $this->_ai18nLang[$sDomain] = array($sDomain, $sLang, $sPath); | |
| 119 | + if ($sPath !== "default") { | |
| 120 | + $sPath = $this->_fixFilename($sPath); | |
| 121 | + } | |
| 122 | + $this->_ai18nLang["$sDomain/$sLang"] = array($sDomain, $sLang, $sPath); | |
| 123 | + } | |
| 124 | + | |
| 125 | + function registerLanguage($sLanguage, $sLanguageName) { | |
| 126 | + $this->_aLanguage[$sLanguage] = array($sLanguage, $sLanguageName); | |
| 119 | 127 | } |
| 120 | 128 | |
| 121 | 129 | function _fixFilename($sFilename) { |
| ... | ... | @@ -222,6 +230,10 @@ class KTPlugin { |
| 222 | 230 | foreach ($this->_ai18nLang as $k => $v) { |
| 223 | 231 | call_user_func_array(array(&$oi18nRegistry, 'registeri18nLang'), $v); |
| 224 | 232 | } |
| 233 | + | |
| 234 | + foreach ($this->_aLanguage as $k => $v) { | |
| 235 | + call_user_func_array(array(&$oi18nRegistry, 'registerLanguage'), $v); | |
| 236 | + } | |
| 225 | 237 | } |
| 226 | 238 | |
| 227 | 239 | function setup() { | ... | ... |
login.php
| ... | ... | @@ -57,6 +57,15 @@ class LoginPageDispatcher extends KTDispatcher { |
| 57 | 57 | |
| 58 | 58 | $errorMessage = KTUtil::arrayGet($_REQUEST, 'errorMessage'); |
| 59 | 59 | $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); |
| 60 | + | |
| 61 | + $oReg =& KTi18nregistry::getSingleton(); | |
| 62 | + $aRegisteredLangs = $oReg->geti18nLanguages('knowledgeTree'); | |
| 63 | + $aLanguageNames = $oReg->getLanguages('knowledgeTree'); | |
| 64 | + $aRegisteredLanguageNames = array(); | |
| 65 | + foreach (array_keys($aRegisteredLangs) as $sLang) { | |
| 66 | + $aRegisteredLanguageNames[$sLang] = $aLanguageNames[$sLang]; | |
| 67 | + } | |
| 68 | + $sLanguageSelect = $default->defaultLanguage; | |
| 60 | 69 | |
| 61 | 70 | $oTemplating =& KTTemplating::getSingleton(); |
| 62 | 71 | $oTemplate = $oTemplating->loadTemplate("ktcore/login"); |
| ... | ... | @@ -66,6 +75,8 @@ class LoginPageDispatcher extends KTDispatcher { |
| 66 | 75 | 'errorMessage' => $errorMessage, |
| 67 | 76 | 'redirect' => $redirect, |
| 68 | 77 | 'systemVersion' => $default->systemVersion, |
| 78 | + 'languages' => $aRegisteredLanguageNames, | |
| 79 | + 'selected_language' => $sLanguageSelect, | |
| 69 | 80 | ); |
| 70 | 81 | return $oTemplate->render($aTemplateData); |
| 71 | 82 | } |
| ... | ... | @@ -132,6 +143,11 @@ class LoginPageDispatcher extends KTDispatcher { |
| 132 | 143 | |
| 133 | 144 | // DEPRECATED initialise page-level authorisation array |
| 134 | 145 | $_SESSION["pageAccess"] = NULL; |
| 146 | + $language = KTUtil::arrayGet($_REQUEST, 'language'); | |
| 147 | + if (empty($language)) { | |
| 148 | + $language = $default->defaultLanguage; | |
| 149 | + } | |
| 150 | + setcookie("kt_language", $language, 2147483647, '/'); | |
| 135 | 151 | |
| 136 | 152 | // check for a location to forward to |
| 137 | 153 | if ($redirect !== null) { | ... | ... |