Skip to content

Commit d926175

Browse files
committed
feature #28952 [Translation] allow using the ICU message format using domains with the "+intl-icu" suffix (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Translation] allow using the ICU message format using domains with the "+intl-icu" suffix | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | no | New feature? | yes | BC breaks? | no (unless merged after 4.2) | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR replaces the `FallbackFormatter` logic by explicit opt-in. This allows triggering accurate exceptions when one wants to use the ICU message format but the extension (or the polyfill) is missing. The way to opt-in is to put messages in a domain with the `+intl-icu` suffix *at loading/declaration time*. E.g. translations in `messages+intl-icu.en.yaml` will be read as part of the `messages` domain , but will be parsed by intl's `MessageFormatter` instead of the default Symfony one. To make it seamless to adopt the ICU format, `%`s are trimmed from parameter keys (idea borrowed from https://github.com/webfactory/WebfactoryIcuTranslationBundle) This is for 4.2 as it changes a feature that is not released yet. ping @Nyholm - we drafted this together. Commits ------- d95cc4d4c6 [Translation] allow using the ICU message format using domains with the "+intl-icu" suffix
2 parents e04862d + c5e198e commit d926175

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
699699
->defaultValue(array('en'))
700700
->end()
701701
->booleanNode('logging')->defaultValue(false)->end()
702-
->scalarNode('formatter')->defaultValue(class_exists(\MessageFormatter::class) ? 'translator.formatter.default' : 'translator.formatter.symfony')->end()
702+
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
703703
->scalarNode('default_path')
704704
->info('The default path used to load translations')
705705
->defaultValue('%kernel.project_dir%/translations')

Resources/config/translation.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@
2929
<tag name="monolog.logger" channel="translation" />
3030
</service>
3131

32-
<service id="translator.formatter.symfony" class="Symfony\Component\Translation\Formatter\MessageFormatter">
32+
<service id="translator.formatter.default" class="Symfony\Component\Translation\Formatter\MessageFormatter">
3333
<argument type="service" id="identity_translator" />
3434
</service>
35-
<service id="translator.formatter.intl" class="Symfony\Component\Translation\Formatter\IntlMessageFormatter" public="false" />
36-
<service id="translator.formatter.fallback" class="Symfony\Component\Translation\Formatter\FallbackFormatter" public="false">
37-
<argument type="service" id="translator.formatter.intl" />
38-
<argument type="service" id="translator.formatter.symfony" />
39-
</service>
40-
<service id="translator.formatter.default" alias="translator.formatter.fallback" />
4135

4236
<service id="translation.loader.php" class="Symfony\Component\Translation\Loader\PhpFileLoader">
4337
<tag name="translation.loader" alias="php" />

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected static function getBundleDefaultConfig()
189189
'enabled' => !class_exists(FullStack::class),
190190
'fallbacks' => array('en'),
191191
'logging' => false,
192-
'formatter' => \class_exists('MessageFormatter') ? 'translator.formatter.default' : 'translator.formatter.symfony',
192+
'formatter' => 'translator.formatter.default',
193193
'paths' => array(),
194194
'default_path' => '%kernel.project_dir%/translations',
195195
),

0 commit comments

Comments
 (0)