adding configuration option to set a default language and/or force it,

resolves #39
pull/17/head
El RIDO 9 years ago
parent ca07398b66
commit e3f4aa982c

@ -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]

@ -43,6 +43,7 @@ class configuration
'notice' => '',
'base64version' => '2.1.9',
'languageselection' => false,
'languagedefault' => '',
),
'expire' => array(
'default' => '1week',

@ -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);

@ -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

Loading…
Cancel
Save