Dave Damage Posted January 19, 2015 Share Posted January 19, 2015 Hello folks, I am currently working at a project where I have to import a Wordpress-Site to Processwire. I have a bunch of multilingual Pages and would like to import them to Processwire. Everything works fine but as soon as I try to set the Page-Url, Processwire throws the error: "Error: Call to a member function setLanguageValue() on a non-object". $page = new Page(); if($category['parent']) { $parent = $this->sanitizer->pageName($category['parent'], true); $page->parent = wire('pages')->get('/articles/'.$parent.'/'); } else { $page->parent = wire('pages')->get('/articles/'); } $page->template = 'category'; $deName = $this->sanitizeUmlaut($category['de']); $en = $this->languages->get("default"); $de = $this->languages->get("german"); $page->name = $this->sanitizer->pageName($category['name'], true); $page->title->setLanguageValue($en, $category['name']); $page->title->setLanguageValue($de, $deName, true); $page->save(); $page->url->setLanguageValue($en, $category['name']); $page->url->setLanguageValue($de, $deName, true); $page->wp_id = $category['id']; $page->save(); $this->message('Successfully imported '.$category['name']); Has anyone an idea on how to solve this problem? Link to comment Share on other sites More sharing options...
Soma Posted January 19, 2015 Share Posted January 19, 2015 You'll find all infos here http://processwire.com/api/multi-language-support/multi-language-fields/ $page->title is a string and not an object, so you need to turn off outputformatting first for the page. Link to comment Share on other sites More sharing options...
Dave Damage Posted January 19, 2015 Author Share Posted January 19, 2015 Hey Soma, thank you for your quick response. Somehow turning off outputformatting did not work: The title is set whether it is turned on or off, but everytime I try to set the localName oer localURL (http://processwire.com/api/multi-language-support/multi-language-urls/) of the page, it throws the same error. $page->localName->setLanguageValue($en, $category['name']); Furthermore, I seem unable to find how to set the "active"-Status of the URL in the API... [Edit:] Nevermind, I found the solution here: http://processwire.com/api/multi-language-support/multi-language-urls/ Link to comment Share on other sites More sharing options...
bcartier Posted January 20, 2015 Share Posted January 20, 2015 Hi Dave, I'm having the same problem - trying to set the page name in another language, and setting it to "active". I looked at the page you pointed to in your [Edit], above, but I'm only seeing a way to read those values... Would you mind sharing what worked for you? Thanks! Link to comment Share on other sites More sharing options...
Pierre-Luc Posted January 20, 2015 Share Posted January 20, 2015 Maybe this is relevant to your problem: https://github.com/ryancramerdesign/ProcessWire/issues/540 Link to comment Share on other sites More sharing options...
Dave Damage Posted January 20, 2015 Author Share Posted January 20, 2015 (edited) Hi Dave, I'm having the same problem - trying to set the page name in another language, and setting it to "active". I looked at the page you pointed to in your [Edit], above, but I'm only seeing a way to read those values... Would you mind sharing what worked for you? Thanks! $page->set("status$de",1); Sets the status for the $language (in my case $de). $page->set("name$de", $this->sanitizer->pageName($pageName_de, [true])); With "name$language" (in my case again $de) you set the Pagename in the Language. I don't know if its best practice to set the default language (in my case $en) with: $page->name = $this->sanitizer->pageName($pageName, [true]); or $page->set("name$en", $this->sanitizer->pageName($pageName_en, [true])); I went with the first option, and did not try the second one. Depending on the language, I highly recommend setting up a small script, that converts language-related mutations ( you english people really call Umlaute 'mutations'?) to more machine-readable characters ("oe" for "ö"). PS: I really like the way processwire handles languages compared to other systems (I'm looking at you, WP!). [Edit]: Somehow I posted the wrong link above and I am unable to retrieve the working one. Edited January 20, 2015 by Dave Damage Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2015 Share Posted January 20, 2015 You would use the beautifier translate option (Sanitizer::translate) to have sanitizer use the special char conversion $name = $this->sanitizer->pageName($pageName_en, Sanitizer::translate); The chars are defined in the PageName module config screen, where you can set conversion for each char like "ö => oe", default is "ö => o" 2 Link to comment Share on other sites More sharing options...
Dave Damage Posted January 20, 2015 Author Share Posted January 20, 2015 Ah good to know, thank you very much., haven't seen that... Link to comment Share on other sites More sharing options...
bcartier Posted January 20, 2015 Share Posted January 20, 2015 Thanks Dave! Link to comment Share on other sites More sharing options...
imandreas Posted March 19 Share Posted March 19 Hi , this topic is quite tricky, using the API to insert multilangual content, thanks for the above input. This works for me, just if someone needs it. Code is not cleaned: // Array with parent ID, object IDs of external database $externalDataFromJson["pwParentID"] = 12345; $externalDataFromJson["DE"] = '{"12": "Äpfel", "13": "Orangen" }'; $externalDataFromJson["EN"] = '{"13": "Oranges","12": "Apples"}'; createIt($externalDataFromJson); function createIt($data) { $dataDE = json_decode($data["DE"], true); $dataEN = json_decode($data["EN"], true); $DE = \ProcessWire\wire("languages")->get("name=default"); // Get the language object for the default language $EN = \ProcessWire\wire("languages")->get("name=en"); // Get the language object for the second language foreach ($dataDE as $id => $term_DE) { $findItBefore = \ProcessWire\wire("pages")->findOne('template=_vocabulary,external_id=' . $id); if ($findItBefore instanceof NullPage) { echo "<br>Do not Exists: " . $id . ' - ' . $term_DE . ' create: external_id '; $p = new \ProcessWire\Page(); $p->setOutputFormatting(false); $p->parent = \ProcessWire\wire("pages")->get( $data["pwParentID"] ); $p->template = '_vocabulary'; } else { echo "<br>Exists: " . $id . ' ' . $term_DE; //var_dump($findItBefore); $p = $findItBefore; $p->setOutputFormatting(false); //$p->of(false); // outputFormatting must be OFF } if (isset($dataEN[$id])) { $term_EN = $dataEN[$id]; } else { $term_EN = "Eng not found"; } $p->name = \ProcessWire\wire('sanitizer')->pageName($term_DE, true); $p->title->setLanguageValue($DE, $term_DE, true); $p->title->setLanguageValue($EN, $term_EN); $p->external_id = $id; $p->save(); //$p->set("status$de",1); $p->set("status$EN",1); //$p->set("name$de", \ProcessWire\wire('sanitizer')->pageName($term_DE, [true])); $p->set("name$EN", \ProcessWire\wire('sanitizer')->pageName($term_EN, [true])); $p->save(); $url = $p->localUrl("de"); echo "<hr>"; var_dump($url); $url = $p->localUrl("en"); echo "<hr>"; var_dump($url); echo "<hr>"; } } Now in settings/ the second URL (in my case "en") is "active" and translated :) 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