From c41db2f66e2b6b98cfb554d69a114bc3b5ad63d6 Mon Sep 17 00:00:00 2001 From: Hidde Wieringa Date: Mon, 18 Oct 2021 21:31:08 +0200 Subject: [PATCH] [HttpKernel] Add basic support for language negotiation --- performance.rst | 4 +- reference/configuration/framework.rst | 129 +++++++++++++++++--------- 2 files changed, 86 insertions(+), 47 deletions(-) diff --git a/performance.rst b/performance.rst index 620b76c01b2..e9d1b5558d6 100644 --- a/performance.rst +++ b/performance.rst @@ -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 ` +Use the :ref:`framework.enabled_locales ` option to only generate the translation files actually used in your application. .. _performance-service-container-single-file: @@ -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 diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index ddaed96d025..cebff51e16f 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -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 + + + + + + + en + es + + + + .. 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -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 - - - - - - - en - es - - - - - .. 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 ` since Symfony 5.4. .. _fallback: 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