merged branch schmittjoh/translationFixes (PR #2213)
Commits -------c0e6118
yet another fixcb9383d
some more fixes7a20b89
fixes some typosac765fc
avoid circular references9b025b7
fixed typo Discussion ---------- Translation fixes
This commit is contained in:
commit
01a24db500
@ -22,7 +22,7 @@ use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* A command that parse templates to extract translation messages and add them into the translation files.
|
||||
*
|
||||
*
|
||||
* @author Michel Salib <michelsalib@hotmail.com>
|
||||
*/
|
||||
class TranslationUpdateCommand extends ContainerAwareCommand
|
||||
@ -83,7 +83,7 @@ EOF
|
||||
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check format
|
||||
$writer = $this->getContainer()->get('translation.writer');
|
||||
$supportedFormats = $writer->getFormats();
|
||||
@ -100,18 +100,18 @@ EOF
|
||||
|
||||
// create catalogue
|
||||
$catalogue = new MessageCatalogue($input->getArgument('locale'));
|
||||
|
||||
|
||||
// load any messages from templates
|
||||
$output->writeln('Parsing templates');
|
||||
$extractor = $this->getContainer()->get('translation.extractor');
|
||||
$extractor->setPrefix($input->getOption('prefix'));
|
||||
$extractor->extractMessages($foundBundle->getPath().'/Resources/views/', $catalogue);
|
||||
|
||||
$extractor->extract($foundBundle->getPath().'/Resources/views/', $catalogue);
|
||||
|
||||
// load any existing messages from the translation files
|
||||
$output->writeln('Loading translation files');
|
||||
$loader = $this->getContainer()->get('translation.loader');
|
||||
$loader->loadMessages($bundleTransPath, $catalogue);
|
||||
|
||||
|
||||
// show compiled list of messages
|
||||
if($input->getOption('dump-messages') === true){
|
||||
foreach ($catalogue->getDomains() as $domain) {
|
||||
|
@ -29,6 +29,10 @@ class TranslationExtractorPass implements CompilerPassInterface
|
||||
$definition = $container->getDefinition('translation.extractor');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('translation.extractor') as $id => $attributes) {
|
||||
if (!isset($attributes[0]['alias'])) {
|
||||
throw new \RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
||||
}
|
||||
|
||||
$definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
|
||||
}
|
||||
}
|
||||
|
@ -17,31 +17,31 @@ use Symfony\Component\Translation\Loader\LoaderInterface;
|
||||
|
||||
/**
|
||||
* TranslationLoader loads translation messages from translation files.
|
||||
*
|
||||
*
|
||||
* @author Michel Salib <michelsalib@hotmail.com>
|
||||
*/
|
||||
class TranslationLoader
|
||||
{
|
||||
/**
|
||||
* Loaders used for import.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $loaders = array();
|
||||
|
||||
|
||||
/**
|
||||
* Adds a loader to the translation extractor.
|
||||
* @param string $format The format of the loader
|
||||
* @param LoaderInterface $loader
|
||||
* @param LoaderInterface $loader
|
||||
*/
|
||||
public function addLoader($format, LoaderInterface $loader)
|
||||
{
|
||||
$this->loaders[$format] = $loader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads translation messages from a directory to the catalogue.
|
||||
*
|
||||
*
|
||||
* @param string $directory the directory to look into
|
||||
* @param MessageCatalogue $catalogue the catalogue
|
||||
*/
|
||||
@ -50,10 +50,11 @@ class TranslationLoader
|
||||
foreach($this->loaders as $format => $loader) {
|
||||
// load any existing translation files
|
||||
$finder = new Finder();
|
||||
$files = $finder->files()->name('*.'.$catalogue->getLocale().$format)->in($directory);
|
||||
$extension = $catalogue->getLocale().'.'.$format;
|
||||
$files = $finder->files()->name('*.'.$extension)->in($directory);
|
||||
foreach ($files as $file) {
|
||||
$domain = substr($file->getFileName(), 0, strrpos($file->getFileName(), $input->getArgument('locale').$format) - 1);
|
||||
$catalogue->addCatalogue($loader->load($file->getPathname(), $input->getArgument('locale'), $domain));
|
||||
$domain = substr($file->getFileName(), 0, -1 * strlen($extension) - 1);
|
||||
$catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +182,10 @@ class Translator implements TranslatorInterface
|
||||
{
|
||||
$current = $this->catalogues[$locale];
|
||||
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
||||
if ($fallback === $locale) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($this->catalogues[$fallback])) {
|
||||
$this->doLoadCatalogue($fallback);
|
||||
}
|
||||
|
Reference in New Issue
Block a user