Skip to content

Navigation Menu

Sign in
Appearance settings

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 7ca354b

Browse filesBrowse files
committed
[Translation] Allow global parameters
1 parent 04551ad commit 7ca354b
Copy full SHA for 7ca354b
Expand file treeCollapse file tree

20 files changed

+312
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
966966
->fixXmlConfig('fallback')
967967
->fixXmlConfig('path')
968968
->fixXmlConfig('provider')
969+
->fixXmlConfig('global')
969970
->children()
970971
->arrayNode('fallbacks')
971972
->info('Defaults to the value of "default_locale".')
@@ -1020,6 +1021,33 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
10201021
->end()
10211022
->defaultValue([])
10221023
->end()
1024+
->arrayNode('globals')
1025+
->info('Global parameters.')
1026+
->example(['app_version' => 3.14])
1027+
->normalizeKeys(false)
1028+
->useAttributeAsKey('name')
1029+
->arrayPrototype()
1030+
->fixXmlConfig('parameter')
1031+
->children()
1032+
->variableNode('value')->end()
1033+
->stringNode('message')->end()
1034+
->arrayNode('parameters')
1035+
->normalizeKeys(false)
1036+
->useAttributeAsKey('name')
1037+
->scalarPrototype()->end()
1038+
->end()
1039+
->stringNode('domain')->end()
1040+
->end()
1041+
->beforeNormalization()
1042+
->ifTrue(static fn ($v) => !\is_array($v))
1043+
->then(static fn ($v) => ['value' => $v])
1044+
->end()
1045+
->validate()
1046+
->ifTrue(static fn ($v) => !(isset($v['value']) xor isset($v['message'])))
1047+
->thenInvalid('The "globals" parameter should be either a string or an array with a "value" or a "message" key')
1048+
->end()
1049+
->end()
1050+
->end()
10231051
->end()
10241052
->end()
10251053
->end()

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,14 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
16111611
$translator->replaceArgument(4, $options);
16121612
}
16131613

1614+
foreach ($config['globals'] as $name => $global) {
1615+
if (isset($global['value'])) {
1616+
$translator->addMethodCall('addGlobalParameter', [$name, $global['value']]);
1617+
} else {
1618+
$translator->addMethodCall('addGlobalTranslatableParameter', [$name, $global['message'], $global['parameters'] ?? [], $global['domain'] ?? null]);
1619+
}
1620+
}
1621+
16141622
if ($config['pseudo_localization']['enabled']) {
16151623
$options = $config['pseudo_localization'];
16161624
unset($options['enabled']);

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
<xsd:element name="path" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
257257
<xsd:element name="pseudo-localization" type="pseudo_localization" minOccurs="0" maxOccurs="1" />
258258
<xsd:element name="provider" type="translation_provider" minOccurs="0" maxOccurs="unbounded" />
259+
<xsd:element name="global" type="translation_global" minOccurs="0" maxOccurs="unbounded" />
259260
</xsd:sequence>
260261
<xsd:attribute name="enabled" type="xsd:boolean" />
261262
<xsd:attribute name="fallback" type="xsd:string" />
@@ -285,6 +286,24 @@
285286
<xsd:attribute name="dsn" type="xsd:string" />
286287
</xsd:complexType>
287288

289+
<xsd:complexType name="translation_global" mixed="true">
290+
<xsd:sequence>
291+
<xsd:element name="parameter" type="translation_global_parameter" minOccurs="0" maxOccurs="unbounded" />
292+
</xsd:sequence>
293+
<xsd:attribute name="name" type="xsd:string" use="required" />
294+
<xsd:attribute name="value" type="xsd:string" />
295+
<xsd:attribute name="message" type="xsd:string" />
296+
<xsd:attribute name="domain" type="xsd:string" />
297+
</xsd:complexType>
298+
299+
<xsd:complexType name="translation_global_parameter" mixed="true">
300+
<xsd:simpleContent>
301+
<xsd:extension base="xsd:string">
302+
<xsd:attribute name="name" type="xsd:string" use="required" />
303+
</xsd:extension>
304+
</xsd:simpleContent>
305+
</xsd:complexType>
306+
288307
<xsd:complexType name="validation">
289308
<xsd:choice minOccurs="0" maxOccurs="unbounded">
290309
<xsd:element name="static-method" type="xsd:string" />

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ protected static function getBundleDefaultConfig()
769769
'localizable_html_attributes' => [],
770770
],
771771
'providers' => [],
772+
'globals' => [],
772773
],
773774
'validation' => [
774775
'enabled' => !class_exists(FullStack::class),
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'annotations' => false,
5+
'http_method_override' => false,
6+
'handle_all_throwables' => true,
7+
'php_errors' => ['log' => true],
8+
'translator' => [
9+
'globals' => [
10+
'%%app_name%%' => 'My application',
11+
'{app_version}' => '1.2.3',
12+
'{url}' => ['message' => 'url', 'parameters' => ['scheme' => 'https://'], 'domain' => 'global'],
13+
],
14+
],
15+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'annotations' => false,
5+
'http_method_override' => false,
6+
'handle_all_throwables' => true,
7+
'php_errors' => ['log' => true],
8+
'translator' => ['globals' => []],
9+
]);
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t" http-method-override="false" handle-all-throwables="true">
10+
<framework:annotations enabled="false" />
11+
<framework:php-errors log="true" />
12+
<framework:translator enabled="true">
13+
<framework:global name="%%app_name%%">My application</framework:global>
14+
<framework:global name="{app_version}" value="1.2.3" />
15+
<framework:global name="{url}" message="url" domain="global">
16+
<framework:parameter name="scheme">https://</framework:parameter>
17+
</framework:global>
18+
</framework:translator>
19+
</framework:config>
20+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t" http-method-override="false" handle-all-throwables="true">
10+
<framework:annotations enabled="false" />
11+
<framework:php-errors log="true" />
12+
<framework:translator enabled="true" />
13+
</framework:config>
14+
</container>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
translator:
8+
globals:
9+
'%%app_name%%': 'My application'
10+
'{app_version}': '1.2.3'
11+
'{url}': { message: 'url', parameters: { scheme: 'https://' }, domain: 'global' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
translator:
8+
globals: []

0 commit comments

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