Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • SensioLabs Professional services to help you with Symfony
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Translation
  4. How to Find Missing or Unused Translation Messages
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

How to Find Missing or Unused Translation Messages

Edit this page

Warning: You are browsing the documentation for Symfony 3.0, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

How to Find Missing or Unused Translation Messages

When maintaining an application or bundle, you may add or remove translation messages and forget to update the message catalogues. The debug:translation command helps you to find these missing or unused translation messages.

Thanks to the messages extractors, the command will detect the translation tag or filter usages in Twig templates:

1
2
3
4
5
6
7
{% trans %}Symfony2 is great{% endtrans %}

{{ 'Symfony2 is great'|trans }}

{{ 'Symfony2 is great'|transchoice(1) }}

{% transchoice 1 %}Symfony2 is great{% endtranschoice %}

It will also detect the following translator usages in PHP templates:

1
2
3
$view['translator']->trans("Symfony2 is great");

$view['translator']->transChoice('Symfony2 is great', 1);

Caution

The extractors are not able to inspect the messages translated outside templates which means that translator usages in form labels or inside your controllers won't be detected. Dynamic translations involving variables or expressions are not detected in templates, which means this example won't be analyzed:

1
2
{% set message = 'Symfony2 is great' %}
{{ message|trans }}

Suppose your application's default_locale is fr and you have configured en as the fallback locale (see Translations and Translations for how to configure these). And suppose you've already setup some translations for the fr locale inside an AcmeDemoBundle:

  • XML
  • YAML
  • PHP
1
2
3
4
5
6
7
8
9
10
11
12
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.xliff -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="file.ext">
        <body>
            <trans-unit id="1">
                <source>Symfony2 is great</source>
                <target>J'aime Symfony2</target>
            </trans-unit>
        </body>
    </file>
</xliff>
1
2
# src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.yml
Symfony2 is great: J'aime Symfony2
1
2
3
4
// src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.php
return array(
    'Symfony2 is great' => 'J\'aime Symfony2',
);

and for the en locale:

  • XML
  • YAML
  • PHP
1
2
3
4
5
6
7
8
9
10
11
12
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.en.xliff -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="file.ext">
        <body>
            <trans-unit id="1">
                <source>Symfony2 is great</source>
                <target>Symfony2 is great</target>
            </trans-unit>
        </body>
    </file>
</xliff>
1
2
# src/Acme/AcmeDemoBundle/Resources/translations/messages.en.yml
Symfony2 is great: Symfony2 is great
1
2
3
4
// src/Acme/AcmeDemoBundle/Resources/translations/messages.en.php
return array(
    'Symfony2 is great' => 'Symfony2 is great',
);

To inspect all messages in the fr locale for the AcmeDemoBundle, run:

1
$ php bin/console debug:translation fr AcmeDemoBundle

You will get this output:

It shows you a table with the result when translating the message in the fr locale and the result when the fallback locale en would be used. On top of that, it will also show you when the translation is the same as the fallback translation (this could indicate that the message was not correctly translated). Furthermore, it indicates that the message Symfony2 is great is unused because it is translated, but you haven't used it anywhere yet.

Now, if you translate the message in one of your templates, you will get this output:

The state is empty which means the message is translated in the fr locale and used in one or more templates.

If you delete the message Symfony2 is great from your translation file for the fr locale and run the command, you will get:

The state indicates the message is missing because it is not translated in the fr locale but it is still used in the template. Moreover, the message in the fr locale equals to the message in the en locale. This is a special case because the untranslated message id equals its translation in the en locale.

If you copy the content of the translation file in the en locale, to the translation file in the fr locale and run the command, you will get:

You can see that the translations of the message are identical in the fr and en locales which means this message was probably copied from French to English and maybe you forgot to translate it.

By default all domains are inspected, but it is possible to specify a single domain:

1
$ php bin/console debug:translation en AcmeDemoBundle --domain=messages

When bundles have a lot of messages, it is useful to display only the unused or only the missing messages, by using the --only-unused or --only-missing switches:

1
2
$ php bin/console debug:translation en AcmeDemoBundle --only-unused
$ php bin/console debug:translation en AcmeDemoBundle --only-missing
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Code consumes server resources. Blackfire tells you how

    Code consumes server resources. Blackfire tells you how

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Christopher Gross, a Symfony contributor

    Thanks Christopher Gross for being a Symfony contributor

    3 commits • 47 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony

    Search by Algolia