From 5cabc75c4ddd735dd394ca7b09147e01ef2bbb43 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 13 Feb 2020 13:29:10 +0100 Subject: [PATCH] [Translation] Document the enabled_locales option --- performance.rst | 9 +++++ reference/configuration/framework.rst | 58 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/performance.rst b/performance.rst index 51d2d83f230..150af0f5b4e 100644 --- a/performance.rst +++ b/performance.rst @@ -13,6 +13,7 @@ Symfony Application Checklist #. :ref:`Install APCu Polyfill if your server uses APC ` #. :ref:`Dump the service container into a single file ` +#. :ref:`Restrict the number of locales enabled in the application ` Production Server Checklist --------------------------- @@ -74,6 +75,14 @@ container into a single file, which could improve performance when using // ... $container->setParameter('container.dumper.inline_factories', true); +.. _performance-enabled-locales: + +Restrict the Number of Locales Enabled in the Application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use the :ref:`framework.translator.enabled_locales ` +option to only generate the translation files actually used in your application. + .. _performance-use-opcache: Use the OPcache Byte Code Cache diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 11672d517d6..1c6dad3681a 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -227,6 +227,7 @@ Configuration * `cache_dir`_ * :ref:`default_path ` * :ref:`enabled ` + * :ref:`enabled_locales ` * `fallbacks`_ * `formatter`_ * `logging`_ @@ -1989,6 +1990,63 @@ enabled Whether or not to enable the ``translator`` service in the service container. +.. _reference-translator-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: + translation: + enabled_locales: ['en', 'es'] + + .. code-block:: xml + + + + + + + + en + es + + + + + .. code-block:: php + + // config/packages/translation.php + $container->loadFromExtension('framework', [ + 'translation' => [ + 'enabled_locales' => ['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. + .. _fallback: fallbacks