Skip to content

Commit 8acfbc8

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Added minor clarification about what StudlyCaps is Update best_practices.rst Removed the reference to specific Symfony files Added a new section "Extracting Translation Contents and Updating Cat… Moved the note before the label Minor reword moved the tips to an include fragment file added a tip to register annotations namespaces
2 parents 786090d + ac99784 commit 8acfbc8

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. note::
2+
3+
In order to use the annotation loader, you should have installed the
4+
``doctrine/annotations`` and ``doctrine/cache`` packages with Composer.
5+
6+
.. tip::
7+
8+
Annotation classes aren't loaded automatically, so you must load them
9+
using a class loader like this::
10+
11+
      use Composer\Autoload\ClassLoader;
12+
use Doctrine\Common\Annotations\AnnotationRegistry;
13+
14+
/** @var ClassLoader $loader */
15+
$loader = require __DIR__.'/../vendor/autoload.php';
16+
17+
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
18+
19+
return $loader;

bundles/best_practices.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A namespace becomes a bundle as soon as you add a bundle class to it. The
3737
bundle class name must follow these simple rules:
3838

3939
* Use only alphanumeric characters and underscores;
40-
* Use a CamelCased name;
40+
* Use a StudlyCaps name (i.e. camelCase with the first letter uppercased);
4141
* Use a descriptive and short name (no more than two words);
4242
* Prefix the name with the concatenation of the vendor (and optionally the
4343
category namespaces);

components/routing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ Last but not least there are
312312
route definitions from class annotations. The specific details are left
313313
out here.
314314

315+
.. include:: /_includes/_rewrite_rule_tip.rst.inc
316+
315317
The all-in-one Router
316318
~~~~~~~~~~~~~~~~~~~~~
317319

components/serializer.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ You are now able to serialize only attributes in the groups you want::
310310
);
311311
// $obj2 = MyObj(foo: 'foo', bar: 'bar')
312312

313+
.. include:: /_includes/_rewrite_rule_tip.rst.inc
314+
313315
.. _ignoring-attributes-when-serializing:
314316

315317
Ignoring Attributes

components/validator/resources.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ method. It takes an optional annotation reader instance, which defaults to
119119
To disable the annotation loader after it was enabled, call
120120
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping`.
121121

122-
.. note::
123-
124-
In order to use the annotation loader, you should have installed the
125-
``doctrine/annotations`` and ``doctrine/cache`` packages from `Packagist`_.
122+
.. include:: /_includes/_rewrite_rule_tip.rst.inc
126123

127124
Using Multiple Loaders
128125
----------------------

translation.rst

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ of text (called a *message*), use the
107107
for 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

186185
Sometimes, 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

197194
However, 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

334358
Translation Resource/File Names and Locations
@@ -513,3 +537,4 @@ Learn more
513537
.. _`ISO 639-1`: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
514538
.. _`Translatable Extension`: http://atlantic18.github.io/DoctrineExtensions/doc/translatable.html
515539
.. _`Translatable Behavior`: https://github.com/KnpLabs/DoctrineBehaviors
540+
.. _`TranslationBundle`: https://github.com/php-translation/symfony-bundle

0 commit comments

Comments
 (0)