I've created module and I want to add translations to core_translate database table. I created array with original string and translation in form:

$words = array(
  'MyCustomModule::StringToTranslate' => 'String translation'

and in install PHP file I tried with:

foreach ($words as $source => $translate) {
    $model = Mage::getModel('core/translate');

and with:

foreach ($words as $source => $translate) {
    $model = Mage::getModel('core/translate');
    $model->setData('string', $source);
    $model->setData('translate', $translate);
    $model->setData('locale', 'pl_PL');

but I still get an error. As I see in Mage/Core/Model/Translate it just a simple class.

How can I add my translations into that table?

  • Which error do you have? – mbalparda Jul 31 '14 at 15:10
  • I had no method found exceptions for setData() and others setTranslate(), setString(). – Filip Górczyński Aug 1 '14 at 6:00

There is no save() function implemented in translate model and it does not extend from Mage_Core_Model_Abstract so you can not use the model for persisting data. instead you need to use resource model directly like this:

    /* @var $resource Mage_Core_Model_Resource_Translate_String */
    $resource = Mage::getResourceModel('core/translate_string');
    foreach ($words as $source => $translate) {
        $resource->saveTranslate($source, $translate, 'pl_PL', $storeId);

note that $storeId can be either null or int

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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