Skip to content

Commit 7bb9b0e

Browse files
committed
merged branch schmittjoh/translationFixes (PR #2213)
Commits ------- c0e6118 yet another fix cb9383d some more fixes 7a20b89 fixes some typos ac765fc avoid circular references 9b025b7 fixed typo Discussion ---------- Translation fixes
2 parents fb52078 + 888907c commit 7bb9b0e

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

Command/TranslationUpdateCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* A command that parse templates to extract translation messages and add them into the translation files.
25-
*
25+
*
2626
* @author Michel Salib <[email protected]>
2727
*/
2828
class TranslationUpdateCommand extends ContainerAwareCommand
@@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
8484
return;
8585
}
86-
86+
8787
// check format
8888
$writer = $this->getContainer()->get('translation.writer');
8989
$supportedFormats = $writer->getFormats();
@@ -100,18 +100,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100

101101
// create catalogue
102102
$catalogue = new MessageCatalogue($input->getArgument('locale'));
103-
103+
104104
// load any messages from templates
105105
$output->writeln('Parsing templates');
106106
$extractor = $this->getContainer()->get('translation.extractor');
107107
$extractor->setPrefix($input->getOption('prefix'));
108-
$extractor->extractMessages($foundBundle->getPath().'/Resources/views/', $catalogue);
109-
108+
$extractor->extract($foundBundle->getPath().'/Resources/views/', $catalogue);
109+
110110
// load any existing messages from the translation files
111111
$output->writeln('Loading translation files');
112112
$loader = $this->getContainer()->get('translation.loader');
113113
$loader->loadMessages($bundleTransPath, $catalogue);
114-
114+
115115
// show compiled list of messages
116116
if($input->getOption('dump-messages') === true){
117117
foreach ($catalogue->getDomains() as $domain) {

DependencyInjection/Compiler/TranslationExtractorPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function process(ContainerBuilder $container)
2929
$definition = $container->getDefinition('translation.extractor');
3030

3131
foreach ($container->findTaggedServiceIds('translation.extractor') as $id => $attributes) {
32+
if (!isset($attributes[0]['alias'])) {
33+
throw new \RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
34+
}
35+
3236
$definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
3337
}
3438
}

Translation/TranslationLoader.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@
1717

1818
/**
1919
* TranslationLoader loads translation messages from translation files.
20-
*
20+
*
2121
* @author Michel Salib <[email protected]>
2222
*/
2323
class TranslationLoader
2424
{
2525
/**
2626
* Loaders used for import.
27-
*
27+
*
2828
* @var array
2929
*/
3030
private $loaders = array();
31-
31+
3232
/**
3333
* Adds a loader to the translation extractor.
3434
* @param string $format The format of the loader
35-
* @param LoaderInterface $loader
35+
* @param LoaderInterface $loader
3636
*/
3737
public function addLoader($format, LoaderInterface $loader)
3838
{
3939
$this->loaders[$format] = $loader;
4040
}
41-
41+
4242
/**
4343
* Loads translation messages from a directory to the catalogue.
44-
*
44+
*
4545
* @param string $directory the directory to look into
4646
* @param MessageCatalogue $catalogue the catalogue
4747
*/
@@ -50,10 +50,11 @@ public function loadMessages($directory, MessageCatalogue $catalogue)
5050
foreach($this->loaders as $format => $loader) {
5151
// load any existing translation files
5252
$finder = new Finder();
53-
$files = $finder->files()->name('*.'.$catalogue->getLocale().$format)->in($directory);
53+
$extension = $catalogue->getLocale().'.'.$format;
54+
$files = $finder->files()->name('*.'.$extension)->in($directory);
5455
foreach ($files as $file) {
55-
$domain = substr($file->getFileName(), 0, strrpos($file->getFileName(), $input->getArgument('locale').$format) - 1);
56-
$catalogue->addCatalogue($loader->load($file->getPathname(), $input->getArgument('locale'), $domain));
56+
$domain = substr($file->getFileName(), 0, -1 * strlen($extension) - 1);
57+
$catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain));
5758
}
5859
}
5960
}

0 commit comments

Comments
 (0)