8000 feature #13124 [Translation] Document the enabled_locales option (jav… · symfony/symfony-docs@a6cff54 · GitHub
[go: up one dir, main page]

Skip to content

Commit a6cff54

Browse files
committed
feature #13124 [Translation] Document the enabled_locales option (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [Translation] Document the enabled_locales option Fixes #13038. DON'T MERGE ... because I'm missing the XML config example. Can someone please help me with that? Thanks! Commits ------- 5cabc75 [Translation] Document the enabled_locales option
2 parents d0b800f + 5cabc75 commit a6cff54

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-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

< 10000 /code>
7988
Use the OPcache Byte Code Cache

reference/configuration/framework.rst

Lines changed: 58 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,63 @@ 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 = 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+
19922050
.. _fallback:
19932051

19942052
fallbacks

0 commit comments

Comments
 (0)
0