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

Skip to content

[Translation] Document the enabled_locales option #13124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Symfony Application Checklist

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

Production Server Checklist
---------------------------
Expand Down Expand Up @@ -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 <reference-translator-enabled-locales>`
option to only generate the translation files actually used in your application.

.. _performance-use-opcache:

Use the OPcache Byte Code Cache
Expand Down
58 changes: 58 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Configuration
* `cache_dir`_
* :ref:`default_path <reference-translator-default_path>`
* :ref:`enabled <reference-translator-enabled>`
* :ref:`enabled_locales <reference-translator-enabled-locales>`
* `fallbacks`_
* `formatter`_
* `logging`_
Expand Down Expand Up @@ -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

<!-- config/packages/translation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:translation>
<enabled-locale>en</enabled-locale>
<enabled-locale>es</enabled-locale>
</framework:translation>
</framework:config>
</container>

.. 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
Expand Down