W3C home > Mailing lists > Public > www-validator-cvs@w3.org > March 2010

2006/unicorn/src/org/w3c/unicorn/util Language.java,1.22,1.23

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 22 Mar 2010 18:16:51 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1NtmBH-0000hk-Ta@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/util
In directory hutz:/tmp/cvs-serv2688/src/org/w3c/unicorn/util

Modified Files:
	Language.java 
Log Message:
updated sortByDisplayName function to allow to choose in which locale to sort

Index: Language.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/util/Language.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- Language.java	22 Mar 2010 17:59:52 -0000	1.22
+++ Language.java	22 Mar 2010 18:16:49 -0000	1.23
@@ -68,7 +68,7 @@
 		}
 		LocalePriorityList availableLocalesPriorityList = builder2.build();
 		availableLocaleMatcher = new LocaleMatcher(availableLocalesPriorityList);
-		sortByDisplayName(availableLocales);
+		sortByDisplayName(availableLocales, defaultLocale);
 	}
 	
 	public static void initUILocaleMatcher() {
@@ -79,7 +79,7 @@
 				builder = builder.add(locale);
 		LocalePriorityList uiLocalesPriorityList = builder.build();
 		uiLocaleMatcher = new LocaleMatcher(uiLocalesPriorityList);
-		sortByDisplayName(uiLocales);
+		sortByDisplayName(uiLocales, null);
 	}
 	
 	public static ULocale getLocale(String languageCode) {
@@ -212,11 +212,18 @@
 		return "ltr";
 	}
 	
-	private static void sortByDisplayName(ArrayList<ULocale> localeArray) {
+	private static void sortByDisplayName(ArrayList<ULocale> localeArray, final ULocale displayLocale) {
 		Collections.sort(localeArray, new Comparator<ULocale>() {
 			public int compare(ULocale l1, ULocale l2) {
-				String loc1 = l1.getDisplayName(l1);
-				String loc2 = l2.getDisplayName(l2);
+				String loc1;
+				String loc2;
+				if (displayLocale == null) {
+					loc1 = l1.getDisplayName(l1);
+					loc2 = l2.getDisplayName(l2);
+				} else {
+					loc1 = l1.getDisplayName(displayLocale);
+					loc2 = l2.getDisplayName(displayLocale);
+				}
 				return loc1.compareToIgnoreCase(loc2);
 			}
 		});
Received on Monday, 22 March 2010 18:16:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:19 GMT