jokiazhang / metadata-extractor

Automatically exported from code.google.com/p/metadata-extractor
0 stars 0 forks source link

Support localisation of description strings #80

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I want to return for the user, typed metadata. I basically go about it like 
this:

    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            String key = tag.getDirectoryName() + ": " + tag.getTagName();
            Object value = directory.getObject(tag.getTagType());
            results.put(key, value);
        }
    }

My problem with this is twofold:

  1. Sometimes there are units and the units are crucial. For instance, I have an image here with IFD0 "X Resolution" of 204 dots per inch. getObject() returns (Rational) 2040000/10000 but now I have no way to get the units.

  2. Sometimes an integer is returned for enum-like values. IFD0 "Resolution Unit" is one such place - getObject() returns (Integer) 2 and the user looks at that and wonders what it means.

Background: The reason I'm trying to avoid TagDescriptor.getDescription() comes 
down to localisation. I don't want to index property values with English text 
in them if the user is Chinese. For this, it would be much easier if I could 
get a value and a unit separately and then worry about what to do about 
localising the units (ideally, what I store into our database should not be 
localised at all, so that multiple users can each see their own language when 
looking at the data.)

Original issue reported on code.google.com by trejkaz on 28 May 2013 at 2:05

GoogleCodeExporter commented 9 years ago
The general solution is not as simple as just just returning a value and a unit 
separately. Many tags have a more complex structure than that.

It's my feeling that having TagDescriptor classes support localisation of 
strings is the most robust and idiomatic approach.

I've renamed the issue accordingly.

Comments on how to perform this are welcome.

Original comment by drewnoakes on 3 Jun 2013 at 11:15

GoogleCodeExporter commented 9 years ago
As far as localising getDescription(), I guess the simplest initial approach 
would be to add an alternate getDescription method with a Locale parameter. The 
default would then delegate to that one with Locale.getDefault() and the 
remaining problem is then finding people to translate the strings 
(unfortunately that is the biggest pain...)

Having a way to get the unit separately from the number/date/whatever, however, 
is still useful for me in cases where this is possible (I'd like to be able to 
index the values as their original types.) Essentially, at the moment I can get 
"Image Width" and "300 pixels" but what I'd rather generate is "Image Width 
(pixels)" and 300. The latter allows me to index numbers as numbers and then 
opens up the ability to do queries on ranges.

Original comment by trejkaz on 3 Jun 2013 at 1:10