Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andrewfairlie opened this issue Jul 8, 2022 · 8 comments
Closed

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

andrewfairlie opened this issue Jul 8, 2022 · 8 comments

Comments

@andrewfairlie
Copy link

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
Copy link
Member

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
Copy link
Contributor

Mosnar commented Jul 8, 2022

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
Copy link
Contributor

khalwat commented Jul 8, 2022

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
Copy link
Member

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
Copy link
Author

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

@brandonkelly
Copy link
Member

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

@ccchapman
Copy link
Contributor

ccchapman commented Aug 2, 2023

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
Copy link
Member

Craft 5 is out now with translatable alt text 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants