Skip to content

Added documentation for translation:debug #3629

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

Merged
merged 4 commits into from
Mar 17, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improved the documentation with examples and images
  • Loading branch information
florianv committed Mar 13, 2014
commit 38b2955966776d2836106bd1650e820b87e4b748
134 changes: 129 additions & 5 deletions book/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -657,25 +657,149 @@ Debugging Translations

When maintaining a bundle, you may use or remove the usage of a translation
message without updating all message catalogues. The ``translation:debug``
command helps you finding these missing or unused translation messages for a
command helps you to find these missing or unused translation messages for a
given locale. It shows you a table with the result when translating the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florianv I really like this feature! To make it easier to understand (and use), I think we should show the first usage (so, the code-block you have below) right after "... given locale" AND I think we should include some sample output of what it might look like. Then, we can continue the descriptions you have here, but actually point out what we mean by referencing the sample output.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @weaverryan
I have added some screenshots and modified it so people can follow it like a tutorial.
Please let me know what you think.

message in the given locale and the result when the fallback would be used.
On top of that, it also shows you when the translation is the same as the
fallback translation (this could indicate that the message was not correctly
translated). To inspect all messages in the ``en`` locale for the AcmeDemoBundle, run:
translated).

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

.. code-block:: jinja

{% trans %}Symfony2 is great{% endtrans %}

{{ 'Symfony2 is great'|trans }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add an example using transchoice as well, which is detected


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

.. code-block:: php

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

$view['translator']->trans(‘Symfony2 is great’);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use ', not . Otherwise your code is invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch


Supposing your application default_locale is French ``fr`` and you have enabled
the translator in your configuration with English ``en`` as fallback locale.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended rewording - this would be immediately followed by the configuration-block

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


See :ref:`book-translation-configuration` and :ref:`book-translation-fallback` for details
about how to configure these.

You are working on the AcmeDemoBundle and the translation file for the ``messages`` domain
in the ``fr`` locale contains:

.. configuration-block::

.. code-block:: xml

<!-- messages.fr.xliff -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the full path here, 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>

.. code-block:: php

// messages.fr.php
return array(
'Symfony2 is great' => 'J\'aime Symfony2',
);

.. code-block:: yaml

# messages.fr.yml
Symfony2 is great: J'aime Symfony2

and for the ``en`` locale:

.. configuration-block::

.. code-block:: xml

<!-- 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>

.. code-block:: php

// messages.en.php
return array(
'Symfony2 is great' => 'Symfony2 is great',
);

.. code-block:: yaml

# messages.en.yml
Symfony2 is great: Symfony2 is great

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

.. code-block:: bash

$ php app/console translation:debug en AcmeDemoBundle
$ php app/console translation:debug fr AcmeDemoBundle

You will get this output:

.. image:: /images/book/translation/debug_1.png
:align: center

It indicates the message with id ``Symfony2 is great`` is unused because it is translated
but we don’t use it in any template yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indicates that the message Symfony2 is great is unused because it is translated, but you haven't used it anywhere yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thiknk this also deserves a warning about the fact that the transaltion may be used in a place where it cannot be detected by the extractor (for instance a form label)


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... if you translate the message somewhere (e.g. like in a template), you will ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extractors will detect only the usages in the templates, I think it deserves a warning as @stof mentionned.
Maybe around line 683 after explaining the extractors ?


.. image:: /images/book/translation/debug_2.png
:align: center

The state is empty which means the message is translated in the ``fr`` locale and used in one or more templates.
Moreover, we see the translation is different than the ``en`` one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete the "Moreover" sentence - I wasn't totally clear of what it was saying, and I think it makes good sense still without it.


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

.. image:: /images/book/translation/debug_3.png
:align: center

The state indicates the message is missing because it is not translated in the ``fr`` locale
but it is still used in the template.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add a little emphasis :)

but it is still

Moreover, we see the message in the ``fr`` locale equals to the message in the ``en`` locale.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should move this back up onto the line before it.

Moreover, the message

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:

.. image:: /images/book/translation/debug_4.png
:align: center

We observe the translations of the message are identical in the ``fr`` and ``en`` locales
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 or vice versa (which is the case).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... 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:

.. code-block:: bash

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

You can also display only the unused or only the missing messages, by using
the ``--only-unused`` or ``--only-missing`` switches:
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:

.. code-block:: bash

Expand Down
Binary file added images/book/translation/debug_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/book/translation/debug_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/book/translation/debug_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/book/translation/debug_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy