2
votes

I have a symfony project in which I've been through my twig templates and added {% trans %}...{% endtrans %} or adding translations like {{ title|trans }} where appropriate. I've also added a messages.de.xliff file and that is working perfectly for the few translations I have tried.

Is there a way I can get a list of strings missing from my xliff file? It's quite hard to keep track of every translation as I add it. It seems like it should log a failure to get a translation in a log file somewhere, but I've been googling a while and can't find anything.

5

5 Answers

2
votes

Hi Try following May Be helpful.

https://github.com/schmittjoh/JMSTranslationBundle/blob/master/Resources/doc/index.rst

Very powerful tool and definitely takes care of you problem.

1
votes

This is a very crappy patch to apply in vendor/symfony that does what I need. Probably not to be run on a production server!

diff --git a/src/Symfony/Component/Translation/MessageCatalogue.php b/src/Symfony/Component/Translation/MessageCatalogue.php
index b55676f..98a5cba 100644
--- a/src/Symfony/Component/Translation/MessageCatalogue.php
+++ b/src/Symfony/Component/Translation/MessageCatalogue.php
@@ -128,6 +128,8 @@ class MessageCatalogue implements MessageCatalogueInterface
             return $this->fallbackCatalogue->get($id, $domain);
         }

+        error_log('Translation not found: "' . $id . '"');
+
         return $id;
     }
0
votes

My solution was to overwrite the Translator and MessageCatalogue classes.

Translator:

class RegisteringTranslator extends \Symfony\Component\Translation\Translator
{
    protected function loadCatalogue($locale)
    {
        parent::loadCatalogue($locale);

        if ( ! $this->catalogues[$locale] instanceof RegisteringMessageCatalogue) {
            $registeringCatalogue = new RegisteringMessageCatalogue($locale);
            $registeringCatalogue->addCatalogue($this->catalogues[$locale]);
            $this->catalogues[$locale] = $registeringCatalogue;
        }
    }
}

Catalogue:

class RegisteringMessageCatalogue extends \Symfony\Component\Translation\MessageCatalogue
{
    public function get($id, $domain = 'messages')
    {
        if ( ! $this->has($id, $domain)) {
            error_log('Translation not found: "' . $id . '"');
        }

        return parent::get($id, $domain);
    }

}

Of course you need to use the new Translator class.

Also not very nice because it uses the protected methods and properties of Translator class. But better than changing the Symfony code directly.

0
votes

I know this is an old question, but I'm posting here just in case somebody still has the same problem.

Starting from Symfony 2.6, you'll find a very nice addition to the web debug toolbar that shows how many translations you're missing.

enter image description here

By clicking it, the profiler will display a detailed list of missing translation.

Works out of the box, without any configuration.

0
votes

Normally you should be able to use the Symfony command debug:translation via app/console.

Something like this:

$ php app/console debug:translation --only-missing <locale> <Bundle Name>

A concrete example would be:

$ php app/console debug:translation --only-missing nl AppBundle

That would output:

 ----------- ---------- ------------------------------------------------------------------------------------------------------- ------------------------------------------
  State       Domain     Id                                                                                                      Message Preview (nl)
 ----------- ---------- ------------------------------------------------------------------------------------------------------- ------------------------------------------
   missing    messages   Create a clean selection                                                                                Create a clean selection
   missing    messages   New Selection                                                                                           New Selection
   missing    messages   login.labels.geoserver_url                                                                              login.labels.geoserver_url