Add translation.

@param Translation $translation

@throws Exception Inserting a master translation is not allowed
558005
public function addTranslation(Translation $translation)
    {
        if ($translation->getLanguage() === $this->masterLanguage) {
            throw new Exception('You cannot insert a new translation for master language');
        }

        $originalRepository = $translation
            ->getMasterTranslation()
            ->getRepository();

        $newRepositoryDirname = $originalRepository->getDirname();
        $newRepositoryDomain = $originalRepository->getDomain();
        $newRepositoryLanguage = $translation->getLanguage();

        /**
         * We check if this repository exists. If not, we create it.
         * Otherwise, we use existing one.
         */
        $expectedRepositories = array_filter(
            $this
                ->repositoryCollection
                ->getRepositories(),
            function (Repository $repository) use ($newRepositoryLanguage, $newRepositoryDomain, $newRepositoryDirname) {
                return
                    $repository->getDomain() === $newRepositoryDomain &&
                    $repository->getLanguage() === $newRepositoryLanguage &&
                    $repository->getDirname() === $newRepositoryDirname;
            }
        );

        $expectedRepository = reset($expectedRepositories);

        if (!($expectedRepository instanceof Repository)) {
            $newRepositoryPath = Repository::buildRepositoryPath(
                $newRepositoryDirname,
                $newRepositoryDomain,
                $newRepositoryLanguage
            );
            $expectedRepository = Repository::createEmptyByFilePath($newRepositoryPath);
            $this
                ->repositoryCollection
                ->addRepository($expectedRepository);
        }

        $expectedRepository->addTranslation($translation);
    }
49608
public function addTranslation(LayoutTranslation $translation)
    {
        $this->translations->add($translation);
        $translation->setLayout($this);
    }
541362
def addTranslation(self,translation):
        '''
        '''
        if isinstance(translation, Translation):
            self.translations.append(translation)
        else:
            raise(TranslationError,
                   'translation Type should be Translation, not %s' % type(
                    translation)
                   )
741217
public function addTranslation(\Haven\CmsBundle\Entity\HtmlContentTranslation $translations) {
        $translations->setParent($this);
        $this->translations[] = $translations;

        return $this;
    }
1210528
protected function addTranslation($string, array $translations, $file)
    {
        if ($this->prepared && !isset($this->written[$file][$string]) && !empty($this->context)) {

            $data = array($string);

            if (isset($translations[$string][0]) && $translations[$string][0] !== '') {
                $data = $translations[$string];
                array_unshift($data, $string);
            }

            gplcart_file_csv($file, $data);
            $this->written[$file][$string] = true;
        }
    }
376585
public function addTranslation($translation)
    {
        $this->getTranslations()->set((string)$translation->getLocale(), $translation);
        $translation->setTranslatable($this);

        return $this;
    }
1005198
protected function replace($translation, $replacement = []) {
        foreach ($replacement as $key => $value) {
            $translation = str_replace(':'.$key, $value, $translation);
        }

        return $translation;
    }
768192
public function loadTranslations($translations)
    {
        if (is_object($translations) && $translations instanceof Translations) {
            $translations = PhpArray::generate($translations, ['includeHeaders' => false]);
        } elseif (is_string($translations) && is_file($translations)) {
            $translations = include $translations;
        } elseif (!is_array($translations)) {
            throw new \InvalidArgumentException(
                'Invalid Translator: only arrays, files or instance of Translations are allowed'
            );
        }

        $this->addTranslations($translations);

        return $this;
    }
846697
public function setTranslation(CategoryTranslationInterface $translation)
    {
        $translationEntity = $this->getTranslationByLocale($translation->getLocale());

        if (!$translationEntity) {
            $translationEntity = $translation;
            $this->entity->addTranslation($translationEntity);
        }

        $translationEntity->setCategory($this->entity);
        $translationEntity->setTranslation($translation->getTranslation());
        $translationEntity->setLocale($translation->getLocale());

        if (null === $this->getId() && null === $this->getDefaultLocale()) {
            // new entity and new translation
            // save first locale as default
            $this->entity->setDefaultLocale($translationEntity->getLocale());
        }
    }
642217
public function update(Translation $translation, FormRequest $request)
    {
        $this->repository->update($request->id, $request->all());

        return $this->redirect($request, $translation);
    }
513160
public function translate($key, $translation, $locale = null) {
        $this->translations[$this->locale($locale)][$key] = $translation;

        return $translation;
    }
644045
public function addTranslation(TranslationGroup $translationGroup, $locale, $text, $filename)
    {
        $translation = new \Kunstmaan\TranslatorBundle\Entity\Translation();
        $translation->setLocale($locale);
        $translation->setText($text);
        $translation->setDomain($translationGroup->getDomain());
        $translation->setFile($filename);
        $translation->setKeyword($translationGroup->getKeyword());
        $translation->setCreatedAt(new \DateTime());
        $translation->setUpdatedAt(new \DateTime());
        $translation->setTranslationId($translationGroup->getId());

        $this->translationRepository->persist($translation);
        $this->dbCopy[] = $translation;
    }
999234
protected function addTranslations(array $translations)
    {
        $domain = $translations['domain'] ?? '';

        //Set the first domain loaded as default domain
        if ($this->domain === null) {
            $this->domain = $domain;
        }

        if (isset($this->dictionary[$domain])) {
            $this->dictionary[$domain] = \array_replace_recursive($this->dictionary[$domain], $translations['messages']);

            return;
        }

        if (!empty($translations['plural-forms'])) {
            [$count, $code] = \array_map('trim', \explode(';', $translations['plural-forms'], 2));

            // extract just the expression turn 'n' into a php variable '$n'.
            // Slap on a return keyword and semicolon at the end.
            $this->plurals[$domain] = [
                'count' => (int) \str_replace('nplurals=', '', $count),
                'code' => \str_replace('plural=', 'return ', \str_replace('n', '$n', $code)).';',
            ];
        }

        $this->dictionary[$domain] = $translations['messages'];
    }
276557
public static function translate($string, Translation $translation = null) {
		if ($translation !== null) {
			$translation = self::get($translation->language, $translation->application_name);
		} else {
			$translation = self::get(\Application::get()->language, \Application::get()->name);
		}

		return $translation->translate_string($string);
	}
1061660
public function addTextDomain($domain, $path): void
    {
        // check path
        if (!is_dir($path)) {
            throw new ConfigurationException("Translator configuration path `$path` not found");
        }

        bindtextdomain($domain, $path);

        // @todo: hardcoded codeset
        bind_textdomain_codeset($domain, 'UTF-8');
    }
67676
public function addTranslationArray(array $translations, $language)
    {
        $language = (string) $language;
        if ($language === '') {
            throw new \InvalidArgumentException('$language cannot be empty');
        }

        if (!isset($this->translations[$language])) {
            $this->translations[$language] = [];
        }

        $this->translations[$language] = array_merge(
            $this->translations[$language],
            $translations
        );
    }
1037727
public void addFolderTranslation(String translation) {

        m_folderTranslations.add(translation);
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_ADD_FOLDER_TRANSLATION_1, translation));
        }
    }