Add functionality to localize asset's ALT text
Its pretty self explanatory ... There is no clean way to translate assets alts now.
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.
+1 for this, this should work as the fields are Localizable.
Please give the issue a 👍 reaction rather than saying +1
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.
Can you provide an update on this FR?
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.
Awesome! ❤️
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.
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!
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
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('.') }}"
Any update about this feature request? Since this is really a crucial shortcoming within the multisite setup....
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 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.
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.
Is there any news on this? Please add proper asset localization to statamic. We really need this supported.
Sorry, there's no news. A PR will be linked to this issue if/when it's implemented.
Any news on this, I still have this problem and the workaround is a bit clunky for pages with a lot of langauges