ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Add functionality to localize asset's ALT text

Open Krzemo opened this issue 5 years ago • 16 comments

Its pretty self explanatory ... There is no clean way to translate assets alts now.

Krzemo avatar Jul 09 '20 21:07 Krzemo

Trying to think of a workaround, only thing I can think of is to create separate fields for each locale and then check the locale in the template and grab the correct field.

edalzell avatar Dec 09 '20 23:12 edalzell

+1 for this, this should work as the fields are Localizable.

afonic avatar Dec 10 '20 08:12 afonic

Please give the issue a 👍 reaction rather than saying +1

jasonvarga avatar Dec 10 '20 14:12 jasonvarga

Until this functionality is implemented, I think that the possibility of marking as translatable the fields that are added in the blueprints of the assets should be disabled.

vaites avatar Jun 24 '21 06:06 vaites

Can you provide an update on this FR?

zehfred avatar Dec 20 '21 22:12 zehfred

Until it gets added to the Roadmap there's no way to give an ETA. This one is climbing the ranks though, stay tuned – it's about to make it to the list.

jackmcdade avatar Dec 20 '21 22:12 jackmcdade

Awesome! ❤️

zehfred avatar Dec 20 '21 22:12 zehfred

Until it gets added to the Roadmap there's no way to give an ETA. This one is climbing the ranks though, stay tuned – it's about to make it to the list.

Hope it is climbing harder and harder, because we need this functionality. Our web editors are asking for this feature a while now and it is to complex for me to make a PR request for this.

GertTimmerman avatar Dec 21 '21 08:12 GertTimmerman

Hey @GertTimmerman if it helps at all, this is how we handled this.

We edited the Asset blueprint and added the alt text for each language using a handle like "alt_handle", where "handle" is the site handle. For example "alt_english", alt_greek", "alt_german" etc.

Then in the frontend we created a simple tag to get the correct language for the captions / alt text:

<?php

namespace App\Tags;

use Statamic\Tags\Tags;

class AltText extends Tags
{
    /**
     * The {{ alt_text }} tag.
     *
     * @return string|array
     */
    public function index()
    {
        $image = $this->params->get('image');
        return $image->get('alt_'.$this->context->get('site'));
    }

}

and then we call it in the template like so: {{ alt_text :image="main_image" }} (if main_image is an asset field)

Hope this helps!

afonic avatar Dec 21 '21 08:12 afonic

Hey @GertTimmerman if it helps at all, this is how we handled this.

We edited the Asset blueprint and added the alt text for each language using a "alt_handle", where handle is the site handle. For example "alt_english", alt_greek", "alt_german" etc.

Then in the frontend we created a simple tag to get the correct language for the captions / alt text:

<?php

namespace App\Tags;

use Statamic\Tags\Tags;

class AltText extends Tags
{
    /**
     * The {{ alt_text }} tag.
     *
     * @return string|array
     */
    public function index()
    {
        $image = $this->params->get('image');
        return $image->get('alt_'.$this->context->get('site'));
    }

}

and then we call it in the template like so: {{ alt_text :image="main_image" }} (if main_image is an asset field)

Help this helps!

Thanks, i will implement that, our web editors and especial our seo guy will be pleased with this

GertTimmerman avatar Dec 22 '21 10:12 GertTimmerman

When you use Runtime you could add fields to the assets blueprint (like Erin suggested) and do this in your template:

{{ localized_alt = 'alt_{locale}' | ensure_right('.') }}

And then use it like this:

alt="{{ @localized_alt ?? alt | ensure_right('.') }}"

robdekort avatar Apr 18 '22 15:04 robdekort

Any update about this feature request? Since this is really a crucial shortcoming within the multisite setup....

justkidding96 avatar Jun 26 '23 14:06 justkidding96

Not what you want to hear probably, but no known updates currently. However localising CP field labels is on the roadmap. Maybe they'll tackle this as well.

You can use the workaround for now though.

robdekort avatar Jun 26 '23 14:06 robdekort

@robdekort Thanks for your answer! For now I created an addon which you can find on the: marketplace I hope that this will be added in the future.

justkidding96 avatar Jun 27 '23 17:06 justkidding96

Since this is still unimplemented, it might be good to take away this flag for fields defined in the asset blueprint as localisable. It is confusing for users, as there is no way of actually entering localised data into that field.

image

lostgeek avatar Jul 15 '24 12:07 lostgeek

Is there any news on this? Please add proper asset localization to statamic. We really need this supported.

albertvisuals avatar Nov 02 '24 17:11 albertvisuals

Sorry, there's no news. A PR will be linked to this issue if/when it's implemented.

duncanmcclean avatar Nov 04 '24 09:11 duncanmcclean

Any news on this, I still have this problem and the workaround is a bit clunky for pages with a lot of langauges

tobinski avatar Nov 11 '25 09:11 tobinski