-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to keep initial translated messages #370
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,11 @@ final class ConfigBuilder | |
*/ | ||
private $keepOldTranslations = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $keepOldTranslationsMessages = false; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here (keepOldTranslationMessages) |
||
/** | ||
* @var array | ||
*/ | ||
|
@@ -285,6 +290,17 @@ public function setKeepOldTranslations($value) | |
return $this; | ||
} | ||
|
||
/** | ||
* @param bool $value | ||
* @return $this | ||
*/ | ||
public function setKeepOldTranslationsMessages($value) | ||
{ | ||
$this->keepOldTranslationsMessages = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Config | ||
*/ | ||
|
@@ -302,6 +318,7 @@ public function getConfig() | |
$this->excludedNames, | ||
$this->enabledExtractors, | ||
$this->keepOldTranslations, | ||
$this->keepOldTranslationsMessages, | ||
$this->loadResources | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
use JMS\TranslationBundle\Model\MessageCatalogue; | ||
use JMS\TranslationBundle\Translation\Comparison\CatalogueComparator; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Translation\Translator; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
/** | ||
|
@@ -72,18 +73,24 @@ class Updater | |
*/ | ||
private $writer; | ||
|
||
/** | ||
* @var Translator | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @param LoaderManager $loader | ||
* @param ExtractorManager $extractor | ||
* @param LoggerInterface $logger | ||
* @param FileWriter $writer | ||
*/ | ||
public function __construct(LoaderManager $loader, ExtractorManager $extractor, LoggerInterface $logger, FileWriter $writer) | ||
public function __construct(LoaderManager $loader, ExtractorManager $extractor, LoggerInterface $logger, FileWriter $writer, Translator $translator) | ||
{ | ||
$this->loader = $loader; | ||
$this->extractor = $extractor; | ||
$this->logger = $logger; | ||
$this->writer = $writer; | ||
$this->translator = $translator; | ||
} | ||
|
||
/** | ||
|
@@ -277,5 +284,23 @@ private function setConfig(Config $config) | |
} | ||
} | ||
} | ||
|
||
//keep old translations translated | ||
if ($this->config->isKeepOldTranslationsMessages()) { | ||
|
||
$locale = $this->scannedCatalogue->getLocale(); | ||
/** @var MessageCatalogue $domainCatalogue */ | ||
foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) { | ||
|
||
/** @var Message $message */ | ||
foreach ($domainCatalogue->all() as $message) { | ||
|
||
$translated = $this->translator->trans($message->getId(), array(), $message->getDomain(), $locale); | ||
$message->setLocaleString($translated); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this seems odd to me that you are translating as you go. If all you want to do is keep any messages that were already there, why is this necessary? |
||
$message->setNew(false); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor nitpick, this variable should be named keepOldTranslationMessages (without the s on Translation)