<commit_before><?php

namespace Pyz\Zed\Glossary\Communication\Plugin;

use ProjectA\Zed\Glossary\Business\GlossaryFacade;
use ProjectA\Zed\Glossary\Communication\GlossaryDependencyContainer;
use ProjectA\Zed\Glossary\Dependency\Plugin\GlossaryInstallerPluginInterface;
use ProjectA\Zed\Kernel\Business\FacadeLocator;
use ProjectA\Zed\Kernel\Communication\AbstractPlugin;
use ProjectA\Zed\Kernel\Locator;
use Symfony\Component\Yaml\Yaml;

class YamlInstallerPlugin extends AbstractPlugin implements GlossaryInstallerPluginInterface
{
    /**
     * @var GlossaryDependencyContainer
     */
    protected $dependencyContainer;


    public function installGlossaryData()
    {
        $filePath = __DIR__ . '/../../File/initial_translation.yml';
        $translations = $this->parseYamlFile($filePath);
        $this->installKeysAndTranslations($translations);
    }

    protected function parseYamlFile($filePath)
    {
        $yamlParser = new Yaml();
        return $yamlParser->parse(file_get_contents($filePath));
    }

    /**
     * @param array $translations
     */
    protected function installKeysAndTranslations(array $translations)
    {
        $glossaryFacade = $this->dependencyContainer->getGlossaryFacade();
        foreach ($translations['keys'] as $keyName => $data) {
            if (!$glossaryFacade->hasKey($keyName)) {
                $glossaryFacade->createKey($keyName);
            }

            foreach ($data['translations'] as $localeName => $text) {
                if (!$glossaryFacade->hasTranslation($keyName, $localeName)) {
                    $glossaryFacade->createTranslation($keyName, $localeName, $text, true);
                }
            }
        }
    }
}<commit_msg>adapt glossary installer to explicit translation touching<commit_after><?php

namespace Pyz\Zed\Glossary\Communication\Plugin;

use ProjectA\Zed\Glossary\Business\GlossaryFacade;
use ProjectA\Zed\Glossary\Communication\GlossaryDependencyContainer;
use ProjectA\Zed\Glossary\Dependency\Plugin\GlossaryInstallerPluginInterface;
use ProjectA\Zed\Kernel\Business\FacadeLocator;
use ProjectA\Zed\Kernel\Communication\AbstractPlugin;
use ProjectA\Zed\Kernel\Locator;
use Symfony\Component\Yaml\Yaml;

class YamlInstallerPlugin extends AbstractPlugin implements GlossaryInstallerPluginInterface
{
    /**
     * @var GlossaryDependencyContainer
     */
    protected $dependencyContainer;


    public function installGlossaryData()
    {
        $filePath = __DIR__ . '/../../File/initial_translation.yml';
        $translations = $this->parseYamlFile($filePath);
        $this->installKeysAndTranslations($translations);
    }

    protected function parseYamlFile($filePath)
    {
        $yamlParser = new Yaml();
        return $yamlParser->parse(file_get_contents($filePath));
    }

    /**
     * @param array $translations
     */
    protected function installKeysAndTranslations(array $translations)
    {
        $glossaryFacade = $this->dependencyContainer->getGlossaryFacade();
        foreach ($translations['keys'] as $keyName => $data) {
            if (!$glossaryFacade->hasKey($keyName)) {
                $glossaryFacade->createKey($keyName);
            }

            foreach ($data['translations'] as $localeName => $text) {
                if (!$glossaryFacade->hasTranslation($keyName, $localeName)) {
                    $glossaryFacade->createAndTouchTranslation($keyName, $localeName, $text, true);
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1153184165232358, 'fraction_numerical': 0.0, 'mean_word_length': 3.2062726176115803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2143033', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1006, 'n_words': 152}