Update $site content in a specific language

languages

#1

Hello!

I’m creating a plugin that imports translated site content into the site. I know that $page->update() can change the content for a specific language, but why $site->update() can’t? I looked over at the Kirby core and it appears that the Site class extends the Page class, so they should behave similarly? It’s not the case, though.

I noticed that $site->update() changes the data for the currently selected panel language, the state of which is stored under $_SESSION['kirby_panel_lang']. So I can kind of force an update for a specific language by changing that value right before I call the update() method. There are two problems with that:

  1. It doesn’t work for the default language. If I have en as the default, change the session value to en and call update(), the content isn’t changed. It only works for the other two languages I currently use (ko and zh).
  2. It’s a hack…

Is there a reliable way to do this?
Thanks!


#2

Actually, It seems to work exactly the same way as it does for $page. The problem was that besides site.en.txt, site.ko.txt and site.zh.txt, I also had site.txt, which was messing things up. I deleted it and everything works as expected now.

However, that functionality is still not documented on $site->update(). If it were documented, I’d know I was doing something wrong and it would’ve taken me less time to find that out.


#3

I’ve added it to the docs. The $siteobject extends the $pageobject, so inherits its methods.