Updates for v9.0 release
This commit is contained in:
@@ -29,9 +29,9 @@ namespace CoreLibs\Language\Core;
|
||||
class CachedFileReader extends \CoreLibs\Language\Core\StringReader
|
||||
{
|
||||
/** @var int */
|
||||
public $error = 0;
|
||||
public int $error = 0;
|
||||
/** @var string */
|
||||
public $fd_str = '';
|
||||
public string $fd_str = '';
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace CoreLibs\Language\Core;
|
||||
class FileReader
|
||||
{
|
||||
/** @var int */
|
||||
public $fr_pos;
|
||||
public int $fr_pos;
|
||||
/** @var resource|bool */
|
||||
public $fr_fd;
|
||||
public mixed $fr_fd; // no resource type yet
|
||||
/** @var int */
|
||||
public $fr_length;
|
||||
public int $fr_length;
|
||||
/** @var int */
|
||||
public $error = 0;
|
||||
public int $error = 0;
|
||||
|
||||
/**
|
||||
* file read constructor
|
||||
|
||||
@@ -41,31 +41,31 @@ class GetTextReader
|
||||
{
|
||||
// public:
|
||||
/** @var int */
|
||||
public $error = 0; // public variable that holds error code (0 if no error)
|
||||
public int $error = 0; // public variable that holds error code (0 if no error)
|
||||
|
||||
// private:
|
||||
/** @var int */
|
||||
private $BYTEORDER = 0; // 0: low endian, 1: big endian
|
||||
private int $BYTEORDER = 0; // 0: low endian, 1: big endian
|
||||
/** @var FileReader */
|
||||
private $STREAM;
|
||||
private FileReader $STREAM;
|
||||
/** @var bool */
|
||||
private $short_circuit = false;
|
||||
private bool $short_circuit = false;
|
||||
/** @var bool */
|
||||
private $enable_cache = false;
|
||||
private bool $enable_cache = false;
|
||||
/** @var int */
|
||||
private $originals = 0; // offset of original table
|
||||
private int $originals = 0; // offset of original table
|
||||
/** @var int */
|
||||
private $translations = 0; // offset of translation table
|
||||
private int $translations = 0; // offset of translation table
|
||||
/** @var string */
|
||||
private $pluralheader = ''; // cache header field for plural forms
|
||||
private string $pluralheader = ''; // cache header field for plural forms
|
||||
/** @var int */
|
||||
private $total = 0; // total string count
|
||||
private int $total = 0; // total string count
|
||||
/** @var array<mixed>|null */
|
||||
private $table_originals = null; // table for original strings (offsets)
|
||||
private array|null $table_originals = null; // table for original strings (offsets)
|
||||
/** @var array<mixed>|null */
|
||||
private $table_translations = null; // table for translated strings (offsets)
|
||||
private array|null $table_translations = null; // table for translated strings (offsets)
|
||||
/** @var array<mixed> */
|
||||
private $cache_translations = []; // original -> translation mapping
|
||||
private array $cache_translations = []; // original -> translation mapping
|
||||
|
||||
/* Methods */
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace CoreLibs\Language\Core;
|
||||
class StringReader
|
||||
{
|
||||
/** @var int */
|
||||
public $sr_pos;
|
||||
public int $sr_pos;
|
||||
/** @var string */
|
||||
public $sr_str;
|
||||
public string $sr_str;
|
||||
|
||||
/**
|
||||
* constructor for string reader
|
||||
|
||||
@@ -35,42 +35,42 @@ class L10n
|
||||
/** @var string the default fallback encoding if nothing is set */
|
||||
public const DEFAULT_CHARSET = 'UTF-8';
|
||||
/** @var string the current locale */
|
||||
private $locale = '';
|
||||
private string $locale = '';
|
||||
/** @var string the SET locale as WHERE the domain file is */
|
||||
private $locale_set = '';
|
||||
private string $locale_set = '';
|
||||
/** @var string the default selected/active domain */
|
||||
private $domain = '';
|
||||
private string $domain = '';
|
||||
/** @var string encoding, as from locale or set from outside */
|
||||
private $override_encoding = self::DEFAULT_CHARSET;
|
||||
private string $override_encoding = self::DEFAULT_CHARSET;
|
||||
/** @var string encoding set during the parse Locale */
|
||||
private $encoding = '';
|
||||
private string $encoding = '';
|
||||
/** @var array<string,array<string,GetTextReader>> locale > domain = translator */
|
||||
private $domains = [];
|
||||
private array $domains = [];
|
||||
/** @var array<string,string> bound paths for domains */
|
||||
private $paths = ['' => './'];
|
||||
private array $paths = ['' => './'];
|
||||
|
||||
// files
|
||||
/** @var string the full path to the mo file to loaded */
|
||||
private $mofile = '';
|
||||
private string $mofile = '';
|
||||
/** @var string base path to search level */
|
||||
private $base_locale_path = '';
|
||||
private string $base_locale_path = '';
|
||||
/** @var string dynamic set path to where the mo file is actually */
|
||||
private $base_content_path = '';
|
||||
private string $base_content_path = '';
|
||||
|
||||
// errors
|
||||
/** @var bool if load of mo file was unsuccessful */
|
||||
private $load_failure = false;
|
||||
private bool $load_failure = false;
|
||||
|
||||
// object holders
|
||||
/** @var FileReader|bool reader class for file reading, false for short circuit */
|
||||
private $input = false;
|
||||
private FileReader|bool $input = false;
|
||||
/** @var GetTextReader reader class for MO data */
|
||||
private $l10n;
|
||||
private GetTextReader|null $l10n = null;
|
||||
/**
|
||||
* @static
|
||||
* @var L10n self class
|
||||
*/
|
||||
private static $instance;
|
||||
private static L10n $instance;
|
||||
|
||||
/**
|
||||
* class constructor call for language getstring
|
||||
@@ -124,7 +124,6 @@ class L10n
|
||||
*/
|
||||
public static function getInstance(): L10n
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (empty(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
@@ -253,6 +252,13 @@ class L10n
|
||||
// dummy
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
}
|
||||
// if this is still null here, we abort
|
||||
if ($this->l10n === null) {
|
||||
throw new \Exception(
|
||||
"Could not create CoreLibs\Language\Core\GetTextReader object",
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
@@ -673,6 +679,7 @@ class L10n
|
||||
// fallback passthrough
|
||||
if ($this->l10n === null) {
|
||||
echo $text;
|
||||
return;
|
||||
}
|
||||
echo $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user