ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: bennetfabian on February 11, 2024, 01:36:04 PM

Title: Custom config i18n
Post by: bennetfabian on February 11, 2024, 01:36:04 PM
Dear Phil,
first of all I'd like to thank you for the amazing work you have done on ExifTool. It's one of the greatest open source projects I know!

I really tried searching for it but I don't think I found a good answer for my question. My .ExifTool_config has some Composite tags. How would I translate the PrintConv depending on which language the user defined in the -lang argument? Is there an internal tag containing ExifTool's language I could request using Require?

Let's say hypothetically that there was a tag that contained either 1 or 2. For example if it's 1 how would I return "One" if English is the requested language and "Eins" (one in German) if German is requested?

Thanks you some much in advance!
Bennet
Title: Re: Custom config i18n
Post by: Phil Harvey on February 11, 2024, 01:43:12 PM
Hi Bennet,

Very interesting question.  You can use "$self->Options('Lang')" in your PrintConv code to determine what language is being used.  Here is an example (I haven't tested it but I think it should work):

PrintConv => q{
    if ($self->Options('Lang') eq 'de') {
        return { 1 => 'Eins', 2 => 'Zwei' }->{$val};
    } else {
        return { 1 => 'One', 2 => 'Two' }->{$val};
    }
},

- Phil
Title: Re: Custom config i18n
Post by: bennetfabian on February 11, 2024, 02:49:55 PM
Hey Phil,
thank you so much for answering that quickly!

The solution you suggested works like a charm. I was pretty surprised that apparently no one has asked this question before (or Google just couldn't find it).

Once again thanks for creating this gem of a software!
Bennet
Title: Re: Custom config i18n
Post by: bennetfabian on February 11, 2024, 04:26:42 PM
Quote from: Phil Harvey on February 11, 2024, 01:43:12 PMHi Bennet,

Very interesting question.  You can use "$self->Options('Lang')" in your PrintConv code to determine what language is being used.  Here is an example (I haven't tested it but I think it should work):

PrintConv => q{
    if ($self->Options('Lang') eq 'de') {
        return { 1 => 'Eins', 2 => 'Zwei' }->{$val};
    } else {
        return { 1 => 'One', 2 => 'Two' }->{$val};
    }
},

- Phil

I used your solution to make a Composite tag called Month which returns the month of DateTimeOriginal in the language set for ExifTool. That's when I noticed that "Month" has a translation in de.pm but not in other languages.

Is there a way to provide tag descriptions in multiple different languages for a Composite tag? Alternatively is it possible to expand the lang files in a config file like .ExifTool_config?
Title: Re: Custom config i18n
Post by: StarGeek on February 11, 2024, 05:16:18 PM
See the -lang option (https://exiftool.org/exiftool_pod.html#lang-LANG) for details on what needs to be done to expand the translations.
Title: Re: Custom config i18n
Post by: bennetfabian on February 11, 2024, 05:35:34 PM
Quote from: StarGeek on February 11, 2024, 05:16:18 PMSee the -lang option (https://exiftool.org/exiftool_pod.html#lang-LANG) for details on what needs to be done to expand the translations.

Thanks for trying to help! Unfortunately I can't help translating into any language other than German.

My question concerns more of a niche case. Imagine you have a custom Composite tag that no one else but you really has use for. Obviously you wouldn't want thousands of people with their obscure custom tags that perhaps only they really have use for spamming the translation files.

So my question was more like if it is possible to have multiple descriptions for Composite tags or alternatively if it's possible to expand or modify the language "objects" in a .ExifTool_config.
Title: Re: Custom config i18n
Post by: Phil Harvey on February 11, 2024, 08:53:11 PM
I haven't thought about adding a translation for a User-defined tag, but here is a proof of concept that works for me:

use Image::ExifTool::Lang::de;

$Image::ExifTool::Lang::de::Translate{MyTag} = {
    Description => 'My German Description',
    PrintConv => { 'One' => 'Eins' },
};

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyTag => {
            Require => 'FileName',
            ValueConv => '1',
            PrintConv => { 1 => 'One' },
        },
    },
);

1;

- Phil
Title: Re: Custom config i18n
Post by: bennetfabian on February 13, 2024, 10:24:15 AM
Quote from: Phil Harvey on February 11, 2024, 08:53:11 PMI haven't thought about adding a translation for a User-defined tag, but here is a proof of concept that works for me:

use Image::ExifTool::Lang::de;

$Image::ExifTool::Lang::de::Translate{MyTag} = {
    Description => 'My German Description',
    PrintConv => { 'One' => 'Eins' },
};

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyTag => {
            Require => 'FileName',
            ValueConv => '1',
            PrintConv => { 1 => 'One' },
        },
    },
);

1;

- Phil

Worked flawlessly!
Thank you so much, Phil.