diff --git a/cfg/conf.ini b/cfg/conf.ini index 28476fb7..41c63382 100644 --- a/cfg/conf.ini +++ b/cfg/conf.ini @@ -48,6 +48,10 @@ base64version = "2.1.9" ; a session cookie to store the choice until the browser is closed. languageselection = false +; set the language your installs defaults to, defaults to English +; if this is set and language selection is disabled, this will be the only language +; languagedefault = "en" + [expire] ; expire value that is selected per default ; make sure the value exists in [expire_options] diff --git a/lib/configuration.php b/lib/configuration.php index 11e062bc..2549eb1b 100644 --- a/lib/configuration.php +++ b/lib/configuration.php @@ -43,6 +43,7 @@ class configuration 'notice' => '', 'base64version' => '2.1.9', 'languageselection' => false, + 'languagedefault' => '', ), 'expire' => array( 'default' => '1week', diff --git a/lib/i18n.php b/lib/i18n.php index 500a9664..5eb2b5e3 100644 --- a/lib/i18n.php +++ b/lib/i18n.php @@ -26,6 +26,15 @@ class i18n */ protected static $_language = 'en'; + /** + * language fallback + * + * @access protected + * @static + * @var string + */ + protected static $_languageFallback = 'en'; + /** * language labels * @@ -248,6 +257,20 @@ class i18n return array_intersect_key(self::$_languageLabels, array_flip($languages)); } + /** + * set the default language + * + * @access public + * @static + * @param string $lang + * @return void + */ + public static function setLanguageFallback($lang) + { + if (in_array($lang, self::getAvailableLanguages())) + self::$_languageFallback = $lang; + } + /** * get language file path * @@ -339,7 +362,7 @@ class i18n } if (count($matches) === 0) { - return 'en'; + return self::$_languageFallback; } krsort($matches); $topmatches = current($matches); diff --git a/lib/zerobin.php b/lib/zerobin.php index f94bc495..a9916503 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -185,6 +185,16 @@ class zerobin $this->_model = new model($this->_conf); $this->_request = new request; $this->_urlbase = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : '/'; + + // set default language + $lang = $this->_conf->getKey('languagedefault'); + i18n::setLanguageFallback($lang); + // force default language, if language selection is disabled and a default is set + if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) + { + $_COOKIE['lang'] = $lang; + setcookie('lang', $lang); + } } /** @@ -448,6 +458,13 @@ class zerobin $page->draw($this->_conf->getKey('template')); } + /** + * outputs requested JSON-LD context + * + * @access private + * @param string $type + * @return void + */ private function _jsonld($type) { if ( @@ -475,7 +492,7 @@ class zerobin } /** - * return JSON encoded message and exit + * prepares JSON encoded status message * * @access private * @param bool $status