$this->loginError = '<p>An unknown error has been received:</p><pre>' . print_r($reply, true) . '</pre><p>Please notify technical support about this new error message, so we can handle it in the future.</p>';
use Waystone\Workspaces\Engines\Controller\LoadableWithContext;
use Waystone\Workspaces\Engines\Framework\Context;
+use Smarty\Smarty;
+
+use InvalidArgumentException;
+
/**
* Language services
*/
class Language implements LoadableWithContext {
///
/// Properties
///
/**
* @var
*/
const FALLBACK = 'en';
/**
* @var Smarty the template engine
*/
private $templateEngine;
///
/// Singleton pattern. Constructor.
///
/**
* @var Language The loaded Language instance
*/
private static $instance;
/**
* Loads an instance of the class
*
* @param ?Context $context The context
* @return Language An instance of the Language class
*/
public static function Load (?Context $context = null) {
if (static::$instance === null) {
//Initializes an instance
if ($context === null) {
throw new InvalidArgumentException("A context is required to load this class for the first time.");
}
if ($context->templateEngine === null) {
throw new InvalidArgumentException("A context is required to load this class for the first time. You provided one, but the template engine isn't initiliazed. This is required, as the languages files are managed by the template engine.");
}
static::$instance = new static($context->templateEngine);
}
return static::$instance;
}
/**
* Initializes a new instance of the Language class
*/
public function __construct ($templateEngine) {
$this->templateEngine = $templateEngine;
}
///
/// Static helper methods
///
/**
* Defines the LANG constant, to lang to print
*
* This information is contained in the session, or if not yet defined,
* it's to determine according the user's browser preferences.
* @see findLanguage
*/
public static function initialize () {
//If $_SESSION['lang'] doesn't exist yet, find a common language
if (!array_key_exists('lang', $_SESSION)) {
$lang = static::findLanguage();
$_SESSION['lang'] = $lang ? $lang : '-';
}
if ($_SESSION['lang'] != '-') {
define('LANG', $_SESSION['lang']);
}
}
/**
* Gets a common lang spoken by the site and the user's browser
- * @see Language::getHttpAcceptLanguages
*
* @return string the language
+ * @see Language::getHttpAcceptLanguages
+ *
*/
public static function findLanguage () {
if (file_exists('lang') && is_dir('lang')) {
//Gets lang/ subdirectories: this is the list of available languages
if (array_key_exists(MESSAGE_FALLBACK_LANG, $this->localizations)) {
trigger_error("Ignored file: $filename.txt, as $filename-" . MESSAGE_FALLBACK_LANG . ".txt already exists and is used for fallback purpose", E_USER_NOTICE);
return;
}
trigger_error("You have $filename.txt and $filename-<lang>.txt files; you should have one or the other, but not both", E_USER_NOTICE);