Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e972531

Browse files
committed
[Translation] Document the enabled_locales option
1 parent 939ae85 commit e972531

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

performance.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Symfony Application Checklist
1313

1414
#. :ref:`Install APCu Polyfill if your server uses APC <performance-install-apcu-polyfill>`
1515
#. :ref:`Dump the service container into a single file <performance-service-container-single-file>`
16+
#. :ref:`Restrict the number of locales enabled in the application <performance-enabled-locales>`
1617

1718
Production Server Checklist
1819
---------------------------
@@ -74,6 +75,14 @@ container into a single file, which could improve performance when using
7475
// ...
7576
$container->setParameter('container.dumper.inline_factories', true);
7677
78+
.. _performance-enabled-locales:
79+
80+
Restrict the number of locales enabled in the application
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
Use the :ref:`framework.translator.enabled_locales <reference-translator-enabled-locales>`
84+
option to only generate the translation files actually used in your application.
85+
7786
.. _performance-use-opcache:
7887

7988
Use the OPcache Byte Code Cache

reference/configuration/framework.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Configuration
227227
* `cache_dir`_
228228
* :ref:`default_path <reference-translator-default_path>`
229229
* :ref:`enabled <reference-translator-enabled>`
230+
* :ref:`enabled_locales <reference-translator-enabled-locales>`_
230231
* `fallbacks`_
231232
* `formatter`_
232233
* `logging`_
@@ -1989,6 +1990,64 @@ enabled
19891990

19901991
Whether or not to enable the ``translator`` service in the service container.
19911992

1993+
.. _reference-translator-enabled-locales:
1994+
1995+
enabled_locales
1996+
...............
1997+
1998+
**type**: ``array`` **default**: ``[]`` (empty array)
1999+
2000+
.. versionadded:: 5.1
2001+
2002+
The ``enabled_locales`` option was introduced in Symfony 5.1.
2003+
2004+
Symfony applications enable by default all locales. This means that Symfony
2005+
generates and tracks tens of translation files (for the validation and security
2006+
messages). If your application only uses some locales, use this option to
2007+
restrict the files generated by Symfony and improve 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+
2032+
?????
2033+
2034+
</framework:translation>
2035+
</framework:config>
2036+
</container>
2037+
2038+
.. code-block:: php
2039+
2040+
// config/packages/translation.php
2041+
$container->loadFromExtension('framework', [
2042+
'translation' => [
2043+
'enabled_locales' => ['en', 'es'],
2044+
],
2045+
]);
2046+
2047+
If some user makes requests with a locale not included in this option, the
2048+
application won't display any error because Symfony will display contents using
2049+
the fallback locale.
2050+
19922051
.. _fallback:
19932052

19942053
fallbacks

0 commit comments

Comments
 (0)