Changeset 1512 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-03-24T14:49:19+01:00 (15 years ago)
Author:
stoecker
Message:

fixed language handling for web access

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

Legend:

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

    r1496 r1512  
    424424    static public String getLanguageCodeU()
    425425    {
    426         String languageCode = Locale.getDefault().getLanguage();
     426        String languageCode = getLanguageCode();
     427        if(languageCode.equals("en"))
     428            return "";
    427429        return languageCode.substring(0,1).toUpperCase() + languageCode.substring(1) + ":";
    428430    }
    429431    static public String getLanguageCode()
    430432    {
     433        String full = Locale.getDefault().toString();
     434        if(full.equals("iw_IL"))
     435            return "he";
     436        /* list of non-single codes supported by josm */
     437        else if(full.equals("en_GB"))
     438            return full;
    431439        return Locale.getDefault().getLanguage();
    432440    }
  • trunk/src/org/openstreetmap/josm/actions/HelpAction.java

    r1511 r1512  
    172172        {
    173173            String title = url.substring(i);
    174             if(!title.startsWith(languageCode) && !languageCode.equals("En:"))
     174            if(languageCode.length() != 0 && !title.startsWith(languageCode))
    175175                title = languageCode + title;
    176176            langurl = url.substring(0, i) + title;
     
    195195          help.read(new StringReader(reader.read(this.url)),
    196196          help.getEditorKit().createDefaultDocument());
    197           if(help.getText().indexOf("      Describe ") >= 0)
     197          if(help.getText().length() == 0)
    198198          {
    199199              if(lang)
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r1509 r1512  
    6767         */
    6868        protected byte[] updateData() {
    69             String motd = "";
    70             String baseurl = Main.pref.get("help.baseurl", "http://josm.openstreetmap.de");
    71             WikiReader wr = new WikiReader(baseurl);
    72             String vers = "";
    73             String languageCode = Main.getLanguageCodeU();
    74             try {
    75                 motd = wr.read(baseurl + "/wiki/"+languageCode+"StartupPage");
    76             } catch (IOException ioe) {
    77                 try {
    78                     motd = wr.read(baseurl + "/wiki/StartupPage");
    79                 } catch (IOException ioe2) {
    80                     motd = "<html>" + styles + "<body><h1>" +
    81                         "JOSM - " + tr("Java OpenStreetMap Editor") +
    82                         "</h1>\n<h2 align=\"center\">(" +
    83                         tr("Message of the day not available") +
    84                         ")</h2></html>";
    85                 }
     69            String motd = new WikiReader().readLang("StartupPage");
     70            if(motd.length() == 0)
     71            {
     72                motd = "<html>" + styles + "<body><h1>" +
     73                "JOSM - " + tr("Java OpenStreetMap Editor") +
     74                "</h1>\n<h2 align=\"center\">(" +
     75                tr("Message of the day not available") +
     76                ")</h2></html>";
    8677            }
    87             motd = motd.replace("<!-- VERSION -->", tr("- running version is {0}",
    88             AboutAction.getVersionString()));
     78            else
     79            {
     80                motd = motd.replace("<!-- VERSION -->", tr("- running version is {0}",
     81                AboutAction.getVersionString()));
     82            }
    8983            // Save this to prefs in case JOSM is updated so MOTD can be refreshed
    9084            Main.pref.putInteger("cache.motd.html.version", myVersion);
  • trunk/src/org/openstreetmap/josm/tools/WikiReader.java

    r1483 r1512  
    66import java.io.InputStreamReader;
    77import java.net.URL;
     8
     9import org.openstreetmap.josm.Main;
    810
    911/**
     
    2022    }
    2123
     24    public WikiReader() {
     25        this.baseurl = Main.pref.get("help.baseurl", "http://josm.openstreetmap.de");
     26    }
     27
    2228    /**
    2329     * Read the page specified by the url and return the content.
     
    3238        BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8"));
    3339        if (url.startsWith(baseurl) && !url.endsWith("?format=txt"))
    34             return readFromTrac(in, url);
     40            return readFromTrac(in);
    3541        return readNormal(in);
     42    }
     43
     44    public String readLang(String text) {
     45        String languageCode = Main.getLanguageCodeU();
     46        String url = baseurl + "/wiki/"+languageCode+text;
     47        String res = "";
     48        try {
     49            res = readFromTrac(new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8")));
     50        } catch (IOException ioe) {}
     51        if(res.length() == 0 && languageCode.length() != 0)
     52        {
     53            url = baseurl + "/wiki/"+text;
     54            try {
     55                res = readFromTrac(new BufferedReader(new InputStreamReader(new URL(url).openStream(), "utf-8")));
     56            } catch (IOException ioe) {}
     57        }
     58        return res;
    3659    }
    3760
     
    4568    }
    4669
    47     private String readFromTrac(BufferedReader in, String url) throws IOException {
     70    private String readFromTrac(BufferedReader in) throws IOException {
    4871        boolean inside = false;
    4972        boolean transl = false;
     
    6689                transl = false;
    6790        }
     91        if(b.indexOf("      Describe ") >= 0)
     92            return "";
    6893        return "<html>" + b + "</html>";
    6994    }
Note: See TracChangeset for help on using the changeset viewer.