If you, like me, develop multi-lingual sites and go for unversioned Media Items, you may stumble upon a couple of problems. Usually we think of media items as a replacement of a regular file, i.e. some kind of binary data that is always the same regardless of its context. The most obvious advantage of a media item over a regular file, is that we can track its usage. That’s really hard with a regular file stored in the file system. The second advantage is of course the ability to decorate a media item with meta data, such as image dimensions etc. Many of these values can be considered as shared values, but some times we want alternative content on different languages, such as alternative (ALT) texts on images. Now the dark clouds are looming…
So, lets for now on just focus on image media items and their ALT texts. Having that said, most of below applies to any other Sitecore field that can be translated. I’ve also focused on “Unversioned Media Items”. Those are the ones we usually go for.
The first obstacle in multi-lingual sites, is probably the actual translation of ALT texts. Even though you don’t “translate” an image, it’s referenced in a context where you’ll have to consider language. That is the page where you write your <img />-tag that contains the alternative text. You may do some translations at the beginning when the site is new and fresh and you’ve done a bulk translation of all contents. But as the site evolves, content authors will probably not bother much about such translations and they probably doesn’t have access to actually do a translation into all languages either.
You could argue that it’s better to change the ALT text field into a shared field, and that’s probably fine in some situations. But in general it would be a shame not to allow translations at all. A good universal alternative text written in English, in combination with a relevant filename and path, is probably the best goal to aim for. When possible, let the content authors do translations of the texts where it’s relevant.
Note: Sorry for the confusing naming in this blog post. We’re mixing things like “unversioned media items” and “unversioned fields”. Language versions of an item is not the same as a versioned media item. Keep in mind the difference and I hope you’ll follow me.
First I’d like to let you know of a small bug that you not have noticed. If you upload a single image into the Media Library, the UI will show a text box where you can type an alternative text. This is a reported and confirmed UI bug in Sitecore, at least version 6.6, 7.0 and 7.1. I haven’t checked the other versions. The text box isn’t supposed to be there, because the dialog is closed as soon as the image is uploaded and if you type anything it won’t be saved. If you want to add an ALT text during upload, you should go for the advanced upload dialog instead.
The upload process
Sitecore MediaCreator, used in the upload process, behaves a bit differently from other item creation processes. When creating unversioned items, it creates a language version for every configured language. This is quite good actually, because it means that regardless of what language you’ve selected, you’ll have a version in each language. If you type an ALT text, using the advanced upload dialog, that text will be written into all languages. This applies even if you haven’t got language write access to every language since the MediaCreator uses the SecurityDisabler. Good. Now you have an alternative text for the image on all languages, provided by the content author. It’s the same for all languages, but it’s a good start.
So far so good.
But content authors may not actually type anything in the alternative text field in the advanced upload dialog. The result is a null value in all language versions and the content author may not have language write access to actually change it. The author may also upload a zip-file for extraction. That also results in null value in all version. Most probably, the content author uses the standard upload dialog, and that also results in an empty Alt text field.
At a glance, Sitecore seems to provide us with a little help here. You can enable the Media.AutoSetAlt setting and Sitecore will store the file name as ALT text during upload. Unfortunately this doesn’t work very well in multi-lingual sites. This is because during the upload process, MediaCreator loops over all configured languages, creates a version in each language, and sets the provided ALT text. That is the ALT text given the advanced upload dialog only. Later down the upload pipeline, UpdateMetaData will check if Media.AutoSetAlt is true and set the filename as ALT text if no such text is previously provided. This means it will set that value on the current language only. And since you cannot provide an alternative text in the standard upload dialog, you’ll also end up with the filename as ALT text on the current language only. Many thank’s to my great colleague Magnus Unger for investigating this! This is now filed as a bug.
Someone suggested setting $name in the standard values for the Alt field on the image template. This will distribute the item name, i.e. the filename, to all language versions. However, this disables the ability to set a proper ALT text in the advanced upload dialog, so it’s not a sufficient solution.
Then we have the management problems. If a content author doesn’t provide a good ALT text from the very beginning, changing it afterwards can be a hazard as well. It has to be changed on all languages, right. Does the content author have access to all languages? Probably not. If they have access, will they bother setting it on let say 30-40 languages? No.
But at least you have a text and you can modify it on each language, since the ALT field is versioned field. You could hook into the item:saving event and check for ALT text changes and distribute the change across multiple languages. But are the content editor writing a better ALT text for the particular item, that should be distributed to all languages, or is (s)he writing a translation or local adaptation of it? I don’t yet know the answer to this. Do you?
There are a few other pitfalls to avoid as well. If you add a language to your setup, language versions will not be created for existing media items. This means you’ll have to make a new language version for each media item. Secondly, if you import items from other systems using the package installer, TDS or similar, the language versions won’t be created either (good!). So you’ll need some kind of script to generate those versions and copy the ALT text. What value should you copy if there are multiple values across the language versions?
I don’t have a silver bullet for this problem. We created a command that analyses a media item and creates missing versions and we try to find the best suited ALT text from the ones provided on the existing languages. It works to some extent, but it’s still hard to manage.
Editing the Alt text field also means you update the statistics fields of the item. As you know, the __Updated field is unversioned, so caching and Last-Modified in the HTTP response header gets messed up. See my post about adding a proper LastModified field to Sitecore as a way of solving this.
Just a note if you didn’t follow me: Why do we need language versions of all images and a relevant ALT text on each language? Well, theoretically don’t, but it certainly helps. On pages where we reference the image, we should have a validator ensuring the image placeholder has a good alternative text. Unless you specify it on the image reference, it will pick up the ALT text from the image itself. Having it on the image means we don’t have to specify it every time we reuse the image and we have a central place to update it. Every time the image is reused, it’s still the same image, so it’s on rare occasions the ALT text needs to be different.
How do you treat your ALT texts on multi-lingual sites? What’s your experiences?