Skip to content

Commit b6ac454

Browse files
committed
Fixed the issues
1 parent 38b2955 commit b6ac454

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

book/translation.rst

+28-19
Original file line numberDiff line numberDiff line change
@@ -673,28 +673,38 @@ tag or filter usages in Twig templates:
673673
674674
{{ 'Symfony2 is great'|trans }}
675675
676+
{{ 'Symfony2 is great'|transchoice(1) }}
677+
678+
{% transchoice 1 %}Symfony2 is great{% endtranschoice %}
679+
676680
It will also detect the following translator usages in PHP templates:
677681

678682
.. code-block:: php
679683
680684
$view['translator']->trans("Symfony2 is great");
681685
682-
$view['translator']->trans(‘Symfony2 is great’);
686+
$view['translator']->trans('Symfony2 is great');
687+
688+
.. caution::
683689

684-
Supposing your application default_locale is French ``fr`` and you have enabled
685-
the translator in your configuration with English ``en`` as fallback locale.
690+
The extractors are not able to inspect the messages translated outside templates which means
691+
that translator usages in form labels or inside your controllers won't be detected.
692+
Dynamic translations involving variables or expressions are not detected in templates,
693+
which means this example won't be analyzed:
686694

687-
See :ref:`book-translation-configuration` and :ref:`book-translation-fallback` for details
688-
about how to configure these.
695+
.. code-block:: jinja
696+
{% set message = 'Symfony2 is great' %}
697+
{{ message|trans }}
689698
690-
You are working on the AcmeDemoBundle and the translation file for the ``messages`` domain
691-
in the ``fr`` locale contains:
699+
Suppose your application's default_locale is ``fr`` and you have configured ``en`` as the fallback locale
700+
(see :ref:`book-translation-configuration` and :ref:`book-translation-fallback` for how to configure these).
701+
And suppose you've already setup some translations for the ``fr`` locale inside an AcmeDemoBundle:
692702

693703
.. configuration-block::
694704

695705
.. code-block:: xml
696706
697-
<!-- messages.fr.xliff -->
707+
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.xliff -->
698708
<?xml version="1.0"?>
699709
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
700710
<file source-language="en" datatype="plaintext" original="file.ext">
@@ -709,14 +719,14 @@ in the ``fr`` locale contains:
709719
710720
.. code-block:: php
711721
712-
// messages.fr.php
722+
// src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.php
713723
return array(
714724
'Symfony2 is great' => 'J\'aime Symfony2',
715725
);
716726
717727
.. code-block:: yaml
718728
719-
# messages.fr.yml
729+
# src/Acme/AcmeDemoBundle/Resources/translations/messages.fr.yml
720730
Symfony2 is great: J'aime Symfony2
721731
722732
and for the ``en`` locale:
@@ -725,7 +735,7 @@ and for the ``en`` locale:
725735

726736
.. code-block:: xml
727737
728-
<!-- messages.en.xliff -->
738+
<!-- src/Acme/AcmeDemoBundle/Resources/translations/messages.en.xliff -->
729739
<?xml version="1.0"?>
730740
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
731741
<file source-language="en" datatype="plaintext" original="file.ext">
@@ -740,14 +750,14 @@ and for the ``en`` locale:
740750
741751
.. code-block:: php
742752
743-
// messages.en.php
753+
// src/Acme/AcmeDemoBundle/Resources/translations/messages.en.php
744754
return array(
745755
'Symfony2 is great' => 'Symfony2 is great',
746756
);
747757
748758
.. code-block:: yaml
749759
750-
# messages.en.yml
760+
# src/Acme/AcmeDemoBundle/Resources/translations/messages.en.yml
751761
Symfony2 is great: Symfony2 is great
752762
753763
To inspect all messages in the ``fr`` locale for the AcmeDemoBundle, run:
@@ -761,16 +771,15 @@ You will get this output:
761771
.. image:: /images/book/translation/debug_1.png
762772
:align: center
763773

764-
It indicates the message with id ``Symfony2 is great`` is unused because it is translated
765-
but we don’t use it in any template yet.
774+
It indicates that the message ``Symfony2 is great`` is unused because it is translated,
775+
but you haven't used it anywhere yet.
766776

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

769779
.. image:: /images/book/translation/debug_2.png
770780
:align: center
771781

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

775784
If you delete the message ``Symfony2 is great`` from your translation file for the ``fr`` locale
776785
and run the command, you will get:
@@ -780,7 +789,7 @@ and run the command, you will get:
780789

781790
The state indicates the message is missing because it is not translated in the ``fr`` locale
782791
but it is still used in the template.
783-
Moreover, we see the message in the ``fr`` locale equals to the message in the ``en`` locale.
792+
Moreover, the message in the ``fr`` locale equals to the message in the ``en`` locale.
784793
This is a special case because the untranslated message id equals its translation in the ``en`` locale.
785794

786795
If you copy the content of the translation file in the ``en`` locale, to the translation file
@@ -789,8 +798,8 @@ in the ``fr`` locale and run the command, you will get:
789798
.. image:: /images/book/translation/debug_4.png
790799
:align: center
791800

792-
We observe the translations of the message are identical in the ``fr`` and ``en`` locales
793-
which means this message was probably copied from French to English or vice versa (which is the case).
801+
You can see that the translations of the message are identical in the ``fr`` and ``en`` locales
802+
which means this message was probably copied from French to English and maybe you forgot to translate it.
794803

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

0 commit comments

Comments
 (0)