Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite7fcd9a

Browse files
bug#45171 [Translation] Allow usage of Provider domains if possible (welcoMattic)
This PR was merged into the 5.4 branch.Discussion----------[Translation] Allow usage of Provider domains if possible| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets || License | MIT| Doc PR |This PR adds possibility for `translation:push` command to use the configured domains value for a provider, if there is no `--domains` option provided.Before that, the command tries to get the domains from the `MessageCatalog` of all local translations (including `validators` and `security` even if the user doesn't override these files).Now, we can configure `domains` in `translation.yaml`:```yamlframework: default_locale: en translator: default_path: '%kernel.project_dir%/translations' fallbacks: - en providers: lokalise: dsn: '%env(LOKALISE_DSN)%' locales: ['de', 'en', 'es', 'fr', 'it', 'pl'] domains: ['messages']```And `bin/console translation:push lokalise` will take `['messages']` as domains value, instead of `['messages', 'validators', 'security']`.Commits-------b752653 Allow usage of Provider domains if possible
2 parents23338d0 +b752653 commite7fcd9a

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

‎src/Symfony/Component/Translation/Command/TranslationPushCommand.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
useSymfony\Component\Console\Input\InputOption;
2121
useSymfony\Component\Console\Output\OutputInterface;
2222
useSymfony\Component\Console\Style\SymfonyStyle;
23+
useSymfony\Component\Translation\Provider\FilteringProvider;
2324
useSymfony\Component\Translation\Provider\TranslationProviderCollection;
2425
useSymfony\Component\Translation\Reader\TranslationReaderInterface;
2526
useSymfony\Component\Translation\TranslatorBag;
@@ -133,7 +134,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
133134
$localTranslations =$this->readLocalTranslations($locales,$domains,$this->transPaths);
134135

135136
if (!$domains) {
136-
$domains =$this->getDomainsFromTranslatorBag($localTranslations);
137+
if ($providerinstanceof FilteringProvider) {
138+
$domains =$provider->getDomains();
139+
}
140+
141+
if (!$domains) {
142+
$domains =$this->getDomainsFromTranslatorBag($localTranslations);
143+
}
137144
}
138145

139146
if (!$deleteMissing &&$force) {

‎src/Symfony/Component/Translation/Tests/Command/TranslationPushCommandTest.php‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
useSymfony\Component\Translation\Command\TranslationPushCommand;
1818
useSymfony\Component\Translation\Loader\ArrayLoader;
1919
useSymfony\Component\Translation\Loader\XliffFileLoader;
20+
useSymfony\Component\Translation\Provider\FilteringProvider;
2021
useSymfony\Component\Translation\Provider\ProviderInterface;
22+
useSymfony\Component\Translation\Provider\TranslationProviderCollection;
2123
useSymfony\Component\Translation\Reader\TranslationReader;
2224
useSymfony\Component\Translation\TranslatorBag;
2325

@@ -259,6 +261,68 @@ public function testPushForceAndDeleteMissingMessages()
259261
$this->assertStringContainsString('[OK] All local translations has been sent to "null" (for "en, fr" locale(s), and "messages" domain(s)).',trim($tester->getDisplay()));
260262
}
261263

264+
publicfunctiontestPushWithProviderDomains()
265+
{
266+
$arrayLoader =newArrayLoader();
267+
$xliffLoader =newXliffFileLoader();
268+
$locales = ['en','fr'];
269+
$domains = ['messages'];
270+
271+
// Simulate existing messages on Provider
272+
$providerReadTranslatorBag =newTranslatorBag();
273+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' =>'NOTE'],'en'));
274+
$providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' =>'NOTE'],'fr'));
275+
276+
$provider =$this->createMock(FilteringProvider::class);
277+
$provider->expects($this->once())
278+
->method('read')
279+
->with($domains,$locales)
280+
->willReturn($providerReadTranslatorBag);
281+
$provider->expects($this->once())
282+
->method('getDomains')
283+
->willReturn(['messages']);
284+
285+
$filenameEn =$this->createFile([
286+
'note' =>'NOTE',
287+
'new.foo' =>'newFoo',
288+
]);
289+
$filenameFr =$this->createFile([
290+
'note' =>'NOTE',
291+
'new.foo' =>'nouveauFoo',
292+
],'fr');
293+
$localTranslatorBag =newTranslatorBag();
294+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameEn,'en'));
295+
$localTranslatorBag->addCatalogue($xliffLoader->load($filenameFr,'fr'));
296+
297+
$provider->expects($this->once())
298+
->method('write')
299+
->with($localTranslatorBag->diff($providerReadTranslatorBag));
300+
301+
$provider->expects($this->once())
302+
->method('__toString')
303+
->willReturn('null://default');
304+
305+
$reader =newTranslationReader();
306+
$reader->addLoader('xlf',newXliffFileLoader());
307+
308+
$command =newTranslationPushCommand(
309+
newTranslationProviderCollection([
310+
'loco' =>$provider,
311+
]),
312+
$reader,
313+
[$this->translationAppDir.'/translations'],
314+
$locales
315+
);
316+
317+
$application =newApplication();
318+
$application->add($command);
319+
$tester =newCommandTester($application->find('translation:push'));
320+
321+
$tester->execute(['--locales' => ['en','fr']]);
322+
323+
$this->assertStringContainsString('[OK] New local translations has been sent to "null" (for "en, fr" locale(s), and "messages" domain(s)).',trim($tester->getDisplay()));
324+
}
325+
262326
/**
263327
* @dataProvider provideCompletionSuggestions
264328
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp