So I have the following demo for the Symfony 4 framework which works fine and translates everything as expected:
$translator = new \Symfony\Component\Translation\Translator('en_GB');
$translator->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());
$translator->addResource('array', [
'sample' => 'The English translation goes here...',
], 'en_GB');
echo $translator->trans('sample');
However I can't seem to get the following demo to work:
echo $this->get('translator')->trans('sample');
The following config is in place:
/config/services.yaml:
parameters:
locale: en
/config/packages/translation.yaml:
framework:
default_locale: en
translator:
fallbacks: ['en']
paths:
- '%kernel.project_dir%/translations'
/translations/messages.en.yaml:
sample: The English translation goes here...
Dumping out the following:
$request->getLocale();
$request->getDefaultLocale();
Produces the following strings:
'en_GB'
'en'
And I've tried renaming the translation file to 'messages.en.yaml', 'messages.en_GB.yaml', 'messages.en_US.yaml' and then run "php bin/console cache:clear" afterwards to ensure the cache was fully cleared.
I can't seem to get the translations to display from the yaml file. There are no errors displaying but only the translation keys are visible.
Can anyone see if I'm making an obvious mistake somewhere or overlooking something?
PHP 7.2.0-2+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Dec 7 2017 20:14:31) ( NTS ) Linux Mint 18, Apache2 Ubuntu.
messages.en.yaml
? – DrKey Jan 15 '18 at 19:35php bin/console debug:container --parameter=kernel.project_dir
? – DrKey Jan 15 '18 at 20:34