Excluding image src translation globally with specific exceptions
-
Hi TranslatePress Support,
I’m looking for some guidance on the recommended way to handle image
srcattribute translation on a large site.Our site currently has approximately 60,000 images across 3,000 URLs, but we only need to translate the
srcattribute for fewer than 20 specific images.Ideally, I would like the following behaviour:
- By default, the
srcattribute 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 usingimgordata-no-translation, because that would prevent other attributes such asaltfrom 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
srcattribute 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
srctranslation.If there is a recommended implementation for this scenario, including a PHP filter or example code, I’d appreciate it.
Thanks,
QinisoThe page I need help with: [log in to see the link]
- By default, the
You must be logged in to reply to this topic.