Jump to content

Help with hook - auto translate module


Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...