@@ -227,6 +227,7 @@ Configuration
227
227
* `cache_dir `_
228
228
* :ref: `default_path <reference-translator-default_path >`
229
229
* :ref: `enabled <reference-translator-enabled >`
230
+ * :ref: `enabled_locales <reference-translator-enabled-locales >`
230
231
* `fallbacks `_
231
232
* `formatter `_
232
233
* `logging `_
@@ -1989,6 +1990,63 @@ enabled
1989
1990
1990
1991
Whether or not to enable the ``translator `` service in the service container.
1991
1992
1993
+ .. _reference-translator-enabled-locales :
1994
+
1995
+ enabled_locales
1996
+ ...............
1997
+
1998
+ **type **: ``array `` **default **: ``[] `` (empty array = enable all locales)
1999
+
2000
+ .. versionadded :: 5.1
2001
+
2002
+ The ``enabled_locales `` option was introduced in Symfony 5.1.
2003
+
2004
+ Symfony applications generate by default the translation files for validation
2005
+ and security messages in all locales. If your application only uses some
2006
+ locales, use this option to restrict the files generated by Symfony and improve
2007
+ performance a bit:
2008
+
2009
+ .. configuration-block ::
2010
+
2011
+ .. code-block :: yaml
2012
+
2013
+ # config/packages/translation.yaml
2014
+ framework :
2015
+ translation :
2016
+ enabled_locales : ['en', 'es']
2017
+
2018
+ .. code-block :: xml
2019
+
2020
+ <!-- config/packages/translation.xml -->
2021
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2022
+ <container xmlns =" http://symfony.com/schema/dic/services"
2023
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2024
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
2025
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
2026
+ https://symfony.com/schema/dic/services/services-1.0.xsd
2027
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
2028
+
2029
+ <framework : config >
2030
+ <framework : translation >
2031
+ <enabled-locale >en</enabled-locale >
2032
+ <enabled-locale >es</enabled-locale >
2033
+ </framework : translation >
2034
+ </framework : config >
2035
+ </container >
2036
+
2037
+ .. code-block :: php
2038
+
2039
+ // config/packages/translation.php
2040
+ $container->loadFromExtension('framework', [
2041
+ 'translation' => [
2042
+ 'enabled_locales' => ['en', 'es'],
2043
+ ],
2044
+ ]);
2045
+
2046
+ If some user makes requests with a locale not included in this option, the
2047
+ application won't display any error because Symfony will display contents using
2048
+ the fallback locale.
2049
+
1992
2050
.. _fallback :
1993
2051
1994
2052
fallbacks
0 commit comments