Changeset 8091 in josm for trunk


Ignore:
Timestamp:
2015-02-21T15:27:40+01:00 (10 years ago)
Author:
stoecker
Message:

proper handling of language infor for maps name and description

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r8067 r8091  
    2828import org.openstreetmap.josm.tools.CheckParameterUtil;
    2929import org.openstreetmap.josm.tools.ImageProvider;
     30import org.openstreetmap.josm.tools.LanguageInfo;
    3031
    3132/**
     
    152153    /** name of the imagery entry (gets translated by josm usually) */
    153154    private String name;
    154     /** original name of the imagery entry in case of translation call */
     155    /** original name of the imagery entry in case of translation call, for multiple languages English when possible */
    155156    private String origName;
     157    /** (original) language of the translated name entry */
     158    private String langName;
    156159    /** id for this imagery entry, optional at the moment */
    157160    private String id;
     
    166169    private ImageryBounds bounds = null;
    167170    private List<String> serverProjections;
     171    /** description of the imagery entry, should contain notes what type of data it is */
    168172    private String description;
     173    /** language of the description entry, "" for tr() result */
     174    private String langDescription;
    169175    private String attributionText;
    170176    private String attributionLinkURL;
     
    686692
    687693    /**
    688      * Sets the entry name and translates it.
     694     * Sets the entry name and handle translation.
     695     * @param name The used language
    689696     * @param name The entry name
    690      * @since 6968
    691      */
    692     public void setTranslatedName(String name) {
    693         this.name = tr(name);
    694         this.origName = name;
     697     * @since 8091
     698     */
     699    public void setName(String language, String name) {
     700        boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
     701        if(LanguageInfo.isBetterLanguage(langName, language)) {
     702            this.name = isdefault ? tr(name) : name;
     703            this.langName = language;
     704        }
     705        if(origName == null || isdefault) {
     706            this.origName = name;
     707        }
    695708    }
    696709
     
    791804    /**
    792805     * Sets the description text when existing.
     806     * @param name The used language
    793807     * @param description the imagery description text
    794      * @since 8065
    795      */
    796     public void setDescription(String description) {
    797         this.description = description;
     808     * @since 8091
     809     */
     810    public void setDescription(String language, String description) {
     811        boolean isdefault = LanguageInfo.getJOSMLocaleCode(null).equals(language);
     812        if(LanguageInfo.isBetterLanguage(langDescription, language)) {
     813            this.description = isdefault ? tr(description) : description;
     814            this.langDescription = language;
     815        }
    798816    }
    799817
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r8065 r8091  
    2020import org.openstreetmap.josm.io.CachedFile;
    2121import org.openstreetmap.josm.io.UTFInputStreamReader;
     22import org.openstreetmap.josm.tools.LanguageInfo;
    2223import org.xml.sax.Attributes;
    2324import org.xml.sax.InputSource;
     
    8283        ImageryBounds bounds;
    8384        Shape shape;
     85        // language of last element, does only work for simple ENTRY_ATTRIBUTE's
     86        String lang;
    8487        List<String> projections;
    8588
     
    133136                }).contains(qName)) {
    134137                    newState = State.ENTRY_ATTRIBUTE;
     138                    lang = atts.getValue("lang");
    135139                } else if ("bounds".equals(qName)) {
    136140                    try {
     
    207211                switch(qName) {
    208212                case "name":
    209                     /* TODO: don't ignore lang attribute */
    210                     entry.setTranslatedName(accumulator.toString());
     213                    entry.setName(lang == null ? LanguageInfo.getJOSMLocaleCode(null) : lang, accumulator.toString());
    211214                    break;
    212215                case "description":
    213                     /* TODO: don't ignore lang attribute */
    214                     entry.setDescription(accumulator.toString());
     216                    entry.setDescription(lang, accumulator.toString());
    215217                    break;
    216218                case "id":
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r7509 r8091  
    123123    }
    124124
     125    /**
     126     * Check if a new language is better than a previous existing. Can be used in classes where
     127     * multiple user supplied language marked strings appear and the best one is searched. Following
     128     * priorities: current language, english, any other
     129     *
     130     * @param oldLanguage the language code of the existing string
     131     * @param newLanguage the language code of the new string
     132     * @return true if new one is better
     133     * @since 8091
     134     */
     135    public static boolean isBetterLanguage(String oldLanguage, String newLanguage) {
     136        if (oldLanguage == null)
     137            return true;
     138        String want = getJOSMLocaleCode();
     139        return want.equals(newLanguage) || (!want.equals(oldLanguage) && newLanguage.startsWith("en"));
     140    }
     141   
     142    /**
     143     * Replies the language prefix for use in XML elements (with a dot appended).
     144     *
     145     * @return the XML language prefix
     146     * @see #getJOSMLocaleCode()
     147     */
    125148    public static String getLanguageCodeXML() {
    126149        return getJOSMLocaleCode()+".";
    127150    }
    128151
     152    /**
     153     * Replies the language prefix for use in manifests (with an underscore appended).
     154     *
     155     * @return the manifest language prefix
     156     * @see #getJOSMLocaleCode()
     157     */
    129158    public static String getLanguageCodeManifest() {
    130159        return getJOSMLocaleCode()+"_";
Note: See TracChangeset for help on using the changeset viewer.