Jump to content

Prevent display of description in default language


depone
 Share

Recommended Posts

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.

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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>";
}

 

Link to comment
Share on other sites

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
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

×
×
  • Create New...