Jump to content

Recommended Posts

Posted

Hey all,

I am trying to prevent the display of descriptions for images in default language while user browses site with alternative language.

In a gallery my goal would be to display the same images, and hide the description that I am using as captions. As a hack I could decide based on tags, but this causes extra workload for the editors of the site, and seems less robust than a built in query.

Any hints are highly appreciated.

Posted

You can use this to check if it's not the default language and only display description in this case.

if(!$user->language->isDefaultLanguage) {
    // display description
}

 

  • Like 1
Posted

@adrian thanks for your reply. 

Sorry, my question wasn’t precise enough. I would like to display captions if they are translated, but need to hide the fallback if there is no translation available of given description.

Posted

@depone - I am still not the most experienced at multi-language stuff, but this will work:

$page->images->first()->get("description".$user->language->id);

This way you are explicitly stating that you want the description in the user's language with no fallback.

Maybe someone else has another solution?

Posted

Thanks again @adrian!

In my case the solution is a combination of your two suggestions. In the first place I am checking if the page is viewed in the default language and return description in the default language. If the page is viewed in another language I use your suggested get-code and display a caption, if there is one:

if ($defaultLanguage) {
  $out .= "<figcaption>{$image->description}</figcaption>";
} else {
  $out .= "<figcaption>{$translatedDescription}</figcaption>";
}

 

Posted

If you like one liners and it fits with the style/logic of code you are using, this will work:

$out .= "<figcaption>" . $page->image->get("description".($user->language->isDefaultLanguage ? '' : $user->language->id)) . "</figcaption>";

 

  • Like 1

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
×
×
  • Create New...