craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

[4.x]: Alternative text doesn't translate across sites #11576

Closed andrewfairlie closed 2 years ago

andrewfairlie commented 2 years ago

What happened?

Description

On Craft CMS 4.1.3 changing the alternative text on a Spanish site changes the English version too. The translation icon appears on the field as expected.

Steps to reproduce

  1. Add multiple sites
  2. Add the built-in alternative text field to an asset source
  3. Upload an asset
  4. Add an alternative text on Site 1
  5. Go to Site 2, and the alternative text is the same
  6. Change alternative text on Site 2
  7. Go to Site 1, the alternative text will have changed too

Expected behavior

The alternative text should be able to be different per-site

Actual behavior

See steps to reproduce

Craft CMS version

4.1.3

PHP version

8.1.7

Operating system and version

Darwin 21.5.0

Database type and version

MySQL 5.7.38

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-39)

Installed plugins and versions

Dashboard Begone - 2.0.0 DigitalOcean Spaces Filesystem - 2.0.0 Expanded Singles - 2.0.0-beta.1 Neo - 3.1.7 Redactor - 3.0.2 Retour - 4.0.2 SEOmatic - 4.0.6 Table Maker - 4.0.2

brandonkelly commented 2 years ago

The native Alternative Text inputs aren’t actually translatable yet, so the bug here was that they got the translatable indicator.

I’m going to look into making them translatable for Craft 5.

Mosnar commented 2 years ago

The native Alternative Text inputs aren’t actually translatable yet, so the bug here was that they got the translatable indicator.

I’m going to look into making them translatable for Craft 5.

With all due respect, this sounds like a bug or at the very least, a critical limitation. I can absolutely see people adding a new language to a website and expecting to be able to translate the alt text, only to find that they need to write a migration to move their alt text back to a custom field in order to translate it.

khalwat commented 2 years ago

I guess the path forward is eschewing the baked-in Alt Text field, and rolling your own custom field for it like we used to. That way it will indeed be localizable per-site.

brandonkelly commented 2 years ago

Agree it’s not ideal. We need to reevaluate how it’s stored for Craft 5. Right now it’s in the assets table, which only gets one row per asset, not a row per asset/site.

andrewfairlie commented 2 years ago

Thanks for the update. I'll avoid using it and maybe migrate to Alternative Text in Craft 5.

brandonkelly commented 2 years ago

Craft 4.1.4 is out with the fix to the translation indicator.

ccchapman commented 1 year ago

Quick and dirty migration from native alt to custom field:

<?php

namespace craft\contentmigrations;

use Craft;
use craft\db\Migration;
use craft\elements\Asset;

/**
 * m230802_162747_move_assets_alt_text migration.
 */
class m230802_162747_move_assets_alt_text extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp(): bool
    {
        $NEW_FIELD_HANDLE = "altText";
        /** @var Asset $asset */
        foreach (
            Asset::find()
                ->hasAlt()
                ->all()
            as $asset
        ) {
            $asset->setFieldValue($NEW_FIELD_HANDLE, $asset->alt);
            Craft::$app->elements->saveElement($asset);
        }

        return true;
    }

    /**
     * @inheritdoc
     */
    public function safeDown(): bool
    {
        echo "m230802_162747_move_assets_alt_text cannot be reverted.\n";
        return false;
    }
}
brandonkelly commented 4 months ago

Craft 5 is out now with translatable alt text 🚀