X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Flocalisation%2FLanguage.java;h=4c6e39012094281c3736c5e4a73649b93c6bbe80;hb=2c4fc7cce080ad0186c3bfd11cbc840a71645b81;hp=3d8ee0b6d36db04a1e4ce4554b30e2dd2fd0fff5;hpb=785fe6cd9e7c9116b801aafc443b4f090cce870c;p=gigi.git diff --git a/src/org/cacert/gigi/localisation/Language.java b/src/org/cacert/gigi/localisation/Language.java index 3d8ee0b6..4c6e3901 100644 --- a/src/org/cacert/gigi/localisation/Language.java +++ b/src/org/cacert/gigi/localisation/Language.java @@ -3,6 +3,8 @@ package org.cacert.gigi.localisation; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.Locale; @@ -32,6 +34,14 @@ public class Language { String language = f.getName().split("\\.", 2)[0]; supported.add(getLocaleFromString(language)); } + Collections.sort(supported, new Comparator() { + + @Override + public int compare(Locale o1, Locale o2) { + return o1.toString().compareTo(o2.toString()); + } + + }); supportedLocales = supported.toArray(new Locale[supported.size()]); } @@ -53,22 +63,22 @@ public class Language { private HashMap translations = new HashMap(); - private Locale l; + private Locale locale; - private static Locale project(Locale l) { - if (l == null) { + private static Locale project(Locale locale) { + if (locale == null) { return Locale.getDefault(); } - File file = new File("locale", l.toString() + ".xml"); + File file = new File("locale", locale.toString() + ".xml"); if ( !file.exists()) { - return new Locale(l.getLanguage()); + return new Locale(locale.getLanguage()); } - return l; + return locale; } - protected Language(Locale loc) throws ParserConfigurationException, IOException, SAXException { - File file = new File("locale", loc.toString() + ".xml"); - l = loc; + protected Language(Locale locale) throws ParserConfigurationException, IOException, SAXException { + File file = new File("locale", locale.toString() + ".xml"); + this.locale = locale; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document d = db.parse(new FileInputStream(file)); @@ -93,30 +103,36 @@ public class Language { return string; } - public static Language getInstance(Locale language) { - language = project(language); - File file = new File("locale", language.toString() + ".xml"); + public static Language getInstance(Locale locale) { + locale = project(locale); + File file = new File("locale", locale.toString() + ".xml"); if ( !file.exists()) { return null; } - Language l = langs.get(language.toString()); - if (l == null) { - try { - l = new Language(language); - langs.put(language.toString(), l); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); + Language lang = langs.get(locale.toString()); + if (lang == null) { + synchronized (Language.class) { + lang = langs.get(locale.toString()); + if (lang != null) { + return lang; + } + try { + lang = new Language(locale); + langs.put(locale.toString(), lang); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } } } - return l; + return lang; } public Locale getLocale() { - return l; + return locale; } }