Jump to content

How adding multilingual description to images or files with the API?


KarlvonKarton
 Share

Recommended Posts

Hi all,

I could not find the answer to following question.
How can I add multilingual descriptions to images or files with the API?

$p = $pages->get(1234);
$p->of(true);
$p->images->add("http://www.somewhere.com/files/filename.jpg");
$p->save();
$p->of(false);

I've been reading the link below, but can not figure it out in the above code...

https://github.com/ryancramerdesign/ProcessWire/issues/496

ps: $images or $files are "Array of Items" in my case

 

Link to comment
Share on other sites

3 minutes ago, adrian said:

$p->images->last()

 

Thus?

// get page
// ...
$en = $languages->get("en");
$fr = $languages->get("fr");
$p->images->add("http://www.somewhere.com/files/filename.jpg");
$lastimage = $p->images->last();
$lastimage->set("description$en", "Description in English");
$lastimage->set("description$fr", "Déscription en Français");
// ...
// save

 

Link to comment
Share on other sites

8 hours ago, KarlvonKarton said:

$p->of(false); // not sure about this

When you are not sure about this, you might want to: $of = $page->of(); and later on $page->of($of); like this:

$of = $page->of();
$page->of(false);
$page->set('property', 'value');
$page->save('property');
$page->of($of);

source: https://processwire.com/blog/posts/processwire-2.6.9-core-updates-and-new-procache-version/#processwire-core-updates-for-2.6.9

BTW: you might want to give $page->setAndSave()a shot.

  • Like 3
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
 Share

  • Recently Browsing   0 members

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