Changeset 4144 in josm for trunk/src


Ignore:
Timestamp:
2011-06-19T12:11:45+02:00 (13 years ago)
Author:
stoecker
Message:

see #6064 - better handling of translation of relations

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r4100 r4144  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55import static org.openstreetmap.josm.tools.I18n.trc;
     6import static org.openstreetmap.josm.tools.I18n.trc_lazy;
    67import static org.openstreetmap.josm.tools.I18n.trn;
    78
     
    372373            return null;
    373374        } else
    374             return relation.get(nameTag);
     375            return trc_lazy(nameTag, relation.get(nameTag));
    375376    }
    376377
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r4081 r4144  
    160160    }
    161161
     162    public static final String trc_lazy(String context, String text) {
     163        if (context == null)
     164            return tr(text);
     165        if (text == null)
     166            return null;
     167        return MessageFormat.format(gettext_lazy(text, context), (Object)null);
     168    }
     169
    162170    /**
    163171     * Marks a string for translation (such that a script can harvest
     
    218226        }
    219227        return text;
     228    }
     229
     230    /* try without context, when context try fails */
     231    private static final String gettext_lazy(String text, String ctx)
     232    {
     233        int i;
     234        if(ctx == null && text.startsWith("_:") && (i = text.indexOf("\n")) >= 0)
     235        {
     236            ctx = text.substring(2,i-1);
     237            text = text.substring(i+1);
     238        }
     239        if(strings != null)
     240        {
     241            String trans = strings.get(ctx == null ? text : "_:"+ctx+"\n"+text);
     242            if(trans != null)
     243                return trans;
     244        }
     245        if(pstrings != null) {
     246            String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text);
     247            if(trans != null)
     248                return trans[0];
     249        }
     250        return gettext(text, null);
    220251    }
    221252
Note: See TracChangeset for help on using the changeset viewer.