<commit_before><?php
/**
 *@file
 * Contains \Drupal\AppConsole\Command\Helper\TranslatorHelper.
 */

namespace Drupal\AppConsole\Command\Helper;

use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\YamlFileLoader;

class TranslatorHelper extends Helper
{

  private $language;

  private $translator;

  public function loadResource($language, $directoryRoot){
    $this->language = $language;

    $this->translator = new Translator($language);
    $this->translator->addLoader('yaml', new YamlFileLoader());
    $this->translator->addResource(
      'yaml',
      $directoryRoot . 'config/translations/console.'.$this->language.'.yml',
      $language
    );
  }

  public function trans($key){
    return $this->translator->trans($key);
  }

  /**
   * @see \Symfony\Component\Console\Helper\HelperInterface::getName()
   */
  public function getName()
  {
    return 'translator';
  }
}<commit_msg>Fallback to en if no language file found<commit_after><?php
/**
 *@file
 * Contains \Drupal\AppConsole\Command\Helper\TranslatorHelper.
 */

namespace Drupal\AppConsole\Command\Helper;

use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\YamlFileLoader;

class TranslatorHelper extends Helper
{

  private $language;

  private $translator;

  public function loadResource($language, $directoryRoot){
    if (!file_exists($directoryRoot . 'config/translations/console.'.$language.'.yml')){
      $language = 'en';
    }
    $this->language = $language;

    $this->translator = new Translator($language);
    $this->translator->addLoader('yaml', new YamlFileLoader());
    $this->translator->addResource(
      'yaml',
      $directoryRoot . 'config/translations/console.'.$language.'.yml',
      $language
    );
  }

  public function trans($key){
    return $this->translator->trans($key);
  }

  /**
   * @see \Symfony\Component\Console\Helper\HelperInterface::getName()
   */
  public function getName()
  {
    return 'translator';
  }
}
{'fraction_non_alphanumeric': 0.14577397910731243, 'fraction_numerical': 0.0, 'mean_word_length': 3.9928909952606637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '1872151', 'n_tokens_mistral': 647, 'n_tokens_neox': 630, 'n_words': 110}