Forums › Forums › OroPlatform › Translate address type
This topic contains 12 replies, has 2 voices, and was last updated by William Radi 5 years, 10 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 9, 2018 at 11:59 am #37120
Hi!
When creating a new contact (/contact/create), and adding a new address, there is a type checkbox, and there are two options: Billin and Shipping:And this appear too at the view page (/contact/view/), inside the address box:
So, how do I translate this options?
Based on this file:
I tryed to add the file entities.pt_BR.yml inside the translation folder, but it didn’t work. My entities.pt_BR.yml file looks like this:
YAML123address_type:billing: Residencialshipping: Comercial - CreatorTopic
- AuthorReplies
- April 10, 2018 at 6:16 am #37121
Hi!
I forgot to say… I’d like to do it programmatically.Thanks!
April 10, 2018 at 8:39 am #37122If necessary, link from the first image:
https://pasteboard.co/HfP6EFv.pngfrom the second image:
https://pasteboard.co/HfP76vKV.pngApril 10, 2018 at 8:55 am #37123Hi William,
You are on the right way, after adding translation please run the commandapp/console oro:translation:load --env=prod
April 10, 2018 at 10:49 am #37124Hello Anyt!
Thanks for the answer! I didn’t know about this command… It found some other translation files, but in this case, “Billing” and “Shipping” still there… =/
April 10, 2018 at 11:16 am #37125Sorry misleading you, AddressType is non a standard choice, it’s a Gedmo Translatable Entity.
So from the code side you can add translations using data migrations.
You can check the default migration that loads the original entities, at line 50 it just adds same translations for all the enabled languages.
https://github.com/oroinc/platform/blob/2.6.1/src/Oro/Bundle/AddressBundle/Migrations/Data/ORM/LoadAddressTypeData.php#L50So you probably should create one more migration that will fetch this entities by title or id and add required translations for your locale like in above example.
April 13, 2018 at 10:56 am #37126Anyt, sorry by late..
I’m new developping with Oro.. Could you give me more detales? :D
I was trying to do what you said, but unsuccessfully…I need to create another Migration that fetch the entityes… Is it like the beggining of the code that you sended, but using new entities with portuguese names?
PHP123456789// ...const ADDRESS_TYPE_PREFIX = 'address_type';/*** @var array*/protected $addressTypes = array(AddressType::TYPE_BILLING,AddressType::TYPE_SHIPPING,);turn into:
PHP123456789// ...const ADDRESS_TYPE_PREFIX = 'address_type';/*** @var array*/protected $addressTypes = array(AddressType::TIPO_RESIDENCIAL,AddressType::TIPO_COMERCIAL,);And do I need to use a data fixture to populate the table oro_address_type_translation?
Or also… If it’s nothing to do.. which files Do I need to create? rsrs
Thanks a lot, man!
April 13, 2018 at 12:08 pm #37127Another question, less long-winded.. rs
(’cause I’m still trying.. hehe)Do I need to update the oro_address_type table or oro_address_type_translation table?
Thanks again!
April 13, 2018 at 2:24 pm #37128Migration just a way to update database state from the code so you don’t need to edit it manually after running migration.
At the example above we just added some data, and you need to update it, so instead of creating new content you need just to fetch it from the database with doctrine, I guess you are familiar with it, like
$em->find(AddressType::class, $entityId)
And after fetching just add new translation like it’s added at the above example.After the migration will be ready make a backup of the database state, just in case something will go wrong and run from the cli command
app/console oro:migration:data:load --bundles=YourFancyBundle
This will synchronise your code and the database so you will get translations loaded to the database.May 2, 2018 at 12:41 pm #37129Hi, Andrey! Thanks for the answer!
But I think I need more details … because it’s not working and I’m sure it’s my fault ..Could you explain it to me again? Because more problems about entity translation are coming up …
So, I need to create a Data Fixture, like the file here
https://github.com/oroinc/platform/blob/2.6.1/src/Oro/Bundle/AddressBundle/Migrations/Data/ORM/LoadAddressTypeData.php#L50Where do I put it and how to set the $entityId?
PHP1$em->find(AddressType::class, $entityId)Thanks again!
May 2, 2018 at 1:15 pm #37130You can find original entity not by id but by label as it’s unique, like
$addressType = $em->getRepository(AddressType::class)->findByLabel('Billing');
May 4, 2018 at 6:47 am #37131Hi, Andrey!!
With your help and after some other researchs, I could translate! :D
That is my data fixture code:
PHP123456789101112131415161718192021222324// ...use Doctrine\Common\Persistence\ObjectManager;use Oro\Bundle\AddressBundle\Entity\AddressType;use Oro\Bundle\TranslationBundle\DataFixtures\AbstractTranslatableEntityFixture;class TranslateBillingAndShipping extends AbstractTranslatableEntityFixture{protected function loadEntities(ObjectManager $manager){$billing = $manager->getRepository(AddressType::class)->findOneByLabel('Billing');$shipping = $manager->getRepository(AddressType::class)->findOneByLabel('Shipping');$billing->setLabel('Cobrança');$billing->setLocale('pt_BR');$manager->persist($billing);$shipping->setLabel('Entrega');$shipping->setLocale('pt_BR');$manager->persist($shipping);$manager->flush();}}Thanks a lot, man!
May 29, 2018 at 6:02 am #37132I forgot to close the topic.. hehe
- AuthorReplies
The forum ‘OroPlatform’ is closed to new topics and replies.