@@ -107,13 +107,12 @@ of text (called a *message*), use the
107107for example, that you're translating a simple message from inside a controller::
108108
109109 // ...
110- use Symfony\Component\HttpFoundation\Response;
111110
112111 public function indexAction()
113112 {
114113 $translated = $this->get('translator')->trans('Symfony is great');
115114
116- return new Response($translated);
115+ // ...
117116 }
118117
119118.. _translation-resources :
@@ -185,13 +184,11 @@ Message Placeholders
185184
186185Sometimes, a message containing a variable needs to be translated::
187186
188- use Symfony\Component\HttpFoundation\Response;
189-
190187 public function indexAction($name)
191188 {
192189 $translated = $this->get('translator')->trans('Hello '.$name);
193190
194- return new Response($translated);
191+ // ...
195192 }
196193
197194However, creating a translation for this string is impossible since the translator
@@ -258,11 +255,11 @@ You can also specify the message domain and pass some additional variables:
258255
259256.. code-block :: twig
260257
261- {% trans with {'%name%': 'Fabien'} from " app" %}Hello %name%{% endtrans %}
258+ {% trans with {'%name%': 'Fabien'} from ' app' %}Hello %name%{% endtrans %}
262259
263- {% trans with {'%name%': 'Fabien'} from " app" into "fr" %}Hello %name%{% endtrans %}
260+ {% trans with {'%name%': 'Fabien'} from ' app' into 'fr' %}Hello %name%{% endtrans %}
264261
265- {% transchoice count with {'%name%': 'Fabien'} from " app" %}
262+ {% transchoice count with {'%name%': 'Fabien'} from ' app' %}
266263 {0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf[ %name%, there are %count% apples
267264 {% endtranschoice %}
268265
@@ -277,7 +274,7 @@ texts* and complex expressions:
277274
278275 {{ message|transchoice(5) }}
279276
280- {{ message|trans({'%name%': 'Fabien'}, " app" ) }}
277+ {{ message|trans({'%name%': 'Fabien'}, ' app' ) }}
281278
282279 {{ message|transchoice(5, {'%name%': 'Fabien'}, 'app') }}
283280
@@ -308,7 +305,7 @@ texts* and complex expressions:
308305
309306 .. code-block :: twig
310307
311- {% trans_default_domain " app" %}
308+ {% trans_default_domain ' app' %}
312309
313310 Note that this only influences the current template, not any "included"
314311 template (in order to avoid side effects).
@@ -329,6 +326,33 @@ The translator service is accessible in PHP templates through the
329326 array('%count%' => 10)
330327 ) ?>
331328
329+ Extracting Translation Contents and Updating Catalogs Automatically
330+ -------------------------------------------------------------------
331+
332+ The most time-consuming tasks when translating an application is to extract all
333+ the template contents to be translated and to keep all the translation files in
334+ sync. Symfony includes a command called ``translation:update `` that helps you
335+ with these tasks:
336+
337+ .. code-block :: terminal
338+
339+ # updates the French translation file with the missing strings found in app/Resources/ templates
340+ $ ./app/console translation:update --dump-messages --force fr
341+
342+ # updates the English translation file with the missing strings found in AppBundle
343+ $ ./app/console translation:update --dump-messages --force en AppBundle
344+
345+ .. note ::
346+
347+ If you want to see the missing translation strings without actually updating
348+ the translation files, remove the ``--force `` option from the command above.
349+
350+ .. tip ::
351+
352+ If you need to extract translation strings from other sources, such as
353+ controllers, forms and flash messages, consider using the more advanced
354+ third-party `TranslationBundle `_.
355+
332356.. _translation-resource-locations :
333357
334358Translation Resource/File Names and Locations
@@ -412,8 +436,8 @@ checks translation resources for several locales:
412436
413437.. note ::
414438
415- When Symfony doesn't find a translation in the given locale, it will
416- add the missing translation to the log file. For details,
439+ When Symfony doesn't find a translation in the given locale, it will
440+ add the missing translation to the log file. For details,
417441 see :ref: `reference-framework-translator-logging `.
418442
419443Handling the User's Locale
@@ -470,3 +494,4 @@ Learn more
470494.. _`ISO 639-1` : https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
471495.. _`Translatable Extension` : http://atlantic18.github.io/DoctrineExtensions/doc/translatable.html
472496.. _`Translatable Behavior` : https://github.com/KnpLabs/DoctrineBehaviors
497+ .. _`TranslationBundle` : https://github.com/php-translation/symfony-bundle
0 commit comments