@@ -673,28 +673,38 @@ tag or filter usages in Twig templates:
673
673
674
674
{{ 'Symfony2 is great'|trans }}
675
675
676
+ {{ 'Symfony2 is great'|transchoice(1) }}
677
+
678
+ {% transchoice 1 %}Symfony2 is great{% endtranschoice %}
679
+
676
680
It will also detect the following translator usages in PHP templates:
677
681
678
682
.. code-block :: php
679
683
680
684
$view['translator']->trans("Symfony2 is great");
681
685
682
- $view['translator']->trans(‘Symfony2 is great’);
686
+ $view['translator']->trans('Symfony2 is great');
687
+
688
+ .. caution ::
683
689
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:
686
694
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 }}
689
698
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:
692
702
693
703
.. configuration-block ::
694
704
695
705
.. code-block :: xml
696
706
697
- <!-- messages.fr.xliff -->
707
+ <!-- src/Acme/AcmeDemoBundle/Resources/translations/ messages.fr.xliff -->
698
708
<?xml version =" 1.0" ?>
699
709
<xliff version =" 1.2" xmlns =" urn:oasis:names:tc:xliff:document:1.2" >
700
710
<file source-language =" en" datatype =" plaintext" original =" file.ext" >
@@ -709,14 +719,14 @@ in the ``fr`` locale contains:
709
719
710
720
.. code-block :: php
711
721
712
- // messages.fr.php
722
+ // src/Acme/AcmeDemoBundle/Resources/translations/ messages.fr.php
713
723
return array(
714
724
'Symfony2 is great' => 'J\'aime Symfony2',
715
725
);
716
726
717
727
.. code-block :: yaml
718
728
719
- # messages.fr.yml
729
+ # src/Acme/AcmeDemoBundle/Resources/translations/ messages.fr.yml
720
730
Symfony2 is great : J'aime Symfony2
721
731
722
732
and for the ``en `` locale:
@@ -725,7 +735,7 @@ and for the ``en`` locale:
725
735
726
736
.. code-block :: xml
727
737
728
- <!-- messages.en.xliff -->
738
+ <!-- src/Acme/AcmeDemoBundle/Resources/translations/ messages.en.xliff -->
729
739
<?xml version =" 1.0" ?>
730
740
<xliff version =" 1.2" xmlns =" urn:oasis:names:tc:xliff:document:1.2" >
731
741
<file source-language =" en" datatype =" plaintext" original =" file.ext" >
@@ -740,14 +750,14 @@ and for the ``en`` locale:
740
750
741
751
.. code-block :: php
742
752
743
- // messages.en.php
753
+ // src/Acme/AcmeDemoBundle/Resources/translations/ messages.en.php
744
754
return array(
745
755
'Symfony2 is great' => 'Symfony2 is great',
746
756
);
747
757
748
758
.. code-block :: yaml
749
759
750
- # messages.en.yml
760
+ # src/Acme/AcmeDemoBundle/Resources/translations/ messages.en.yml
751
761
Symfony2 is great : Symfony2 is great
752
762
753
763
To inspect all messages in the ``fr `` locale for the AcmeDemoBundle, run:
@@ -761,16 +771,15 @@ You will get this output:
761
771
.. image :: /images/book/translation/debug_1.png
762
772
:align: center
763
773
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.
766
776
767
777
Now, if you translate the message in one of your templates, you will get this output:
768
778
769
779
.. image :: /images/book/translation/debug_2.png
770
780
:align: center
771
781
772
782
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.
774
783
775
784
If you delete the message ``Symfony2 is great `` from your translation file for the ``fr `` locale
776
785
and run the command, you will get:
@@ -780,7 +789,7 @@ and run the command, you will get:
780
789
781
790
The state indicates the message is missing because it is not translated in the ``fr `` locale
782
791
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.
784
793
This is a special case because the untranslated message id equals its translation in the ``en `` locale.
785
794
786
795
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:
789
798
.. image :: /images/book/translation/debug_4.png
790
799
:align: center
791
800
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 .
794
803
795
804
By default all domains are inspected, but it is possible to specify a single domain:
796
805
0 commit comments