<commit_before><?php
namespace Nexendrie\Translation;

use Nexendrie\Translation\Loaders\ILoader,
    Nette\PhpGenerator\Helpers,
    Nette\Utils\FileSystem;

/**
 * CatalogueCompiler
 * Compiles messages catalogues from resources found by loader
 *
 * @author <NAME>
 */
class CatalogueCompiler {
  use \Nette\SmartObject;
  
  /** @var ILoader */
  protected $loader;
  /** @var string[] */
  protected $languages = [];
  /** @var string */
  protected $folder = "";
  
  /**
   * @param ILoader $loader
   * @param string $folder
   * @param string[] $languages
   */
  function __construct(ILoader $loader, $folder, array $languages = []) {
    $this->loader = $loader;
    if(!count($languages)) {
      $languages = $loader->getAvailableLanguages();
    }
    $this->languages = $languages;
    $this->folder = $folder;
  }
  
  /**
   * Compile catalogues
   *
   * @return void
   */
  function compile() {
    FileSystem::createDir($this->folder);
    foreach($this->languages as $language) {
      $this->loader->setLang($language);
      $texts = $this->loader->getTexts();
      $texts["__resources"] = $this->loader->getResources();
      $content = "<?php
return " . Helpers::dump($texts) . ";
?>";
      $filename = $this->folder . "/catalogue.$language.php";
      file_put_contents($filename, $content);
    }
  }
}
?><commit_msg>use FileSystem::write() from nette/utils to create catalogues in CatalogueCompiler::compile()<commit_after><?php
namespace Nexendrie\Translation;

use Nexendrie\Translation\Loaders\ILoader,
    Nette\PhpGenerator\Helpers,
    Nette\Utils\FileSystem;

/**
 * CatalogueCompiler
 * Compiles messages catalogues from resources found by loader
 *
 * @author <NAME>
 */
class CatalogueCompiler {
  use \Nette\SmartObject;
  
  /** @var ILoader */
  protected $loader;
  /** @var string[] */
  protected $languages = [];
  /** @var string */
  protected $folder = "";
  
  /**
   * @param ILoader $loader
   * @param string $folder
   * @param string[] $languages
   */
  function __construct(ILoader $loader, $folder, array $languages = []) {
    $this->loader = $loader;
    if(!count($languages)) {
      $languages = $loader->getAvailableLanguages();
    }
    $this->languages = $languages;
    $this->folder = $folder;
  }
  
  /**
   * Compile catalogues
   *
   * @return void
   */
  function compile() {
    foreach($this->languages as $language) {
      $this->loader->setLang($language);
      $texts = $this->loader->getTexts();
      $texts["__resources"] = $this->loader->getResources();
      $content = "<?php
return " . Helpers::dump($texts) . ";
?>";
      $filename = $this->folder . "/catalogue.$language.php";
      FileSystem::write($filename, $content);
    }
  }
}
?>
{'fraction_non_alphanumeric': 0.16947291361639824, 'fraction_numerical': 0.0, 'mean_word_length': 3.2046153846153844, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, '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': '7026542', 'n_tokens_mistral': 874, 'n_tokens_neox': 880, 'n_words': 171}