Forums › Forums › OroPlatform › Overwrite translation
This topic contains 7 replies, has 2 voices, and was last updated by William Radi 5 years, 11 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- April 10, 2018 at 6:38 am #37141
Hello there!
I installed the portuguese language (pt_BR ) in my CRM, however there are some expressions (that are in portuguese) that should be changed.
Is there a way to programmatically overwrite the downloaded translation?
Thanks!
- CreatorTopic
- AuthorReplies
- April 13, 2018 at 11:00 am #37142
Is it possible to do?
April 13, 2018 at 2:31 pm #37143Hi Willam,
translations are already loaded to the database and you can edit it from UI, it will be easy
see this link https://oroinc.com/orocrm/doc/current/admin-guide/localization/translationsAnd from the code side you can load them from the yml files as usual to symfony, from the files like “messages.pt_BR.yml” placed at Resources/translation folder. Where “messages” is the translation domain. the original domain and message you can find at the UI just by searching at the translation grid.
Just don’t forget to run “app/console oro:translation:load” command after you updated it at the code to load new translation to the database.
April 17, 2018 at 7:27 pm #37144Hi Anyt! Thanks again! :)
And, sorry for the delay too..So… Using the UI, I can translate.. But from the code side, I found the exatly key that I wanted to translate and added to my messages.pt_BR.yml, but didn’t work =/
I guess I couldn’t made sth wrong because I found the key in the documentation and I could translate english things near of the portuguese text that I want to change.
Any idea? :D
Thaks so much!April 24, 2018 at 8:26 am #37145Did you run
app/console oro:translation:load
command after changing messages at the code?April 30, 2018 at 4:38 am #37146Tried it again here.. But unsuccesful…
April 30, 2018 at 5:19 am #37147Hi William,
Downloaded translations have higher priority than yml files, so the command didn’t help.
You can override them now only using data fixtures from code.For that purpose use
Oro\Bundle\TranslationBundle\Manager\TranslationManager::saveTranslation()
method withTranslation::SCOPE_UI
as the last argument.Here is an example of how this migration will look like
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657<?phpnamespace AppBundle\Migrations\Data\ORM;use Doctrine\Common\DataFixtures\AbstractFixture;use Doctrine\Common\Persistence\ObjectManager;use Oro\Bundle\TranslationBundle\Entity\Translation;use Oro\Bundle\TranslationBundle\Manager\TranslationManager;use Symfony\Component\DependencyInjection\ContainerAwareInterface;use Symfony\Component\DependencyInjection\ContainerAwareTrait;class LoadCustomTranslations extends AbstractFixture implements ContainerAwareInterface{use ContainerAwareTrait;/** @var TranslationManager */protected $translationManager;/*** {@inheritdoc}*/public function load(ObjectManager $manager){$this->createTranslation('translation_key.1', 'Translated Value1');$this->createTranslation('translation_key.2', 'Translated Value2');$this->getTranslationManager()->flush();$this->container->get('translator.default')->rebuildCache();}/*** @param string $key* @param string $value* @param string $locale* @return Translation*/protected function createTranslation($key, $value){$translationManager = $this->getTranslationManager();return $translationManager->saveTranslation($key,$value,'pt_BR','messages',Translation::SCOPE_UI);}/*** @return TranslationManager*/protected function getTranslationManager(){return $this->container->get('oro_translation.manager.translation');}}After adding migration you need to run
app/console oro:migration:data:load --env=prod --bundles=AppBundle
where AppBundle should be replaced with your bundle name.Migrations also can be loaded with
app/console oro:platform:update
but it will take more time as there a lot of other actions executedApril 30, 2018 at 2:49 pm #37148Thanks a lot, man!
I just changed the namespace, translation keys and values, executed:
PHP1app/console oro:migration:data:loadAnd works! o/
- AuthorReplies
The forum ‘OroPlatform’ is closed to new topics and replies.