MY FIRST MIRRORLESS GRAND SLAM COVERAGE
The first time I came in contact with mirrorless…
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.
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
require_once(‘vendor/autoload.php’); use \Holiday\Metadata; use \DeepL\Translator;
$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’];
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");
$metadata = new Metadata(); $translator = new Translator($deepl_key);
$metadata->read($src_file);
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); } }
$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.
$ ./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