<commit_before><?php
namespace Core\Lib\Content;

use Core\Lib\Errors\Exceptions\InvalidArgumentException;

/**
 * Language.php
 *
 * @author Michael "Tekkla" Zorn <<EMAIL>>
 * @copyright 2015
 * @license MIT
 */
class Language
{

    private static $txt = [];

    /**
     * Loads an app related language file.
     *
     * Throws exception when the language file cannot be found.
     *
     * @param string $app_name
     * @param string $lang_file
     *
     * @throws InvalidArgumentException
     */
    public function loadLanguageFile($app_name, $lang_file)
    {
        if (! file_exists($lang_file)) {
            throw new InvalidArgumentException('The language file "' . $lang_file . '" does not exist.');
        }

        self::$txt[$app_name] = include ($lang_file);
    }

    /**
     * Returns translated text
     *
     * Only translates texts that does not contain spaces.
     * Tries to find core text when either app language or the requested key is found.
     * Returns the key when no language text is found.
     *
     * @param string $key
     * @param string $app
     *
     * @return string
     */
    public function getTxt($key, $app = 'core')
    {
        // IMPORTANT! Keys with spaces won't be processed without any further
        // notice to the developer or user. Spaces mean texts and no keys for the $txt array.
        if (strpos($key, ' ')) {
            return $key;
        }

        // Return key when key is not found
        if (! isset(self::$txt[$app]) || ! isset(self::$txt[$app][$key])) {

            if (isset(self::$txt['Core'][$key])) {
                return self::$txt['Core'][$key];
            }

            return $key;
        }

        // Return requested text
        return self::$txt[$app][$key];
    }
}<commit_msg>Switches internal txt array handling<commit_after><?php
namespace Core\Lib\Content;

use Core\Lib\Errors\Exceptions\InvalidArgumentException;

/**
 * Language.php
 *
 * @author Michael "Tekkla" Zorn <<EMAIL>>
 * @copyright 2015
 * @license MIT
 */
class Language
{

    private $txt = [];

    /**
     * Loads an app related language file.
     *
     * Throws exception when the language file cannot be found.
     *
     * @param string $app_name
     * @param string $lang_file
     *
     * @throws InvalidArgumentException
     */
    public function loadLanguageFile($app_name, $lang_file)
    {
        if ( file_exists($lang_file)) {
            $this->txt[$app_name] = include ($lang_file);
        }
    }

    /**
     * Returns translated text
     *
     * Only translates texts that does not contain spaces.
     * Tries to find core text when either app language or the requested key is found.
     * Returns the key when no language text is found.
     *
     * @param string $key
     * @param string $app
     *
     * @return string
     */
    public function getTxt($key, $app = 'core')
    {
        // IMPORTANT! Keys with spaces won't be processed without any further
        // notice to the developer or user. Spaces mean texts and no keys for the $txt array.
        if (strpos($key, ' ')) {
            return $key;
        }

        // Return key when key is not found
        if (! isset($this->txt[$app]) || ! isset($this->txt[$app][$key])) {

            if (isset($this->txt['Core'][$key])) {
                return $this->txt['Core'][$key];
            }

            return $key;
        }

        // Return requested text
        return $this->txt[$app][$key];
    }
}
{'fraction_non_alphanumeric': 0.12335808109651628, 'fraction_numerical': 0.002284408909194746, 'mean_word_length': 2.086343612334802, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1854417', 'n_tokens_mistral': 1016, 'n_tokens_neox': 991, 'n_words': 316}