• Resolved QinisoM

    (@qinisom)


    Hi TranslatePress Support,

    I’m looking for some guidance on the recommended way to handle image src attribute translation on a large site.

    Our site currently has approximately 60,000 images across 3,000 URLs, but we only need to translate the src attribute for fewer than 20 specific images.

    Ideally, I would like the following behaviour:

    • By default, the src attribute of all <img> elements should not be translated.
    • For the small number of images that do require translation, I would explicitly mark them with a class such as allow-trp.
    • Other attributes on the image, particularly alt, should remain translatable.
    • I would like to avoid using a selector such as img:not(.allow-trp), as your documentation recommends avoiding :not() selectors.
    • I also don’t want to exclude the entire <img> element using img or data-no-translation, because that would prevent other attributes such as alt from being translated.

    For example, the desired behaviour would be:

    <!-- src should NOT be translated, alt SHOULD be translated -->
    <img src="/images/example.jpg" alt="Some translatable text">
    
    <!-- src SHOULD be translated, alt SHOULD also be translated -->
    <img class="allow-trp" src="/images/example.jpg" alt="Some translatable text">
    

    Is there a supported TranslatePress filter, hook, or configuration option that allows translation to be disabled specifically for the src attribute of <img> elements by default, while allowing individual images to opt back in via a class or other attribute?

    I’m particularly interested in an approach that doesn’t require TranslatePress to process or evaluate all 60,000 images unnecessarily, given that fewer than 20 actually require src translation.

    If there is a recommended implementation for this scenario, including a PHP filter or example code, I’d appreciate it.

    Thanks,
    Qiniso

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Alex

    (@alexcozmoslabs)

    Hi Qiniso,

    Thank you for the detailed explanation and for outlining the exact behaviour you are looking for.

    There is an important point that may simplify your setup: the src attribute of images is not translated automatically by TranslatePress when using automatic translation. Therefore, you do not need to exclude the src attribute for all 60,000 images.

    in your particular case, such a customization should not be necessary because automatic translation does not translate the image src attribute in the first place.

    You can simply focus on the fewer than 20 images that actually require a translated source and translate those manually in the TranslatePress Editor.

    At the same time, the alt attribute is automatically translated when using automatic translation, so the behaviour would match what you are looking for:

    • src → remains unchanged by automatic translation, so you can manually translate the source only for the specific images that require it.
    • alt → is automatically translated for all images.
    • No need to use img:not(.allow-trp).
    • No need to exclude the entire <img> element with img or data-no-translation.
    Thread Starter QinisoM

    (@qinisom)

    Hi Alex.

    Thanks for the prompt response and the above info.

    King regards,

    Qiniso

    Plugin Support Alex

    (@alexcozmoslabs)

    HI,

    You are welcome!

    Happy Translating,

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.