adding configuration option to set a default language and/or force it,
resolves #39
This commit is contained in:
parent
ca07398b66
commit
e3f4aa982c
@ -48,6 +48,10 @@ base64version = "2.1.9"
|
|||||||
; a session cookie to store the choice until the browser is closed.
|
; a session cookie to store the choice until the browser is closed.
|
||||||
languageselection = false
|
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]
|
||||||
; expire value that is selected per default
|
; expire value that is selected per default
|
||||||
; make sure the value exists in [expire_options]
|
; make sure the value exists in [expire_options]
|
||||||
|
@ -43,6 +43,7 @@ class configuration
|
|||||||
'notice' => '',
|
'notice' => '',
|
||||||
'base64version' => '2.1.9',
|
'base64version' => '2.1.9',
|
||||||
'languageselection' => false,
|
'languageselection' => false,
|
||||||
|
'languagedefault' => '',
|
||||||
),
|
),
|
||||||
'expire' => array(
|
'expire' => array(
|
||||||
'default' => '1week',
|
'default' => '1week',
|
||||||
|
25
lib/i18n.php
25
lib/i18n.php
@ -26,6 +26,15 @@ class i18n
|
|||||||
*/
|
*/
|
||||||
protected static $_language = 'en';
|
protected static $_language = 'en';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* language fallback
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @static
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $_languageFallback = 'en';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* language labels
|
* language labels
|
||||||
*
|
*
|
||||||
@ -248,6 +257,20 @@ class i18n
|
|||||||
return array_intersect_key(self::$_languageLabels, array_flip($languages));
|
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
|
* get language file path
|
||||||
*
|
*
|
||||||
@ -339,7 +362,7 @@ class i18n
|
|||||||
}
|
}
|
||||||
if (count($matches) === 0)
|
if (count($matches) === 0)
|
||||||
{
|
{
|
||||||
return 'en';
|
return self::$_languageFallback;
|
||||||
}
|
}
|
||||||
krsort($matches);
|
krsort($matches);
|
||||||
$topmatches = current($matches);
|
$topmatches = current($matches);
|
||||||
|
@ -185,6 +185,16 @@ class zerobin
|
|||||||
$this->_model = new model($this->_conf);
|
$this->_model = new model($this->_conf);
|
||||||
$this->_request = new request;
|
$this->_request = new request;
|
||||||
$this->_urlbase = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : '/';
|
$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'));
|
$page->draw($this->_conf->getKey('template'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* outputs requested JSON-LD context
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @param string $type
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
private function _jsonld($type)
|
private function _jsonld($type)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
@ -475,7 +492,7 @@ class zerobin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return JSON encoded message and exit
|
* prepares JSON encoded status message
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param bool $status
|
* @param bool $status
|
||||||
|
Loading…
Reference in New Issue
Block a user