/** * Merges this translations with other translations. * * @param Translations $translations The translations instance to merge with * @param int|null $method One or various Translations::MERGE_* constants to define how to merge the translations */ public function mergeWith(Translations $translations, $method = null) { if ($method === null) { $method = self::$mergeDefault; } if ($method & self::MERGE_HEADERS) { foreach ($translations->getHeaders() as $name => $value) { if (!$this->getHeader($name)) { $this->setHeader($name, $value); } } } $add = (bool) ($method & self::MERGE_ADD); foreach ($translations as $entry) { if ($existing = $this->find($entry)) { $existing->mergeWith($entry, $method); } elseif ($add) { $this[] = clone $entry; } } if ($method & self::MERGE_REMOVE) { $filtered = array(); foreach ($this as $entry) { if ($translations->find($entry)) { $filtered[] = $entry; } } $this->exchangeArray($filtered); } if ($method & self::MERGE_LANGUAGE) { $language = $translations->getLanguage(); $pluralForm = $translations->getPluralForms(); if (!$pluralForm) { if (!empty($language)) { $this->setLanguage($language); } } else { if (!empty($language)) { $this->setHeader(self::HEADER_LANGUAGE, $language); } $this->setPluralForms($pluralForm[0], $pluralForm[1]); } } }