matjash Posted November 4, 2015 Share Posted November 4, 2015 Can someone help me solve this one: I have a saveReady hook. It shold read default language field and on save translate it with yandex translate api. I've got it working if I put the value manualy but it doesn't get read if I input it as $page->opis public function init() { // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookBefore('saveReady', $this, 'translate'); //$this->pages->addHookAfter('save', $this, 'example2'); } public function translate($event) { $page = $event->arguments[0]; $this->message("Hello you changed {$page->opis}."); /*Api key for yandex translator*/ $key = "trnsl.1.1.20151103T231043Z.0a5368c915d3f2ea.1906616d49e10cfd99e499e1884cbc175178f28b"; /*Bootstrap pw*/ include "../index.php"; /*Translator script*/ include "code.php"; $translateTxt = $page->opis; //Problematic line //$translateTxt = "Ali deluje?"; //Working $translateLang = 'sl-en'; $translator = new Translator($key); $translation = $translator->translate($translateTxt, $translateLang); $event->return = $page->opis->setLanguageValue("en", $translation); } Link to comment Share on other sites More sharing options...
matjash Posted November 5, 2015 Author Share Posted November 5, 2015 I've found the error: $translateTxt = $page->getLanguageValue("default", "opis"); //Problematic line Link to comment Share on other sites More sharing options...
Soma Posted November 5, 2015 Share Posted November 5, 2015 Huh? Why do you Bootstrap PW, when you're already in PW? 2 Link to comment Share on other sites More sharing options...
matjash Posted November 10, 2015 Author Share Posted November 10, 2015 I noticed that. The line stayed there from earlier testing. At that time the code wasn't put in an autoload module. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now