Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce9207e

Browse filesBrowse files
committed
minor #20862 [Translation] document global variables feature configuration (94noni)
This PR was merged into the 7.3 branch. Discussion ---------- [Translation] document global variables feature configuration document symfony/symfony#53425 close #20754 > [!NOTE] > I am very unsure of the php config via object config (not inline php array) > all example have been taken from the merged PR Commits ------- 97de6eb [Translator] document global variables feature configuration
2 parents f70f43d + 97de6eb commit ce9207e
Copy full SHA for ce9207e

File tree

1 file changed

+61
-0
lines changed
Filter options

1 file changed

+61
-0
lines changed

‎translation.rst

Copy file name to clipboardExpand all lines: translation.rst
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,67 @@ service argument with the :class:`Symfony\\Component\\Translation\\LocaleSwitche
11601160
class to inject the locale switcher service. Otherwise, configure your services
11611161
manually and inject the ``translation.locale_switcher`` service.
11621162

1163+
.. _translation-global-variables:
1164+
1165+
Global Variables
1166+
~~~~~~~~~~~~~~~~
1167+
1168+
The translator allows you to automatically configure global variables that will be available
1169+
for the translation process. These global variables are defined in the ``translations.globals``
1170+
option inside the main configuration file:
1171+
1172+
.. configuration-block::
1173+
1174+
.. code-block:: yaml
1175+
1176+
# config/packages/translator.yaml
1177+
translator:
1178+
# ...
1179+
globals:
1180+
'%%app_name%%': 'My application'
1181+
'{app_version}': '1.2.3'
1182+
'{url}': { message: 'url', parameters: { scheme: 'https://' }, domain: 'global' }
1183+
1184+
.. code-block:: xml
1185+
1186+
<!-- config/packages/translation.xml -->
1187+
<?xml version="1.0" encoding="UTF-8" ?>
1188+
<container xmlns="http://symfony.com/schema/dic/services"
1189+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1190+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1191+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1192+
https://symfony.com/schema/dic/services/services-1.0.xsd
1193+
http://symfony.com/schema/dic/symfony
1194+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1195+
1196+
<framework:config>
1197+
<framework:translator>
1198+
<!-- ... -->
1199+
<framework:global name="%%app_name%%">My application</framework:global>
1200+
<framework:global name="{app_version}" value="1.2.3" />
1201+
<framework:global name="{url}" message="url" domain="global">
1202+
<framework:parameter name="scheme">https://</framework:parameter>
1203+
</framework:global>
1204+
</framework:translator>
1205+
</framework:config>
1206+
</container>
1207+
1208+
.. code-block:: php
1209+
1210+
// config/packages/translator.php
1211+
use Symfony\Config\TwigConfig;
1212+
1213+
return static function (TwigConfig $translator): void {
1214+
// ...
1215+
$translator->globals('%%app_name%%')->value('My application');
1216+
$translator->globals('{app_version}')->value('1.2.3');
1217+
$translator->globals('{url}')->value(['message' => 'url', 'parameters' => ['scheme' => 'https://']);
1218+
};
1219+
1220+
.. versionadded:: 7.3
1221+
1222+
The ``translator:globals`` option was introduced in Symfony 7.3.
1223+
11631224
.. _translation-debug:
11641225

11651226
How to Find Missing or Unused Translation Messages

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.