@@ -126,7 +126,7 @@ for example, that you're translating a simple message from inside a controller::
126126 {
127127 $translated = $translator->trans('Symfony is great');
128128
129- return new Response($translated);
129+ // ...
130130 }
131131
132132.. _translation-resources :
@@ -205,7 +205,7 @@ Sometimes, a message containing a variable needs to be translated::
205205 {
206206 $translated = $translator->trans('Hello '.$name);
207207
208- return new Response($translated);
208+ // ...
209209 }
210210
211211However, creating a translation for this string is impossible since the translator
@@ -272,11 +272,11 @@ You can also specify the message domain and pass some additional variables:
272272
273273.. code-block :: twig
274274
275- {% trans with {'%name%': 'Fabien'} from " app" %}Hello %name%{% endtrans %}
275+ {% trans with {'%name%': 'Fabien'} from ' app' %}Hello %name%{% endtrans %}
276276
277- {% trans with {'%name%': 'Fabien'} from " app" into "fr" %}Hello %name%{% endtrans %}
277+ {% trans with {'%name%': 'Fabien'} from ' app' into 'fr' %}Hello %name%{% endtrans %}
278278
279- {% transchoice count with {'%name%': 'Fabien'} from " app" %}
279+ {% transchoice count with {'%name%': 'Fabien'} from ' app' %}
280280 {0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf[ %name%, there are %count% apples
281281 {% endtranschoice %}
282282
@@ -291,7 +291,7 @@ texts* and complex expressions:
291291
292292 {{ message|transchoice(5) }}
293293
294- {{ message|trans({'%name%': 'Fabien'}, " app" ) }}
294+ {{ message|trans({'%name%': 'Fabien'}, ' app' ) }}
295295
296296 {{ message|transchoice(5, {'%name%': 'Fabien'}, 'app') }}
297297
@@ -322,7 +322,7 @@ texts* and complex expressions:
322322
323323 .. code-block :: twig
324324
325- {% trans_default_domain " app" %}
325+ {% trans_default_domain ' app' %}
326326
327327 Note that this only influences the current template, not any "included"
328328 template (in order to avoid side effects).
@@ -343,6 +343,33 @@ The translator service is accessible in PHP templates through the
343343 array('%count%' => 10)
344344 ) ?>
345345
346+ Extracting Translation Contents and Updating Catalogs Automatically
347+ -------------------------------------------------------------------
348+
349+ The most time-consuming tasks when translating an application is to extract all
350+ the template contents to be translated and to keep all the translation files in
351+ sync. Symfony includes a command called ``translation:update `` that helps you
352+ with these tasks:
353+
354+ .. code-block :: terminal
355+
356+ # updates the French translation file with the missing strings found in app/Resources/ templates
357+ $ ./bin/console translation:update --dump-messages --force fr
358+
359+ # updates the English translation file with the missing strings found in AppBundle
360+ $ ./bin/console translation:update --dump-messages --force en AppBundle
361+
362+ .. note ::
363+
364+ If you want to see the missing translation strings without actually updating
365+ the translation files, remove the ``--force `` option from the command above.
366+
367+ .. tip ::
368+
369+ If you need to extract translation strings from other sources, such as
370+ controllers, forms and flash messages, consider using the more advanced
371+ third-party `TranslationBundle `_.
372+
346373.. _translation-resource-locations :
347374
348375Translation Resource/File Names and Locations
@@ -528,3 +555,4 @@ Learn more
528555.. _`ISO 639-1` : https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
529556.. _`Translatable Extension` : http://atlantic18.github.io/DoctrineExtensions/doc/translatable.html
530557.. _`Translatable Behavior` : https://github.com/KnpLabs/DoctrineBehaviors
558+ .. _`TranslationBundle` : https://github.com/php-translation/symfony-bundle
0 commit comments