neosin Posted April 3, 2018 Share Posted April 3, 2018 Hi all I am bootstraping PW to import large batches of data however I am having a hard time importing the alternate language using the suggested method I am using the language alternate field method as outlined here https://processwire.com/api/multi-language-support/multi-language-fields/#language-alternate-field-values here is the code I am using and the issue is that the French fields do not populate at all. The English data is fine but for some reason the French does not get filled in. The name of the alt lang is "fr" and the title is "Français", so I assumed I could do $page->body_fr but this seems not to be the case? while($row = $result->fetch_assoc()) { $p = new Page(); $p->template = "video-item"; $p->parent_id = 1057; $p->of(false); // outputFormatting must be OFF $p->title = $row['title_en']; $p->title_fr = $row['title_fr']; $p->summary = $row['description_en']; $p->summary_fr = $row['description_fr']; $p->save(); } The external database (non-PW) fields for French all exist and all have data. It seems if I have outputFormatting on or off makes no difference, initially I did not have it but after reading the link above I added it but it has no effect so far. What am I doing wrong? Link to comment Share on other sites More sharing options...
maxf5 Posted April 3, 2018 Share Posted April 3, 2018 Your code snippet is inside a foreach, right? You have to save the Page at the end. $p->save(); Link to comment Share on other sites More sharing options...
neosin Posted April 3, 2018 Author Share Posted April 3, 2018 yes sorry I didn't include that bit, but yes I have that, since the English saves. I've updated the OP code to show the full thing Link to comment Share on other sites More sharing options...
maxf5 Posted April 3, 2018 Share Posted April 3, 2018 Hm it's strange. Can you try this? $frz = $languages->get("fr"); $p->of(false); $p->summary->setLanguageValue($frz, $row['description_fr']); $p->save(); Link to comment Share on other sites More sharing options...
neosin Posted April 3, 2018 Author Share Posted April 3, 2018 @maxf5 it gives error "Call to a member function setLanguageValue() on string" but we are using $p->of(false); so it should be an array... I am confused This is the update code which is giving this error now while($row = $result->fetch_assoc()) { $fr = $languages->get("fr"); $p->of(false); $p->title = $row['title_en']; $p->title->setLanguageValue($fr, $row['title_fr']); $p->summary = $row['description_en']; $p->summary->setLanguageValue($fr, $row['description_fr']); $p->save(); } Link to comment Share on other sites More sharing options...
kongondo Posted April 3, 2018 Share Posted April 3, 2018 1 hour ago, neosin said: It seems if I have outputFormatting on or off makes no difference, It's always off when bootstrapping, so no need to set it yourself. Link to comment Share on other sites More sharing options...
bernhard Posted April 3, 2018 Share Posted April 3, 2018 setLanguageValue is a method of the $page api variable: https://processwire.com/api/ref/page/ $p->setLanguageValue($language, $field, $value); You cannot call it from the $p->summary property 1 Link to comment Share on other sites More sharing options...
neosin Posted April 3, 2018 Author Share Posted April 3, 2018 Hmm I found this old post it seems that some language options like LanguageSupportPageNames does not get loaded when bootstrapping? not sure if this is related to my issue Link to comment Share on other sites More sharing options...
bernhard Posted April 3, 2018 Share Posted April 3, 2018 1 Link to comment Share on other sites More sharing options...
maxf5 Posted April 3, 2018 Share Posted April 3, 2018 2 minutes ago, bernhard said: $p->setLanguageValue($language, $field, $value); You cannot call it from the $p->summary property Doesn't it work when he prefix his file with: <?php namespace ProcessWire; 1 Link to comment Share on other sites More sharing options...
neosin Posted April 3, 2018 Author Share Posted April 3, 2018 7 minutes ago, bernhard said: this worked thank you very much! $p->summary = $description_en; $p->setLanguageValue($fr,'summary',$description_fr); 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