What is the best way to override text string in Magento module's Save.php?
-
26-12-2020 - |
Question
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?
Solution
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