0

I just need to change one string which is hardcoded (this was surprise for me) in

vendor/magento/module-catalog/Controller/Adminhtml/Product/Attribute/Save.php ,

in execute() method:

 $this->messageManager->addSuccess(__('You saved the product attribute.'));

I must change 'You saved the product attribute.' to another text with plugins/rewrites. As far as I know, the plugin can change only arguments' values or return value. If I will use extending the class, I can just overwrite the method, but then I have to copy-paste all the method's code.

Is there a better way to change this one string?

2
  • You want to change the only message You saved the product attribute?
    – Keyur Shah
    Commented Jan 11, 2018 at 20:27
  • @KeyurShah Yes, you're right
    – Audiophile
    Commented Jan 11, 2018 at 20:35

1 Answer 1

0

To translate the text you can use translation feature of Magento2. If you are using custom theme then you just need to create en_US.csv (I am assuming you have this locale If you have different then you can create different csv i.e for German(de_DE.csv)).

app\design\adminhtml\YOUR_THEME_VENDOR\YOUR_THEMEN_NAME\Magento_Catalog\i18n\en_US.csv

In this CSV file, you need to write like this,

"You saved the product attribute.","Your custom message here"

Then just execute

php bin/magento s:s:d and clear your cache php bin/magento c:f

10
  • Thank you. I understand that translations are the best way to change string. But accroding to my test task I need to do this with plugins or rewrites. Do you mean that this methods a-priory are terrible/overkill for such purposes?
    – Audiophile
    Commented Jan 11, 2018 at 20:59
  • It's always best practice to use translation feature to just change the text. plugins/rewrites is used when you need to change logic at code level or you need to add some new feature :) @Audiophile
    – Keyur Shah
    Commented Jan 11, 2018 at 21:03
  • This doesn't work... The string remains the same.
    – Audiophile
    Commented Jan 14, 2018 at 8:41
  • You're wrong, the i18n folder must be put in the module's folder, not theme's
    – Audiophile
    Commented Jan 14, 2018 at 9:04
  • No, you can also put in your module folder :) Please try it It works @Audiophile
    – Keyur Shah
    Commented Jan 14, 2018 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.