JMSTranslationBundle icon indicating copy to clipboard operation
JMSTranslationBundle copied to clipboard

Translation skipped when using transChoice with null domain

Open guillaumesmo opened this issue 9 years ago • 3 comments

transChoice allows to set the $domain argument as null when the next argument ($locale) is set.

example:

$translation=$this->translator->transChoice('test_transchoice', 5, [], null, 'fr');

translation:extract shows an error when using DefaultPhpFileExtractor in that case because the argument is set as a PHPParser_Node_Expr_ConstFetch and not null. https://github.com/schmittjoh/JMSTranslationBundle/blob/1.1.0/Translation/Extractor/File/DefaultPhpFileExtractor.php#L107

Can only extract the translation domain from a scalar string, but got "PHPParser_Node_Scalar_String". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element

Additionally, the error is wrong as it shows the type of the first argument and not the argument at $index https://github.com/schmittjoh/JMSTranslationBundle/blob/1.1.0/Translation/Extractor/File/DefaultPhpFileExtractor.php#L113 (Should show "PHPParser_Node_Expr_ConstFetch" instead of "PHPParser_Node_Scalar_String")

I bypassed the issue by hardcoding the default domain

$translation=$this->translator->transChoice('test_transchoice', 5, [], 'messages', 'fr');

guillaumesmo avatar Jan 22 '16 10:01 guillaumesmo

I know it was a long time ago you posted this issue. Do you still experiencing this? Or is it fixed in the latest version of the bundle?

Nyholm avatar Aug 04 '16 16:08 Nyholm

I'm not anymore in the company where I experienced the issue. I don't know if it's worth digging into this

guillaumesmo avatar Aug 04 '16 18:08 guillaumesmo

I just tested this myself and I can confirm it is still an issue and that the workaround still works.

Nyholm avatar Aug 04 '16 18:08 Nyholm