Translating image captions with WPML

How to translate image captions provided by Image Source Control in WordPress combined with the WPML plugin

WPML is one of the best-known plugins for translating your WordPress website. I have recently worked with them to make our plugins more compatible.

In detail, with Image Source Control and WPML, you can:

  • show image captions and URLs based on the site language
  • translate the caption label and per-post list headline
  • translate the fallback image source text

Requirements

For the information in this tutorial to work, you need a valid license for WPML. Install the basic plugin and these add-ons from the WPML downloads page:

  • WPML String Translation – for translating options
  • Media Translation – for a better view of translating media

You must enable translation for custom media fields using a filter to translate image captions.

See https://wpml.org/wpml-hook/wpml_apply_save_attachment_actions/

The snippet to include in your theme function.php or a custom plugin could be this:

add_filter( 'wpml_apply_save_attachment_actions', '__return_true' );Code language: JavaScript (javascript)

Translating image captions

Once you enable media field translations, you should see the Image Source Control fields under WPML > Settings > Multilingual Content Setup > Custom Fields Translation.

I chose the default translation settings for the Image Source Control custom fields with care. You can still change them if you need to. Here are their meanings.

  • Don’t translate: WPML ignores these fields, which are good for system post meta. You shouldn’t change them for the four meta fields that have this by default.
  • Translate: allows to translate into different languages
  • Copy: Copies the field value across all languages, keeping it the same everywhere. It is ideal for custom fields like numbers or images that stay the same in every language. Update the information ideally at the original image.
  • Copy once: Takes the content from the original image once, but then you can translate it freely.

Source: https://wpml.org/documentation/getting-started-guide/translating-custom-fields/

You need the Media Translator add-on to get the original language and the original image when using the “Copy” options. Once configured, you can go to WPML > Media translator to see a list of media and an indication of their original language. Then switch to that language while editing the image source information in your media library to keep it persistent among all languages, in case you choose “Copy”.

You can

The following custom fields are system fields from ISC and should not be translated or translatable.

  • isc_image_posts
  • isc_post_images
  • isc_possible_usages
  • isc_possible_usages_last_check

Translating options

Some ISC options contain texts that you might want to translate. To find them, go to Settings > Image Sources.

  • Overlay > Overlay prefix – string name: source_pretext
  • Per-page list > Headline – string name: image_list_headline
  • Miscellaneous settings > Standard Source > Custom text – string name: standard_source_text

You can translate these strings under WPML > String Translation.

Limitations

Some links to posts with missing images or missing image sources might point to the original version instead of a translated one. I am also not entirely sure how reliably removing unused images is with WPML translations.

Let me know which specific features you need to work with WPML, and I will be happy to take a closer look.

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?

Reach out directly via the contact form.