Skip to content

Commit 0b2f05a

Browse files
committed
minor #15942 [HttpKernel] Add basic support for language negotiation (hiddewie)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [HttpKernel] Add basic support for language negotiation From symfony/symfony#43108 Fixes #15891 I moved the documentation for the deprecated option with a deprecation notice at the old place. The new options `set_content_language_from_locale` and `set_locale_from_accept_language` have been documented. Commits ------- c41db2f [HttpKernel] Add basic support for language negotiation
2 parents b9c5ac1 + c41db2f commit 0b2f05a

File tree

2 files changed

+86
-47
lines changed

2 files changed

+86
-47
lines changed

performance.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ features, such as the APCu Cache adapter.
4343
Restrict the Number of Locales Enabled in the Application
4444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4545

46-
Use the :ref:`framework.translator.enabled_locales <reference-translator-enabled-locales>`
46+
Use the :ref:`framework.enabled_locales <reference-enabled-locales>`
4747
option to only generate the translation files actually used in your application.
4848

4949
.. _performance-service-container-single-file:
@@ -115,7 +115,7 @@ Symfony generates a file with the list of classes to preload in the
115115
116116
; php.ini
117117
opcache.preload=/path/to/project/config/preload.php
118-
118+
119119
; required for opcache.preload:
120120
opcache.preload_user=www-data
121121

reference/configuration/framework.rst

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,87 @@ method.
282282
You can read more information about the default locale in
283283
:ref:`translation-default-locale`.
284284

285+
.. _reference-enabled-locales:
286+
287+
enabled_locales
288+
...............
289+
290+
**type**: ``array`` **default**: ``[]`` (empty array = enable all locales)
291+
292+
.. versionadded:: 5.1
293+
294+
The ``enabled_locales`` option was introduced in Symfony 5.1.
295+
296+
Symfony applications generate by default the translation files for validation
297+
and security messages in all locales. If your application only uses some
298+
locales, use this option to restrict the files generated by Symfony and improve
299+
performance a bit:
300+
301+
.. configuration-block::
302+
303+
.. code-block:: yaml
304+
305+
# config/packages/translation.yaml
306+
framework:
307+
enabled_locales: ['en', 'es']
308+
309+
.. code-block:: xml
310+
311+
<!-- config/packages/translation.xml -->
312+
<?xml version="1.0" encoding="UTF-8" ?>
313+
<container xmlns="http://symfony.com/schema/dic/services"
314+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
315+
xmlns:framework="http://symfony.com/schema/dic/symfony"
316+
xsi:schemaLocation="http://symfony.com/schema/dic/services
317+
https://symfony.com/schema/dic/services/services-1.0.xsd
318+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
319+
320+
<framework:config>
321+
<enabled-locale>en</enabled-locale>
322+
<enabled-locale>es</enabled-locale>
323+
</framework:config>
324+
</container>
325+
326+
.. code-block:: php
327+
328+
// config/packages/translation.php
329+
use Symfony\Config\FrameworkConfig;
330+
331+
return static function (FrameworkConfig $framework) {
332+
$framework->enabledLocales(['en', 'es']);
333+
};
334+
335+
If some user makes requests with a locale not included in this option, the
336+
application won't display any error because Symfony will display contents using
337+
the fallback locale.
338+
339+
set_content_language_from_locale
340+
...............
341+
342+
**type**: ``boolean`` **default**: ``false``
343+
344+
.. versionadded:: 5.4
345+
346+
The ``set_content_language_from_locale`` option was introduced in Symfony 5.4.
347+
348+
If this option is set to ``true``, the response will have a ``Content-Language``
349+
HTTP header set with the ``Request`` locale.
350+
351+
set_locale_from_accept_language
352+
...............
353+
354+
**type**: ``boolean`` **default**: ``false``
355+
356+
.. versionadded:: 5.4
357+
358+
The ``set_locale_from_accept_language`` option was introduced in Symfony 5.4.
359+
360+
The ``Request`` locale will automatically be set to the value of the
361+
``Accept-Language`` HTTP header.
362+
363+
When the ``_locale`` request attribute is passed, the ``Accept-Language`` header
364+
is ignored.
365+
285366
disallow_search_engine_index
286367
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287368

@@ -2142,52 +2223,10 @@ enabled_locales
21422223

21432224
The ``enabled_locales`` option was introduced in Symfony 5.1.
21442225

2145-
Symfony applications generate by default the translation files for validation
2146-
and security messages in all locales. If your application only uses some
2147-
locales, use this option to restrict the files generated by Symfony and improve
2148-
performance a bit:
2149-
2150-
.. configuration-block::
2151-
2152-
.. code-block:: yaml
2153-
2154-
# config/packages/translation.yaml
2155-
framework:
2156-
translator:
2157-
enabled_locales: ['en', 'es']
2158-
2159-
.. code-block:: xml
2226+
.. deprecated:: 5.4
21602227

2161-
<!-- config/packages/translation.xml -->
2162-
<?xml version="1.0" encoding="UTF-8" ?>
2163-
<container xmlns="http://symfony.com/schema/dic/services"
2164-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2165-
xmlns:framework="http://symfony.com/schema/dic/symfony"
2166-
xsi:schemaLocation="http://symfony.com/schema/dic/services
2167-
https://symfony.com/schema/dic/services/services-1.0.xsd
2168-
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
2169-
2170-
<framework:config>
2171-
<framework:translator>
2172-
<enabled-locale>en</enabled-locale>
2173-
<enabled-locale>es</enabled-locale>
2174-
</framework:translator>
2175-
</framework:config>
2176-
</container>
2177-
2178-
.. code-block:: php
2179-
2180-
// config/packages/translation.php
2181-
use Symfony\Config\FrameworkConfig;
2182-
2183-
return static function (FrameworkConfig $framework) {
2184-
$framework->translator()
2185-
->enabledLocales(['en', 'es']);
2186-
};
2187-
2188-
If some user makes requests with a locale not included in this option, the
2189-
application won't display any error because Symfony will display contents using
2190-
the fallback locale.
2228+
Using `framework.translator.enabled_locales` has been deprecated in favour of
2229+
:ref:`framework.enabled_locales <reference-enabled-locales>` since Symfony 5.4.
21912230

21922231
.. _fallback:
21932232

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy