2

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');
    $model->setString($source);
    $model->setTranslate($translate);
    $model->setLocale('pl_PL');
    $model->save();
}

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');
    $model->save();
}

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?

2
  • Which error do you have?
    – mbalparda
    Commented Jul 31, 2014 at 15:10
  • I had no method found exceptions for setData() and others setTranslate(), setString(). Commented Aug 1, 2014 at 6:00

1 Answer 1

5

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

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.