Skip to content

[Translator] [FrameworkBundle] Translation loader - ignore locale #9225

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));

// load any messages from templates
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$extractedCatalogue = new MessageCatalogue(null);
$output->writeln('Parsing templates');
$extractor = $this->getContainer()->get('translation.extractor');
$extractor->setPrefix($input->getOption('prefix'));
$extractor->extract($foundBundle->getPath().'/Resources/views/', $extractedCatalogue);

// load any existing messages from the translation files
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$output->writeln('Loading translation files');
$loader = $this->getContainer()->get('translation.loader');

$fallbackCatalogue = new MessageCatalogue(null);
$loader->loadMessages($bundleTransPath, $fallbackCatalogue);

$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$loader->loadMessages($bundleTransPath, $currentCatalogue);
$currentCatalogue->addFallbackCatalogue($fallbackCatalogue);

// process catalogues
$operation = $input->getOption('clean')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function loadMessages($directory, MessageCatalogue $catalogue)
foreach ($this->loaders as $format => $loader) {
// load any existing translation files
$finder = new Finder();
$extension = $catalogue->getLocale().'.'.$format;
$extension = $catalogue->getLocale() === null ? $format : $catalogue->getLocale().'.'.$format;
$files = $finder->files()->name('*.'.$extension)->in($directory);
foreach ($files as $file) {
$domain = substr($file->getFileName(), 0, -1 * strlen($extension) - 1);
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Translation/MessageCatalogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public function replace($messages, $domain = 'messages')
*/
public function add($messages, $domain = 'messages')
{
if ($this->locale === null) {
$messages = array_fill_keys(array_keys($messages), null);
}

if (!isset($this->messages[$domain])) {
$this->messages[$domain] = $messages;
} else {
Expand All @@ -164,7 +168,7 @@ public function add($messages, $domain = 'messages')
*/
public function addCatalogue(MessageCatalogueInterface $catalogue)
{
if ($catalogue->getLocale() !== $this->locale) {
if ($this->locale !== null && $catalogue->getLocale() !== $this->locale) {
throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
}

Expand Down