<commit_before><?php
namespace T3v\T3vCore\Utility\Draft;

use \TYPO3\CMS\Core\Localization\Locales;
use \TYPO3\CMS\Core\Localization\LocalizationFactory;
use \TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Localization Utility Class
 *
 * The language can be enforced <https://agilepark.de/?p=37>.
 *
 * @package T3v\T3vCore\Utility\Draft
 */
class LocalizationUtility extends \TYPO3\CMS\Extbase\Utility\LocalizationUtility {
  /**
   * Loads local language values by looking for a `locallang.php` (or `locallang.xlf`) file in the plugin resources
   * directory and if found includes it. Also locallang values set in the TypoScript property `_LOCAL_LANG` are merged
   * onto the values found in the "locallang.php" file.
   *
   * @param string $extensionName The extension name
   * @param string $enforcedLanguage The optional language to be used instead of using the language derived from FE or BE configuration
   * @return void
   */
  public static function initializeLocalization($extensionName, $enforcedLanguage = NULL) {
    if (!is_null($enforcedLanguage)) {
      // Clear language contents as we load another language
      self::$LOCAL_LANG = array();
    } else if (isset(self::$LOCAL_LANG[$extensionName])) {
      return;
    }

    $locallangPathAndFilename = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/' . self::$locallangPath . 'locallang.xlf';

    self::setLanguageKeys($enforcedLanguage);

    $renderCharset = TYPO3_MODE === 'FE' ? self::getTypoScriptFrontendController()->renderCharset : self::getLanguageService()->charSet;

    $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);

    self::$LOCAL_LANG[$extensionName] = $languageFactory->getParsedData($locallangPathAndFilename, self::$languageKey, $renderCharset);

    foreach (self::$alternativeLanguageKeys as $language) {
      $tempLL = $languageFactory->getParsedData($locallangPathAndFilename, $language, $renderCharset);

      if (self::$languageKey !== 'default' && isset($tempLL[$language])) {
        self::$LOCAL_LANG[$extensionName][$language] = $tempLL[$language];
      }
    }

    self::loadTypoScriptLabels($extensionName);
  }

  /**
   * Sets the currently active language / language_alt keys.
   * Default values are `default` for language key and `` for language_alt key.
   * @param string $enforcedLanguage The optional language to be used instead of using the language derived from FE or BE configuration
   * @return void
   */
  protected static function setLanguageKeys() {
    self::$alternativeLanguageKeys = array();

    if (is_null($enforcedLanguage)) {
      self::$languageKey = 'default';

      if (TYPO3_MODE === 'FE') {
        if (isset(self::getTypoScriptFrontendController()->config['config']['language'])) {
          self::$languageKey = self::getTypoScriptFrontendController()->config['config']['language'];

          if (isset(self::getTypoScriptFrontendController()->config['config']['language_alt'])) {<commit_msg>[➠] Minor changes.<commit_after><?php
namespace T3v\T3vCore\Utility\Draft;

use \TYPO3\CMS\Core\Localization\Locales;
use \TYPO3\CMS\Core\Localization\LocalizationFactory;
use \TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Localization Utility Class
 *
 * The language can be enforced <https://agilepark.de/?p=37>.
 *
 * @package T3v\T3vCore\Utility\Draft
 */
class LocalizationUtility extends \TYPO3\CMS\Extbase\Utility\LocalizationUtility {
  /**
   * Loads local language values by looking for a `locallang.php` (or `locallang.xlf`) file in the plugin resources
   * directory and if found includes it. Also locallang values set in the TypoScript property `_LOCAL_LANG` are merged
   * onto the values found in the "locallang.php" file.
   *
   * @param string $extensionName The extension name
   * @param string $enforcedLanguage The optional language to be used instead of using the language derived from FE or BE configuration
   * @return void
   */
  public static function initializeLocalization($extensionName, $enforcedLanguage = NULL) {
    if (!is_null($enforcedLanguage)) {
      // Clear language contents as we load another language
      self::$LOCAL_LANG = [];
    } else if (isset(self::$LOCAL_LANG[$extensionName])) {
      return;
    }

    $locallangPathAndFilename = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/' . self::$locallangPath . 'locallang.xlf';

    self::setLanguageKeys($enforcedLanguage);

    $renderCharset = TYPO3_MODE === 'FE' ? self::getTypoScriptFrontendController()->renderCharset : self::getLanguageService()->charSet;

    $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);

    self::$LOCAL_LANG[$extensionName] = $languageFactory->getParsedData($locallangPathAndFilename, self::$languageKey, $renderCharset);

    foreach (self::$alternativeLanguageKeys as $language) {
      $tempLL = $languageFactory->getParsedData($locallangPathAndFilename, $language, $renderCharset);

      if (self::$languageKey !== 'default' && isset($tempLL[$language])) {
        self::$LOCAL_LANG[$extensionName][$language] = $tempLL[$language];
      }
    }

    self::loadTypoScriptLabels($extensionName);
  }

  /**
   * Sets the currently active language / language_alt keys.
   * Default values are `default` for language key and `` for language_alt key.
   * @param string $enforcedLanguage The optional language to be used instead of using the language derived from FE or BE configuration
   * @return void
   */
  protected static function setLanguageKeys() {
    self::$alternativeLanguageKeys = [];

    if (is_null($enforcedLanguage)) {
      self::$languageKey = 'default';

      if (TYPO3_MODE === 'FE') {
        if (isset(self::getTypoScriptFrontendController()->config['config']['language'])) {
          self::$languageKey = self::getTypoScriptFrontendController()->config['config']['language'];

          if (isset(self::getTypoScriptFrontendController()->config['config']['language_alt'])) {
{'fraction_non_alphanumeric': 0.12622814321398834, 'fraction_numerical': 0.003996669442131557, 'mean_word_length': 4.613084112149533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '6429931', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1719, 'n_words': 412}