I have list of months names in my translation config file
messages.en.yml:
basic:
months:
-
- January
- February
- March
- April
- May
- June
- July
- August
- September
- October
- November
- December
The translation works when I do this:
$this->translator->trans('basic.months.'.$month);
But the problem here is that php bin/console debug:translation en
gives error that translation basic.months
is missing.
How can I fix the issue without changing the config file ?
I can try this but
$this->translator->trans('basic.months', ['%count%' => $month]);
This code doesn’t work and doesn’t translate the message.
Thanks.
2
Answers
So the problem was resolved by just doing this:
Now no debug errors are recorded and translations work as expected
The
bin/console debug:translation
scan all source files for static strings that contain message ids from yourmessages.en.yml
file.Your message id
'basic.months.'.$month
is dynamic and that’s whydebug:translation
could not detect it. Therefore it’s hardly possible to fix error without changing the config file.I suggest using icu message format:
https://symfony.com/doc/current/translation/message_format.html#selecting-different-messages-based-on-a-condition