Custom config i18n

Started by bennetfabian, February 11, 2024, 01:36:04 PM

Previous topic - Next topic

bennetfabian

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bennetfabian

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

bennetfabian

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?

StarGeek

See the -lang option for details on what needs to be done to expand the translations.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

bennetfabian

Quote from: StarGeek on February 11, 2024, 05:16:18 PMSee the -lang option 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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bennetfabian

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.