CoreFiles by mySites.guru
Language.php976 lines, 29,565 bytes, from Joomla_6.2.0-Stable-Full_Package.zip
Raw History Compare with 6.1.4
md5
cc9bf8278a2063675978822b89a82134
sha1
817810ac887ff21a0e47c9483081f9c590ea3cc0
sha256
efe14286a3402c6f0fdddf7e5591a187b5d518f9860aca2537d10feaf2999e6c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Language;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\Language\Language as BaseLanguage;
use Joomla\String\StringHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Languages/translation handler class
 *
 * @since  1.7.0
 */
class Language extends BaseLanguage
{
    /**
     * Array of Language objects
     *
     * @var    Language[]
     * @since  1.7.0
     */
    protected static $languages = [];

    /**
     * Translations
     *
     * @var    array
     * @since  1.7.0
     */
    protected $strings = [];

    /**
     * Cached fallback chains, keyed by language tag.
     *
     * @var    array
     * @since  6.2.0
     */
    protected $fallbackChains = [];

    /**
     * Cached admin fallback overrides (language tag => fallback tag), or null until first read.
     *
     * @var    array|null
     * @since  6.2.0
     */
    protected $fallbackOverrides = null;

    /**
     * Name of the transliterator function for this language.
     *
     * @var    callable
     * @since  1.7.0
     */
    protected $transliterator = null;

    /**
     * Name of the pluralSuffixesCallback function for this language.
     *
     * @var    callable
     * @since  1.7.0
     */
    protected $pluralSuffixesCallback = null;

    /**
     * Name of the ignoredSearchWordsCallback function for this language.
     *
     * @var    callable
     * @since  1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    protected $ignoredSearchWordsCallback = null;

    /**
     * Name of the lowerLimitSearchWordCallback function for this language.
     *
     * @var    callable
     * @since  1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    protected $lowerLimitSearchWordCallback = null;

    /**
     * Name of the upperLimitSearchWordCallback function for this language.
     *
     * @var    callable
     * @since  1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    protected $upperLimitSearchWordCallback = null;

    /**
     * Name of the searchDisplayedCharactersNumberCallback function for this language.
     *
     * @var    callable
     * @since  1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    protected $searchDisplayedCharactersNumberCallback = null;

    /**
     * Constructor activating the default information of the language.
     *
     * @param   string   $lang   The language
     * @param   boolean  $debug  Indicates if language debugging is enabled.
     *
     * @since   1.7.0
     */
    public function __construct($lang = null, $debug = false)
    {
        $this->strings = [];

        if ($lang == null) {
            $lang = $this->default;
        }

        $this->lang     = $lang;
        $this->metadata = LanguageHelper::getMetadata($this->lang);
        $this->setDebug($debug);

        /*
         * Let's load the default override once, so we can profit from that, too
         * But make sure, that we don't enforce it on each language file load.
         * So don't put it in $this->override
         */
        if (!$this->debug && $lang !== $this->default) {
            $this->loadLanguage(JPATH_BASE . '/language/overrides/' . $this->default . '.override.ini');
        }

        $this->override = $this->parse(JPATH_BASE . '/language/overrides/' . $lang . '.override.ini');

        // Look for a language specific localise class
        $class = str_replace('-', '_', $lang . 'Localise');
        $paths = [];

        if (\defined('JPATH_SITE')) {
            // Note: Manual indexing to enforce load order.
            $paths[0] = JPATH_SITE . "/language/overrides/$lang.localise.php";
            $paths[2] = JPATH_SITE . "/language/$lang/localise.php";
            $paths[4] = JPATH_SITE . "/language/$lang/$lang.localise.php";
        }

        if (\defined('JPATH_ADMINISTRATOR')) {
            // Note: Manual indexing to enforce load order.
            $paths[1] = JPATH_ADMINISTRATOR . "/language/overrides/$lang.localise.php";
            $paths[3] = JPATH_ADMINISTRATOR . "/language/$lang/localise.php";
            $paths[5] = JPATH_ADMINISTRATOR . "/language/$lang/$lang.localise.php";
        }

        ksort($paths);
        $path = reset($paths);

        while (!class_exists($class) && $path) {
            if (is_file($path)) {
                require_once $path;
            }

            $path = next($paths);
        }

        if (class_exists($class)) {
            /**
             * Class exists. Try to find
             * -a transliterate method,
             * -a getPluralSuffixes method,
             * -a getIgnoredSearchWords method
             * -a getLowerLimitSearchWord method
             * -a getUpperLimitSearchWord method
             * -a getSearchDisplayCharactersNumber method
             */
            if (method_exists($class, 'transliterate')) {
                $this->transliterator = [$class, 'transliterate'];
            }

            if (method_exists($class, 'getPluralSuffixes')) {
                $this->pluralSuffixesCallback = [$class, 'getPluralSuffixes'];
            }

            if (method_exists($class, 'getIgnoredSearchWords')) {
                $this->ignoredSearchWordsCallback = [$class, 'getIgnoredSearchWords'];
            }

            if (method_exists($class, 'getLowerLimitSearchWord')) {
                $this->lowerLimitSearchWordCallback = [$class, 'getLowerLimitSearchWord'];
            }

            if (method_exists($class, 'getUpperLimitSearchWord')) {
                $this->upperLimitSearchWordCallback = [$class, 'getUpperLimitSearchWord'];
            }

            if (method_exists($class, 'getSearchDisplayedCharactersNumber')) {
                $this->searchDisplayedCharactersNumberCallback = [$class, 'getSearchDisplayedCharactersNumber'];
            }
        }

        $this->load();
    }

    /**
     * Returns a language object.
     *
     * @param   string   $lang   The language to use.
     * @param   boolean  $debug  The debug mode.
     *
     * @return  Language  The Language object.
     *
     * @since       1.7.0
     *
     * @deprecated  4.3 will be removed in 7.0
     *              Use the language factory instead
     *              Example: Factory::getContainer()->get(LanguageFactoryInterface::class)->createLanguage($lang, $debug);
     */
    public static function getInstance($lang, $debug = false)
    {
        if (!isset(self::$languages[$lang . $debug])) {
            self::$languages[$lang . $debug] = Factory::getContainer()->get(LanguageFactoryInterface::class)->createLanguage($lang, $debug);
        }

        return self::$languages[$lang . $debug];
    }

    /**
     * Translate function, mimics the php gettext (alias _) function.
     *
     * The function checks if $jsSafe is true, then if $interpretBackslashes is true.
     *
     * @param   string   $string                The string to translate
     * @param   boolean  $jsSafe                Parameter to add slashes to the string that will be rendered as JavaScript.
     *                                          However, set as "false" if the string is going to be encoded by json_encode().
     * @param   boolean  $interpretBackSlashes  Interpret \t and \n
     *
     * @return  string  The translation of the string
     *
     * @since   1.7.0
     */
    public function _($string, $jsSafe = false, $interpretBackSlashes = true)
    {
        // Detect empty string
        if ($string == '') {
            return '';
        }

        $key = strtoupper($string);

        if (isset($this->strings[$key])) {
            $string = $this->strings[$key];

            // Store debug information
            if ($this->debug) {
                $value  = Factory::getApplication()->get('debug_lang_const', true) ? $string : $key;
                $string = '**' . $value . '**';

                $caller = $this->getCallerInfo();

                if (!\array_key_exists($key, $this->used)) {
                    $this->used[$key] = [];
                }

                $this->used[$key][] = $caller;
            }
        } else {
            if ($this->debug) {
                $info           = [];
                $info['trace']  = $this->getTrace();
                $info['key']    = $key;
                $info['string'] = $string;

                if (!\array_key_exists($key, $this->orphans)) {
                    $this->orphans[$key] = [];
                }

                $this->orphans[$key][] = $info;

                $string = '??' . $string . '??';
            }
        }

        if ($jsSafe) {
            // Javascript filter
            $string = addslashes($string);
        } elseif ($interpretBackSlashes) {
            if (str_contains($string, '\\')) {
                // Interpret \n and \t characters
                $string = str_replace(['\\\\', '\t', '\n'], ["\\", "\t", "\n"], $string);
            }
        }

        return $string;
    }

    /**
     * Transliterate function
     *
     * This method processes a string and replaces all accented UTF-8 characters by unaccented
     * ASCII-7 "equivalents".
     *
     * @param   string  $string  The string to transliterate.
     *
     * @return  string  The transliteration of the string.
     *
     * @since   1.7.0
     */
    public function transliterate($string)
    {
        // First check for transliterator provided by translation
        if ($this->transliterator !== null) {
            $string = \call_user_func($this->transliterator, $string);

            // Check if all symbols were transliterated (contains only ASCII), otherwise continue
            if (!preg_match('/[\\x80-\\xff]/', $string)) {
                return $string;
            }
        }

        // Run our transliterator for common symbols,
        // This need to be executed before native php transliterator, because it may not have all required transliterators
        $string = Transliterate::utf8_latin_to_ascii($string);

        // Check if all symbols were transliterated (contains only ASCII),
        // Otherwise try to use native php function if available
        if (preg_match('/[\\x80-\\xff]/', $string) && \function_exists('transliterator_transliterate') && \function_exists('iconv')) {
            return iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $string));
        }

        return StringHelper::strtolower($string);
    }

    /**
     * Getter for transliteration function
     *
     * @return  callable  The transliterator function
     *
     * @since   1.7.0
     */
    public function getTransliterator()
    {
        return $this->transliterator;
    }

    /**
     * Set the transliteration function.
     *
     * @param   callable  $function  Function name or the actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     */
    public function setTransliterator(callable $function)
    {
        $previous             = $this->transliterator;
        $this->transliterator = $function;

        return $previous;
    }

    /**
     * Returns an array of suffixes for plural rules.
     *
     * @param   integer  $count  The count number the rule is for.
     *
     * @return  array    The array of suffixes.
     *
     * @since   1.7.0
     */
    public function getPluralSuffixes($count)
    {
        if ($this->pluralSuffixesCallback !== null) {
            return \call_user_func($this->pluralSuffixesCallback, $count);
        }

        return [(string) $count];
    }

    /**
     * Getter for pluralSuffixesCallback function.
     *
     * @return  callable  Function name or the actual function.
     *
     * @since   1.7.0
     */
    public function getPluralSuffixesCallback()
    {
        return $this->pluralSuffixesCallback;
    }

    /**
     * Set the pluralSuffixes function.
     *
     * @param   callable  $function  Function name or actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     */
    public function setPluralSuffixesCallback(callable $function)
    {
        $previous                     = $this->pluralSuffixesCallback;
        $this->pluralSuffixesCallback = $function;

        return $previous;
    }

    /**
     * Returns an array of ignored search words
     *
     * @return  array  The array of ignored search words.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getIgnoredSearchWords()
    {
        if ($this->ignoredSearchWordsCallback !== null) {
            return \call_user_func($this->ignoredSearchWordsCallback);
        }

        return [];
    }

    /**
     * Getter for ignoredSearchWordsCallback function.
     *
     * @return  callable  Function name or the actual function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getIgnoredSearchWordsCallback()
    {
        return $this->ignoredSearchWordsCallback;
    }

    /**
     * Setter for the ignoredSearchWordsCallback function
     *
     * @param   callable  $function  Function name or actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function setIgnoredSearchWordsCallback(callable $function)
    {
        $previous                         = $this->ignoredSearchWordsCallback;
        $this->ignoredSearchWordsCallback = $function;

        return $previous;
    }

    /**
     * Returns a lower limit integer for length of search words
     *
     * @return  integer  The lower limit integer for length of search words (3 if no value was set for a specific language).
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getLowerLimitSearchWord()
    {
        if ($this->lowerLimitSearchWordCallback !== null) {
            return \call_user_func($this->lowerLimitSearchWordCallback);
        }

        return 3;
    }

    /**
     * Getter for lowerLimitSearchWordCallback function
     *
     * @return  callable  Function name or the actual function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getLowerLimitSearchWordCallback()
    {
        return $this->lowerLimitSearchWordCallback;
    }

    /**
     * Setter for the lowerLimitSearchWordCallback function.
     *
     * @param   callable  $function  Function name or actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function setLowerLimitSearchWordCallback(callable $function)
    {
        $previous                           = $this->lowerLimitSearchWordCallback;
        $this->lowerLimitSearchWordCallback = $function;

        return $previous;
    }

    /**
     * Returns an upper limit integer for length of search words
     *
     * @return  integer  The upper limit integer for length of search words (200 if no value was set or if default value is < 200).
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getUpperLimitSearchWord()
    {
        if ($this->upperLimitSearchWordCallback !== null && \call_user_func($this->upperLimitSearchWordCallback) > 200) {
            return \call_user_func($this->upperLimitSearchWordCallback);
        }

        return 200;
    }

    /**
     * Getter for upperLimitSearchWordCallback function
     *
     * @return  callable  Function name or the actual function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getUpperLimitSearchWordCallback()
    {
        return $this->upperLimitSearchWordCallback;
    }

    /**
     * Setter for the upperLimitSearchWordCallback function
     *
     * @param   callable  $function  Function name or the actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function setUpperLimitSearchWordCallback(callable $function)
    {
        $previous                           = $this->upperLimitSearchWordCallback;
        $this->upperLimitSearchWordCallback = $function;

        return $previous;
    }

    /**
     * Returns the number of characters displayed in search results.
     *
     * @return  integer  The number of characters displayed (200 if no value was set for a specific language).
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getSearchDisplayedCharactersNumber()
    {
        if ($this->searchDisplayedCharactersNumberCallback !== null) {
            return \call_user_func($this->searchDisplayedCharactersNumberCallback);
        }

        return 200;
    }

    /**
     * Getter for searchDisplayedCharactersNumberCallback function
     *
     * @return  callable  Function name or the actual function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function getSearchDisplayedCharactersNumberCallback()
    {
        return $this->searchDisplayedCharactersNumberCallback;
    }

    /**
     * Setter for the searchDisplayedCharactersNumberCallback function.
     *
     * @param   callable  $function  Function name or the actual function.
     *
     * @return  callable  The previous function.
     *
     * @since   1.7.0
     *
     * @deprecated  4.4 will be removed in 7.0 without replacement
     */
    public function setSearchDisplayedCharactersNumberCallback(callable $function)
    {
        $previous                                      = $this->searchDisplayedCharactersNumberCallback;
        $this->searchDisplayedCharactersNumberCallback = $function;

        return $previous;
    }

    /**
     * Loads a single language file and appends the results to the existing strings
     *
     * @param   string   $extension  The extension for which a language file should be loaded.
     * @param   string   $basePath   The basepath to use.
     * @param   string   $lang       The language to load, default null for the current language.
     * @param   boolean  $reload     Flag that will force a language to be reloaded if set to true.
     * @param   boolean  $default    Flag that force the default language to be loaded if the current does not exist.
     *
     * @return  boolean  True if the file has successfully loaded.
     *
     * @since   1.7.0
     */
    public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null, $reload = false, $default = true)
    {
        // If language is null set as the current language.
        if (!$lang) {
            $lang = $this->lang;
        }

        // Load the default language first if we're not debugging and a non-default language is requested to be loaded
        // with $default set to true
        if (!$this->debug && ($lang != $this->default) && $default) {
            $this->load($extension, $basePath, $this->default, false, true);
        }

        // Load the fallback chain next, weakest first, so missing strings are filled per key.
        if (!$this->debug) {
            foreach (array_reverse($this->getFallbackChain($lang)) as $fallbackLang) {
                $this->load($extension, $basePath, $fallbackLang, $reload, false);
            }
        }

        $path = LanguageHelper::getLanguagePath($basePath, $lang);

        $internal = $extension === 'joomla' || $extension == '';

        $filenames = [];

        if ($internal) {
            $filenames[] = "$path/joomla.ini";
            $filenames[] = "$path/$lang.ini";
        } else {
            // Try first without a language-prefixed filename.
            $filenames[] = "$path/$extension.ini";
            $filenames[] = "$path/$lang.$extension.ini";
        }

        foreach ($filenames as $filename) {
            if (isset($this->paths[$extension][$filename]) && !$reload) {
                // This file has already been tested for loading.
                $result = $this->paths[$extension][$filename];
            } else {
                // Load the language file
                $result = $this->loadLanguage($filename, $extension);
            }

            if ($result) {
                return true;
            }
        }

        return false;
    }

    /**
     * Resolves the ordered fallback chain for a language tag, strongest first.
     *
     * The fallback of a tag is taken from the com_languages override, else from the optional
     * <fallback> element of its langmetadata.xml. The chain stops at a language without a fallback,
     * the site default, or a cycle, and excludes both the requested language and the site default.
     *
     * @param   string  $lang  The language tag to resolve the fallback chain for.
     *
     * @return  string[]  Ordered list of fallback language tags, strongest first.
     *
     * @since   6.2.0
     */
    protected function getFallbackChain($lang)
    {
        if (isset($this->fallbackChains[$lang])) {
            return $this->fallbackChains[$lang];
        }

        $chain     = [];
        $seen      = [$lang => true];
        $next      = $lang;
        $overrides = $this->getFallbackOverrides();

        while (true) {
            if (isset($overrides[$next])) {
                $fallback = $overrides[$next];
            } else {
                $metadata = ($next === $this->lang ? $this->metadata : LanguageHelper::getMetadata($next)) ?: [];
                $fallback = $metadata['fallback'] ?? '';
            }

            if ($fallback === '' || $fallback === $this->default || isset($seen[$fallback])) {
                break;
            }

            $chain[]         = $fallback;
            $seen[$fallback] = true;
            $next            = $fallback;
        }

        $this->fallbackChains[$lang] = $chain;

        return $chain;
    }

    /**
     * Reads and caches the administrator fallback overrides (tag => fallback) from the
     * com_languages options. Returns an empty map when the component parameters are not yet available.
     *
     * @return  array  Map of language tag => fallback tag.
     *
     * @since   6.2.0
     */
    protected function getFallbackOverrides()
    {
        if ($this->fallbackOverrides !== null) {
            return $this->fallbackOverrides;
        }

        $this->fallbackOverrides = [];

        try {
            $overrides = ComponentHelper::getParams('com_languages')->get('fallback_overrides');
        } catch (\Throwable $e) {
            return $this->fallbackOverrides;
        }

        foreach ((array) $overrides as $override) {
            $tag      = trim((string) ($override->tag ?? ''));
            $fallback = trim((string) ($override->fallback ?? ''));

            if ($tag !== '' && $fallback !== '') {
                $this->fallbackOverrides[$tag] = $fallback;
            }
        }

        return $this->fallbackOverrides;
    }

    /**
     * Loads a language file.
     *
     * This method will not note the successful loading of a file - use load() instead.
     *
     * @param   string  $fileName   The name of the file.
     * @param   string  $extension  The name of the extension.
     *
     * @return  boolean  True if new strings have been added to the language
     *
     * @see     Language::load()
     * @since   1.7.0
     */
    protected function loadLanguage($fileName, $extension = 'unknown')
    {
        $this->counter++;

        $result  = false;
        $strings = $this->parse($fileName);

        if ($strings !== []) {
            $this->strings = array_replace($this->strings, $strings, $this->override);
            $result        = true;
        }

        // Record the result of loading the extension's file.
        if (!isset($this->paths[$extension])) {
            $this->paths[$extension] = [];
        }

        $this->paths[$extension][$fileName] = $result;

        return $result;
    }

    /**
     * Parses a language file.
     *
     * @param   string  $fileName  The name of the file.
     *
     * @return  array  The array of parsed strings.
     *
     * @since   1.7.0
     */
    protected function parse($fileName)
    {
        try {
            $strings = LanguageHelper::parseIniFile($fileName, $this->debug);

            // Parser Errors detected
            if ($this->debug && is_file($fileName)) {
                $this->debugFile($fileName);
            }
        } catch (\RuntimeException $e) {
            $strings = [];

            // Debug the ini file if needed.
            if ($this->debug && is_file($fileName)) {
                if (!$this->debugFile($fileName)) {
                    // We didn't find any errors but there's a parser warning.
                    $this->errorfiles[$fileName] = 'PHP parser errors :' . $e->getMessage();
                }
            }
        }

        return $strings;
    }

    /**
     * Debugs a language file
     *
     * @param   string  $filename  Absolute path to the file to debug
     *
     * @return  integer  A count of the number of parsing errors
     *
     * @since   3.6.3
     * @throws  \InvalidArgumentException
     */
    public function debugFile(string $filename): int
    {
        // Make sure our file actually exists
        if (!is_file($filename)) {
            throw new \InvalidArgumentException(
                \sprintf('Unable to locate file "%s" for debugging', $filename)
            );
        }

        // Initialise variables for manually parsing the file for common errors.
        $reservedWord = ['YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'];
        $errors       = [];

        // Open the file as a stream.
        $file = new \SplFileObject($filename);

        foreach ($file as $lineNumber => $line) {
            // Avoid BOM error as BOM is OK when using parse_ini.
            if ($lineNumber == 0) {
                $line = str_replace("\xEF\xBB\xBF", '', $line);
            }

            $line = trim($line);

            // Ignore comment lines.
            if (!\strlen($line) || $line['0'] == ';') {
                continue;
            }

            // Ignore grouping tag lines, like: [group]
            if (preg_match('#^\[[^\]]*\](\s*;.*)?$#', $line)) {
                continue;
            }

            // Remove any escaped double quotes \" from the equation
            $line = str_replace('\"', '', $line);

            $realNumber = $lineNumber + 1;

            // Check for odd number of double quotes.
            if (substr_count($line, '"') % 2 != 0) {
                $errors[] = $realNumber;
                continue;
            }

            // Check that the line passes the necessary format.
            if (!preg_match('#^[A-Z][A-Z0-9_:\*\-\.]*\s*=\s*".*"(\s*;.*)?$#', $line)) {
                $errors[] = $realNumber;
                continue;
            }

            // Check that the key is not in the reserved constants list.
            $key = strtoupper(trim(substr($line, 0, strpos($line, '='))));

            if (\in_array($key, $reservedWord)) {
                $errors[] = $realNumber;
            }
        }

        // Check if we encountered any errors.
        if (\count($errors)) {
            $this->errorfiles[$filename] = $errors;
        }

        return \count($errors);
    }

    /**
     * Get a back trace.
     *
     * @return array
     *
     * @since 4.0.0
     */
    protected function getTrace()
    {
        return \function_exists('debug_backtrace') ? debug_backtrace() : [];
    }

    /**
     * Get a list of language files that have been loaded.
     *
     * @param   string  $extension  An optional extension name.
     *
     * @return  array
     *
     * @since   1.7.0
     */
    public function getPaths($extension = null)
    {
        if (isset($extension)) {
            if (isset($this->paths[$extension])) {
                return $this->paths[$extension];
            }

            return [];
        }

        return $this->paths;
    }

    /**
     * Getter for the calendar type
     *
     * @return  string  The calendar type.
     *
     * @since   3.7.0
     */
    public function getCalendar()
    {
        return $this->metadata['calendar'] ?? 'gregorian';
    }

    /**
     * Determines is a key exists.
     *
     * @param   string  $string  The key to check.
     *
     * @return  boolean  True, if the key exists.
     *
     * @since   1.7.0
     */
    public function hasKey($string)
    {
        if ($string === null) {
            return false;
        }

        return isset($this->strings[strtoupper($string)]);
    }
}

The same content is in 2 releases, Joomla 6.2.0-rc2 to 6.2.0. See them all, or every version of this file.