• HOME
  • ALBUMS
    • RECENT
    • MILANO CORTINA 2026
    • PARIS 2024
    • RIO 2016
    • ROLAND GARROS
    • SWISS SPORTS
    • SWISS AT ROLAND GARROS
  • MY BLOG
  • HOLIDAY DATABASE
  • FRESHFOCUS
  • HOME
  • ALBUMS
    • RECENT
    • MILANO CORTINA 2026
    • PARIS 2024
    • RIO 2016
    • ROLAND GARROS
    • SWISS SPORTS
    • SWISS AT ROLAND GARROS
  • MY BLOG
  • HOLIDAY DATABASE
  • FRESHFOCUS
  • HOME
  • ALBUMS
    • RECENT
    • MILANO CORTINA 2026
    • PARIS 2024
    • RIO 2016
    • ROLAND GARROS
    • SWISS SPORTS
    • SWISS AT ROLAND GARROS
  • MY BLOG
  • HOLIDAY DATABASE
  • FRESHFOCUS

MAKING CAPTION TRANSLATION WORK FOR YOU

    Claude Diderich How-To Technology No Comments

MAKING CAPTION TRANSLATION WORK FOR YOU


Translating IPTC-IM
If you are working for clients whose native language is not English, you probably have been challenged to write IPTC (International Press Telecommunications Council) image metadata, denoted by IPTC-IM, that is, headlines, captions, keywords, etc. in different languages. The challenge worsens if you want to offer the same images to different clients speaking/publishing in other languages.

Wouldn’t it be great if you could associate IPTC-IM in different languages with a single image? Although the XMP (eXtensibel Metadata Platform) standard image metadata, also known as ISO 16684-1, supports multi-lingual metadata (at least for some fields), currently, none of the commonly used software packages, like Photoshop and Photo Mechanic, support multi-lingual IPTC-IM. Unless your customer uses proprietary data that can read and interpret multi-lingual IPTC-IM, you are bound to manage multiple copies of the same image, only differentiation by the language in which IPTC-IM is written.

But a more challenging, or should I say, the time-consuming challenge, is to write IPTC-IM in multiple languages and ensure their consistency, not only when you are not native in each language. At least here on this front, technology can offer a sound solution. It is called AI-based machine translation. Many companies today provide high-quality translation engines that can be accessed through simple APIs (application programming interfaces). Most of them even offer free access if you are not a heavy user, meaning they often translate less than 500’000 characters per month.

Automatic caption translation using PHP

Today’s Open-Source environment offers multiple tools, libraries, and classes to read, translate, and write IPTC-IM automatically. In this post, I show how you can have your IPTC-IM translated on the fly with only a handful of PHP program lines using existing libraries.

Accessing the required libraries

Although multiple freely available libraries exist on the Web (or on github.com), I chose to use DeepL’s translation API simply because it offers the best translations I have seen. In nearly all the cases, the translations suggested by DeepL were correct out of the box. The only time I had an issue was when DeepL translated “Cross Country” in the context of cycling into “Langlauf,” which means “cross-country skiing.”

For the second library, I am biased, as I am using the Metadata class library that I have developed myself in the context of the HOLIDAY photo database project.

Both libraries can be easily installed using composer. Alternatively, you may download them from github.com.

composer require deeplcom/deepl-php
composer require diderich/metadata

Making the libraries available

Next, I make the libraries available to my IPTC-IM translation program using the recommended autoloading mechanism (using the PSR-4 standard).

require_once(‘vendor/autoload.php’);
use \Holiday\Metadata;
use \DeepL\Translator;

Configuring the data

To use the translation API from DeepL (or any other provider, like Google or IBM), you need to get an access key ($deep_key). The process is simple but often requires a credit card to ensure that you do not create multiple accounts to circumvent free usage limitations.

Next, I create an array ($field_ary) to store all the IPTC-IM fields I want to have automatically translated.

For the sake of parameter checking (and the fact that DeepL distinguished between British English and American English), I create an array ($lang_ary) of supported languages.

$deepl_key = ‘xxxxxxxx-xxxx-xxxx-xxxxxxxxxx’;
$fields_ary = [Metadata::CAPTION => 'CAPTION', Metadata::HEADLINE => 'HEADLINE' , Metadata::EVENT => 'EVENT', 
    Metadata::LOCATION => 'LOCATION', Metadata::INSTRUCTIONS => 'INSTRUCTIONS', 
    Metadata::USAGE_TERMS => 'USAGE TERMS', Metadata::KEYWORDS =>  KEYWORDS',      Metadata::SCENES => 'SCENES', 
    Metadata::GENRE => 'GENRE', Metadata::CITY => 'CITY', Metadata::COUNTRY => 'COUNTRY'];
$lang_ary = [‘en’ => ‘en-US’, ‘de’ => ‘de’, ‘fr’ => ‘fr’];

Getting the command line arguments

The next step is quite boring. It reads the arguments from the command line and checks their validity.

if($argv !== 3 && $argc !== 4) die(“$argv[0] src_lang dst_lang src_file [dst_file]\n”);
$src_lang = argv[1]; $dst_lan = $argv[2];
$src_file = $argv[3]; $dst_file = $argv[4];
if(!isset($lang_ary[$src_lang])) die("Error: Invalid source language specified '$src_lang'\n");
if(!isset($lang_ary[$dst_lang])) die("Error: Invalid target language specified '$dst_lang'\n");
if(!file_exists($src_file)) die("Error: Image file not found '$src_file'\n");

Initializing the libraries used

At the translation process’s core are Metadata (which handles reading and writing IPTC-IM from JPEG images) and Translator (which provides access to DeepL’s machine learning-based translation algorithm).

$metadata = new Metadata();
$translator = new Translator($deepl_key);

Reading the IPTC-IM

I start by reading the original image containing the IPTC metadata to be translated and written in English. One call to the Metadata::read() function does the job. The function raises an exception if the file cannot be found or an error occurs while reading the image and associated metadata.

$metadata->read($src_file);

Translating the IPTC-IM

Next, I iterate through all the fields I want to translate and translate their content using the DeepL API. Alternatively, you could use Google Translate or IBM Watson translate APIs. While translating fields, I distinguish between those fields that contain a single text string and those, like keywords, that contain an array of a text string. For reference, I display the translated results on the screen.

foreach($fields_ary as $field_id => $field_name) {
    if($metadata->isset($field_id)) {
        $src_data = $metadata->get($field_id);
        if(is_array($src_data)) {
            $tr_data = array();
            foreach($src_data as $key => $src_text) {
                $tr_data[$key] = $translator->translateText($src_text, $src_lang, $lang_ary[$dst_lang])->text;
            }
            echo "$field_name\n\t".implode(', ', $src_data)."\n\t".implode(', ', $tr_data)."\n";
        }
        else {
            $tr_data = $translator->translateText($src_data, $src_lang, $lang_ary[$dst_lang])->text;
            echo "$field_name\n\t$src_data\n\t$tr_data\n";
        }
        $metadata->set($field_id, empty($tr_data) ? false : $tr_data);
    }
}

Writing the IPTC-IM back

Finally, with one line of code, I create a new file containing the translated IPTC-IM. The metadata is written in both the IPTC/APP13 and the XMP/APP1 segments of the image.

$metadata->write($dst_file);

That’s it. Now you have a second file containing the translated IPTC-IM. Translating IPTC-IM has never been easier. If needed, you may edit the translated IPTC-IM in your favorite application.

Example

The example below shows all translated fields, as written back to the translated file example.de.jpg.

$ ./trcaption.php en de example.jpg example.de.jpg

CAPTION
    Silver medalists Timea Bacsinszky (left) and Martina Hingis (right) of Switzerland pose on the podium during the ceremony of the women's doubles gold medal match of the tennis tournament on day ten during the 2016 Rio Olympic Games in Rio de Janeiro, Brazil on August 14, 2016
    Die Silbermedaillengewinnerinnen Timea Bacsinszky (links) und Martina Hingis (rechts) aus der Schweiz posieren auf dem Podium während der Zeremonie des Goldmedaillenspiels im Damendoppel des Tennisturniers an Tag zehn der Olympischen Spiele 2016 in Rio de Janeiro, Brasilien, am 14. August 2016

HEADLINE
    Women's Double Tennis Gold Medal Match  During the 2016 Rio Olympic Games
    Tennis-Goldmedaillenmatch im Damendoppel bei den Olympischen Spielen 2016 in Rio

EVENT
    2016 Rio Olympic Games - Tennis
    Olympische Spiele 2016 in Rio - Tennis

INSTRUCTIONS
    * EDITORIAL USE ONLY *
    * NUR FÜR REDAKTIONELLE ZWECKE *

KEYWORDS
    Olympic Games, Tennis, Finals, Women, Sui, Silve Medal, Podium
    Olympische Spiele, Tennis, Endrunde, Frauen, Sui, Silvestermedaille, Podium

SCENES
    Jubilation
    Jubel

CITY
    Rio de Janeiro
    Rio de Janeiro

COUNTRY
    Brazil
    Brasilien
codeiptciptc-immetadataphptranslation

Claude Diderich

Claude Diderich is working as freelance professional sports photographer. He likes to freeze the action. His preferred sports are tennis, alpine ski, and athletics. Claude Diderich has covered numerous national as well as international sports events, including the 1998 Nagano, the 2002 Salt Lake City, the 2006 Torino, the Rio 2016, and most recently the 2024 Paris Olympic games. In 2015 he covered the Australian Open and in 2018, 2019, 2023, and 2024 the Roland Garros tennis tournament. His work has been published in Swiss and foreign publications. His photos are distributed by the Swiss photo agency freshfocus. Claude is a member of the International Sports Press Association (AIPS).

Post navigation

TEN TIPS FOR MORE EFFICIENTLY CAPTIONING PHOTOS
MY FIRST MIRRORLESS GRAND SLAM COVERAGE

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

SEARCH

CATEGORIES

  • Equipment (2)
  • How-To (4)
  • Technology (3)

LATEST BLOG POSTS

MY CANON EOS R1 CONFIGURATION

Here is a summary of the key configurations I…

MY FIRST MIRRORLESS GRAND SLAM COVERAGE

The first time I came in contact with mirrorless…

MAKING CAPTION TRANSLATION WORK FOR YOU

If you are working for clients whose native language…

GET IN TOUCH

CLAUDE DIDERICH SPORTS PICTURES

  • Mülibachstrasse 49, 8805 Richterswil, Switzerland
  • +41 (44) 450 8100
  • +41 (44) 450 8119
  • info@cdsp.photo
LATEST BLOG POSTS
MY CANON EOS R1 CONFIGURATION

Here is a summary of the key configurations I…

MY FIRST MIRRORLESS GRAND SLAM COVERAGE

The first time I came in contact with mirrorless…

MAKING CAPTION TRANSLATION WORK FOR YOU

If you are working for clients whose native language…

TEN TIPS FOR MORE EFFICIENTLY CAPTIONING PHOTOS

Thoroughly captioning photos is critical! Caption information (when using…

© 2021..2026 by Claude Diderich Sports Pictures. All Rights Reserved.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Cookie SettingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT