diff --git a/composer.json b/composer.json index 5e86c880826a8..5debe9419734e 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,7 @@ "joomla/filesystem": "~3.0.x-dev", "joomla/http": "~3.0.x-dev", "joomla/input": "~3.0.x-dev", + "joomla/language": "~3.0.x-dev", "joomla/oauth1": "~3.0.x-dev", "joomla/oauth2": "~3.0.x-dev", "joomla/registry": "~3.0.x-dev", diff --git a/composer.lock b/composer.lock index 45d2c8eab81d2..967cdb180d9b3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "37c1e684fbbfd1311e0fa7d37a3d7460", + "content-hash": "56e69f88a12f4a9b79df0331e7f56270", "packages": [ { "name": "algo26-matthias/idna-convert", @@ -1857,6 +1857,77 @@ ], "time": "2023-04-19T11:50:38+00:00" }, + { + "name": "joomla/language", + "version": "dev-3.x-dev", + "source": { + "type": "git", + "url": "https://github.com/joomla-framework/language.git", + "reference": "aadf23374f38fd3157b66a6de2f71ae19e405798" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/joomla-framework/language/zipball/aadf23374f38fd3157b66a6de2f71ae19e405798", + "reference": "aadf23374f38fd3157b66a6de2f71ae19e405798", + "shasum": "" + }, + "require": { + "ext-xml": "*", + "joomla/string": "3.0.x-dev", + "php": "^8.1.0", + "symfony/deprecation-contracts": "^2|^3" + }, + "require-dev": { + "joomla/di": "3.0.x-dev", + "joomla/registry": "3.0.x-dev", + "joomla/test": "3.0.x-dev", + "phan/phan": "^5.4.2", + "phpstan/phpstan": "^1.10.7", + "phpunit/phpunit": "^9.5.28", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "suggest": { + "joomla/di": "To use the Language ServiceProviderInterface objects, install joomla/di." + }, + "type": "joomla-package", + "extra": { + "branch-alias": { + "dev-2.0-dev": "2.0-dev", + "dev-3.x-dev": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Joomla\\Language\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Joomla Language Package", + "homepage": "https://github.com/joomla-framework/language", + "keywords": [ + "framework", + "joomla", + "language" + ], + "support": { + "issues": "https://github.com/joomla-framework/language/issues", + "source": "https://github.com/joomla-framework/language/tree/3.x-dev" + }, + "funding": [ + { + "url": "https://community.joomla.org/sponsorship-campaigns.html", + "type": "custom" + }, + { + "url": "https://github.com/joomla", + "type": "github" + } + ], + "time": "2023-04-19T11:42:22+00:00" + }, { "name": "joomla/oauth1", "version": "dev-3.x-dev", @@ -10036,6 +10107,7 @@ "joomla/filesystem": 20, "joomla/http": 20, "joomla/input": 20, + "joomla/language": 20, "joomla/oauth1": 20, "joomla/oauth2": 20, "joomla/registry": 20, diff --git a/libraries/src/Language/Language.php b/libraries/src/Language/Language.php index 7c5e6d05e9c68..fff1c1d7cf7df 100644 --- a/libraries/src/Language/Language.php +++ b/libraries/src/Language/Language.php @@ -10,6 +10,7 @@ namespace Joomla\CMS\Language; use Joomla\CMS\Factory; +use Joomla\Language\Language as BaseLanguage; use Joomla\String\StringHelper; // phpcs:disable PSR1.Files.SideEffects @@ -21,7 +22,7 @@ * * @since 1.7.0 */ -class Language +class Language extends BaseLanguage { /** * Array of Language objects @@ -31,70 +32,6 @@ class Language */ protected static $languages = []; - /** - * Debug language, If true, highlights if string isn't found. - * - * @var boolean - * @since 1.7.0 - */ - protected $debug = false; - - /** - * The default language, used when a language file in the requested language does not exist. - * - * @var string - * @since 1.7.0 - */ - protected $default = 'en-GB'; - - /** - * An array of orphaned text. - * - * @var array - * @since 1.7.0 - */ - protected $orphans = []; - - /** - * Array holding the language metadata. - * - * @var array - * @since 1.7.0 - */ - protected $metadata = null; - - /** - * Array holding the language locale or boolean null if none. - * - * @var array|boolean - * @since 1.7.0 - */ - protected $locale = null; - - /** - * The language to load. - * - * @var string - * @since 1.7.0 - */ - protected $lang = null; - - /** - * A nested array of language files that have been loaded - * - * @var array - * @since 1.7.0 - */ - protected $paths = []; - - /** - * List of language files that are in error state - * - * @var array - * @since 1.7.0 - */ - protected $errorfiles = []; - /** * Translations * @@ -103,30 +40,6 @@ class Language */ protected $strings = []; - /** - * An array of used text, used during debugging. - * - * @var array - * @since 1.7.0 - */ - protected $used = []; - - /** - * Counter for number of loads. - * - * @var integer - * @since 1.7.0 - */ - protected $counter = 0; - - /** - * An array used to store overrides. - * - * @var array - * @since 1.7.0 - */ - protected $override = []; - /** * Name of the transliterator function for this language. * @@ -782,7 +695,7 @@ protected function parse($fileName) * @since 3.6.3 * @throws \InvalidArgumentException */ - public function debugFile($filename) + public function debugFile(string $filename): int { // Make sure our file actually exists if (!is_file($filename)) { @@ -857,25 +770,6 @@ public function debugFile($filename) return \count($errors); } - /** - * Get a metadata language property. - * - * @param string $property The name of the property. - * @param mixed $default The default value. - * - * @return mixed The value of the property. - * - * @since 1.7.0 - */ - public function get($property, $default = null) - { - if (isset($this->metadata[$property])) { - return $this->metadata[$property]; - } - - return $default; - } - /** * Get a back trace. * @@ -888,59 +782,6 @@ protected function getTrace() return \function_exists('debug_backtrace') ? debug_backtrace() : []; } - /** - * Determine who called Language or Text. - * - * @return array Caller information. - * - * @since 1.7.0 - */ - protected function getCallerInfo() - { - // Try to determine the source if none was provided - if (!\function_exists('debug_backtrace')) { - return; - } - - $backtrace = debug_backtrace(); - $info = []; - - // Search through the backtrace to our caller - $continue = true; - - while ($continue && next($backtrace)) { - $step = current($backtrace); - $class = @$step['class']; - - // We're looking for something outside of language.php - if ($class != self::class && $class != Text::class) { - $info['function'] = @$step['function']; - $info['class'] = $class; - $info['step'] = prev($backtrace); - - // Determine the file and name of the file - $info['file'] = @$step['file']; - $info['line'] = @$step['line']; - - $continue = false; - } - } - - return $info; - } - - /** - * Getter for Name. - * - * @return string Official name element of the language. - * - * @since 1.7.0 - */ - public function getName() - { - return $this->metadata['name']; - } - /** * Get a list of language files that have been loaded. * @@ -963,30 +804,6 @@ public function getPaths($extension = null) return $this->paths; } - /** - * Get a list of language files that are in error state. - * - * @return array - * - * @since 1.7.0 - */ - public function getErrorFiles() - { - return $this->errorfiles; - } - - /** - * Getter for the language tag (as defined in RFC 3066) - * - * @return string The language tag. - * - * @since 1.7.0 - */ - public function getTag() - { - return $this->metadata['tag']; - } - /** * Getter for the calendar type * @@ -1003,102 +820,6 @@ public function getCalendar() } } - /** - * Get the RTL property. - * - * @return boolean True is it an RTL language. - * - * @since 1.7.0 - */ - public function isRtl() - { - return (bool) $this->metadata['rtl']; - } - - /** - * Set the Debug property. - * - * @param boolean $debug The debug setting. - * - * @return boolean Previous value. - * - * @since 1.7.0 - */ - public function setDebug($debug) - { - $previous = $this->debug; - $this->debug = (bool) $debug; - - return $previous; - } - - /** - * Get the Debug property. - * - * @return boolean True is in debug mode. - * - * @since 1.7.0 - */ - public function getDebug() - { - return $this->debug; - } - - /** - * Get the default language code. - * - * @return string Language code. - * - * @since 1.7.0 - */ - public function getDefault() - { - return $this->default; - } - - /** - * Set the default language code. - * - * @param string $lang The language code. - * - * @return string Previous value. - * - * @since 1.7.0 - */ - public function setDefault($lang) - { - $previous = $this->default; - $this->default = $lang; - - return $previous; - } - - /** - * Get the list of orphaned strings if being tracked. - * - * @return array Orphaned text. - * - * @since 1.7.0 - */ - public function getOrphans() - { - return $this->orphans; - } - - /** - * Get the list of used strings. - * - * Used strings are those strings requested and found either as a string or a constant. - * - * @return array Used strings. - * - * @since 1.7.0 - */ - public function getUsed() - { - return $this->used; - } - /** * Determines is a key exists. * @@ -1116,50 +837,4 @@ public function hasKey($string) return isset($this->strings[strtoupper($string)]); } - - /** - * Get the language locale based on current language. - * - * @return array The locale according to the language. - * - * @since 1.7.0 - */ - public function getLocale() - { - if (!isset($this->locale)) { - $locale = str_replace(' ', '', $this->metadata['locale'] ?? ''); - - if ($locale) { - $this->locale = explode(',', $locale); - } else { - $this->locale = false; - } - } - - return $this->locale; - } - - /** - * Get the first day of the week for this language. - * - * @return integer The first day of the week according to the language - * - * @since 1.7.0 - */ - public function getFirstDay() - { - return (int) ($this->metadata['firstDay'] ?? 0); - } - - /** - * Get the weekends days for this language. - * - * @return string The weekend days of the week separated by a comma according to the language - * - * @since 3.2 - */ - public function getWeekEnd() - { - return $this->metadata['weekEnd'] ?? '0,6'; - } }