We are using Pimcore v5.4
Our use case is that we have a ~500 documents that will need to be translated in 15+ languages. The content is stored in editable input fields and Wysiwyg fields. Instead of creating duplicate documents, and ending up with 15x500 languages, I would like the translations to be based on user locale using the same document. The Pimcore suggestion to replicate a document per locale will result in redundancies i’d like to avoid.
So… I tried to follow Symfony translation tutorial to get the Translator sample working, but not very successful. I am open to suggestions on a better way to do this, but my thought are as follows:
- Get JSON view of the document to extract all the keys (or use the Translator Bundle if possible)
- Get the missing keys to a translation thirdparty, our content is heavy legal/compliance type content, and we would like to setup an export/import process as opposed to directly editing/entering translations inside pimcore documents
- Use Symfony Translator component to render the appropriate translation at run-time based on locale for the same document
#/app/config/config.yml framework: translator: paths: - "%kernel.root_dir%/Resources/translations" fallback: [en] #---- #/app/Resources/translations/messages.es.yml (also have messages.es.xlf, just in case) 'Symfony is great': 'Symfony es mui bueno'
$request->setLocale('es'); $this->view->translated = $this->get('translator')->trans('Symfony is great'); $this->view->locale = $request->getLocale();
View - [Cache cleeared]:
'es' yet the
$translated value is still in English.
Here is the sample script i tried to run after configuration, it just emits “Done”, no errors…
> php bin/console pimcore:run-script /tmp/translation.php > Running script /tmp/translation.php // -- script /tmp/translation.php -- $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'); > <blank line> > Done