Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Add basic support for language negotiation #15942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ features, such as the APCu Cache adapter.
Restrict the Number of Locales Enabled in the Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. _performance-service-container-single-file:
Expand Down Expand Up @@ -115,7 +115,7 @@ Symfony generates a file with the list of classes to preload in the

; php.ini
opcache.preload=/path/to/project/config/preload.php

; required for opcache.preload:
opcache.preload_user=www-data

Expand Down
129 changes: 84 additions & 45 deletions 129 reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,87 @@ method.
You can read more information about the default locale in
:ref:`translation-default-locale`.

.. _reference-enabled-locales:

enabled_locales
...............

**type**: ``array`` **default**: ``[]`` (empty array = enable all locales)

.. versionadded:: 5.1

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

Symfony applications generate by default the translation files for validation
and security messages in all locales. If your application only uses some
locales, use this option to restrict the files generated by Symfony and improve
performance a bit:

.. configuration-block::

.. code-block:: yaml

# config/packages/translation.yaml
framework:
enabled_locales: ['en', 'es']

.. code-block:: xml

<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<enabled-locale>en</enabled-locale>
<enabled-locale>es</enabled-locale>
</framework:config>
</container>

.. code-block:: php

// config/packages/translation.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->enabledLocales(['en', 'es']);
};

If some user makes requests with a locale not included in this option, the
application won't display any error because Symfony will display contents using
the fallback locale.

set_content_language_from_locale
...............

**type**: ``boolean`` **default**: ``false``

.. versionadded:: 5.4

The ``set_content_language_from_locale`` option was introduced in Symfony 5.4.

If this option is set to ``true``, the response will have a ``Content-Language``
HTTP header set with the ``Request`` locale.

set_locale_from_accept_language
...............

**type**: ``boolean`` **default**: ``false``

.. versionadded:: 5.4

The ``set_locale_from_accept_language`` option was introduced in Symfony 5.4.

The ``Request`` locale will automatically be set to the value of the
``Accept-Language`` HTTP header.

When the ``_locale`` request attribute is passed, the ``Accept-Language`` header
is ignored.

disallow_search_engine_index
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -2142,52 +2223,10 @@ enabled_locales

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

Symfony applications generate by default the translation files for validation
and security messages in all locales. If your application only uses some
locales, use this option to restrict the files generated by Symfony and improve
performance a bit:

.. configuration-block::

.. code-block:: yaml

# config/packages/translation.yaml
framework:
translator:
enabled_locales: ['en', 'es']

.. code-block:: xml
.. deprecated:: 5.4

<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:translator>
<enabled-locale>en</enabled-locale>
<enabled-locale>es</enabled-locale>
</framework:translator>
</framework:config>
</container>

.. code-block:: php

// config/packages/translation.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->translator()
->enabledLocales(['en', 'es']);
};

If some user makes requests with a locale not included in this option, the
application won't display any error because Symfony will display contents using
the fallback locale.
Using `framework.translator.enabled_locales` has been deprecated in favour of
:ref:`framework.enabled_locales <reference-enabled-locales>` since Symfony 5.4.

.. _fallback:

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.