Jump to content

How to figure Multilanguage Images with one image var ?


iNoize
 Share

Recommended Posts

Hello I need some advice how to solve my problem.

I have a slider with 4 images.

The first picture is different for every language.

How can I define with the most efficient method which images should shown for every language??

Link to comment
Share on other sites

Alternative language fields maybe?

image // default

image_fr // alternative for "fr" lang

image_en // alternative for "en" lang

In template use

echo $page->image->url; 

And it will choose the right one depending on language.

Link to comment
Share on other sites

Keep in mind: What Soma suggested will only work as long as images are in the same position if you use a multi image field. 

If for example if you want the fourth image to be language specific, each of these fields need to have all four images. 

Regarding text in images: It would be good to consider twice, if you want to do this. It's a best practise to not do it. 

Link to comment
Share on other sites

my first idea was the same like Soma's

for every language own image var. 

I thought maybe there is a simple way. 

At the end I have about 10 Languages maybe and i have to upload foe every language all the 4 pictures ? 

And it will choose the right one depending on language.

I have to write an function ? 

How to check which language is active currently ? 

I come not around to solve this so, because the customer want it so :) 

Link to comment
Share on other sites

my first idea was the same like Soma's

for every language own image var. 

I thought maybe there is a simple way. 

At the end I have about 10 Languages maybe and i have to upload foe every language all the 4 pictures ? 

I have to write an function ? 

How to check which language is active currently ? 

I come not around to solve this so, because the customer want it so :)

No no function "And it will choose the right one depending on language."

Readup http://processwire.com/api/multi-language-support/multi-language-fields/#language-alternate-fields

somefield //default

somefield_fr / must match a language name "fr"

And PW will look for them and take care of which field is used according user language of course.

1. I think for carousel I would create a image per page and add language alternate fields for each language. Then create the slider from the those pages.

2. Or use the new core PageTable field to handle the slider. in the end it's the same as 1 as it creates a page for each PageTable entry, but nicer editing features.

3. Repeaters are still nice to also handle sliders, again each item is a page at the end anyway.

... not sure, it's what you have and it works fine. This is also one of those cases you wish there were no languages ;) I had to always deal with these sort of things and while it can't be simple it has to be complicated. An image has language descriptions that's enough most of the time, but there's cases where the image also has to be translated. PW doesn't have an image field that could stores an image per language (yet), which is a shame kinda :)

If you'd ask Ryan, he would response with my first post, that you can use language alternate fields for that. But it's not always the optimal and most practical solution. And it's really a edge case. In projects I work they're most likely often "Institutions etc" they like to have images of graphs and Political images that exist in various languages, flyers etc etc. 

After all it would be nice to have, and if PW could in some way support that, it would be really cool.

  • Like 1
Link to comment
Share on other sites

Like Soma suggested with language alternate fields installed, but for less redundance I'd go with that:

three (or more depending on language count) fields:

firstSliderImage (image)

firstSliderImage_fr (image)

multilangSliderImages (image)

then you build your slider like that (shematic):

$firstSlide = "<div class='slide'>
<img src='{$firstSliderImage->eq(0)->url}'>
</div>";

foreach($multilangSliderImages as $si){
$slides = "<div class='slide'>
<img src='{$si->url}'>
</div>";
}

$slider = $firstSlide.$slides;

echo $slider;

Advantage: Your client only has to differ the first slides, for the rest it suffices to upload one version.

edit: While re-reading this, it isn't even needed to build it like that since with language alternate fields you can configure to fall back to the standard language content. So just build it like Soma suggested, no need for multiple upload of the same image.

  • 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

  • Recently Browsing   0 members

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