Add Kazakhstan to locales. Use static list instead of jdk locales

This commit is contained in:
Manfred Karrer 2016-10-09 13:57:54 +02:00
parent 6d4d394395
commit 3361de2c72
3 changed files with 149 additions and 16 deletions

View File

@ -23,7 +23,10 @@ import io.bitsquare.user.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class CountryUtil {
@ -140,18 +143,8 @@ public class CountryUtil {
return allCountries;
}
// We use getAvailableLocales as we depend on display names (would be a bit painful with translations if handled
// from a static list -or we find something ready made?).
private static List<Locale> getAllCountryLocales() {
List<Locale> allLocales = Arrays.asList(Locale.getAvailableLocales());
Set<Locale> allLocalesAsSet = allLocales.stream().filter(locale -> !"".equals(locale.getCountry()))
.map(locale -> new Locale("", locale.getCountry(), ""))
.collect(Collectors.toSet());
allLocales = new ArrayList<>();
allLocales.addAll(allLocalesAsSet);
allLocales.add(new Locale("", "MD", "")); // Moldava
allLocales.add(new Locale("", "KH", "")); // Cambodia
List<Locale> allLocales = LocaleUtil.getAllLocales();
allLocales.sort((locale1, locale2) -> locale1.getDisplayCountry().compareTo(locale2.getDisplayCountry()));
return allLocales;
}
@ -164,7 +157,7 @@ public class CountryUtil {
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",
"BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
"EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN",
"IQ", "IS", "IT", "JO", "JP", "KH", "KR", "KW", "LB", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MT", "MX",
"IQ", "IS", "IT", "JO", "JP", "KH", "KR", "KW", "KZ", "LB", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MT", "MX",
"MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU",
"SA", "SD", "SE", "SG", "SI", "SK", "SV", "SY", "TH", "TN", "TR", "TW", "UA", "US", "UY", "VE", "VN",
"YE", "ZA"};
@ -173,7 +166,7 @@ public class CountryUtil {
private static final String[] regionCodes = new String[]{"AS", "EU", "SA", "EU", "OC", "EU", "EU", "EU", "AS",
"SA", "SA", "EU", "NA", "EU", "SA", "AS", "SA", "NA", "EU", "NA", "EU", "EU", "EU", "EU", "NA", "AF",
"SA", "EU", "AF", "EU", "EU", "EU", "EU", "EU", "NA", "AS", "NA", "EU", "EU", "AS", "EU", "AS", "AS",
"AS", "EU", "EU", "AS", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "EU", "AF", "AF", "EU", "EU", "EU", "EU", "NA",
"AS", "EU", "EU", "AS", "AS", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "EU", "AF", "AF", "EU", "EU", "EU", "EU", "NA",
"AS", "NA", "EU", "EU", "OC", "AS", "NA", "SA", "AS", "EU", "NA", "EU", "SA", "AS", "EU", "EU", "EU",
"AS", "AF", "EU", "AS", "EU", "EU", "NA", "AS", "AS", "AF", "AS", "AS", "EU", "NA", "SA", "SA", "AS",
"AS", "AF"};

View File

@ -21,18 +21,23 @@ import io.bitsquare.user.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
public class LanguageUtil {
private static final Logger log = LoggerFactory.getLogger(LanguageUtil.class);
public static List<String> getAllLanguageCodes() {
List<Locale> allLocales = Arrays.asList(Locale.getAvailableLocales());
List<Locale> allLocales = LocaleUtil.getAllLocales();
final Set<String> allLocaleCodesAsSet = allLocales.stream()
.filter(locale -> !"".equals(locale.getLanguage()) && !"".equals(locale.getDisplayLanguage()))
.map(locale -> new Locale(locale.getLanguage(), "").getLanguage())
.collect(Collectors.toSet());
List<String> allLocaleCodes = new ArrayList<>();
allLocaleCodes.addAll(allLocaleCodesAsSet);
allLocaleCodes.sort((o1, o2) -> getDisplayName(o1).compareTo(getDisplayName(o2)));

View File

@ -0,0 +1,135 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class LocaleUtil {
private static final Logger log = LoggerFactory.getLogger(LocaleUtil.class);
public static List<Locale> getAllLocales() {
List<Locale> allLocales = new ArrayList<>();
allLocales.add(new Locale("", "AE", ""));
allLocales.add(new Locale("", "AL", ""));
allLocales.add(new Locale("", "AR", ""));
allLocales.add(new Locale("", "AT", ""));
allLocales.add(new Locale("", "AU", ""));
allLocales.add(new Locale("", "BA", ""));
allLocales.add(new Locale("", "BE", ""));
allLocales.add(new Locale("", "BG", ""));
allLocales.add(new Locale("", "BH", ""));
allLocales.add(new Locale("", "BO", ""));
allLocales.add(new Locale("", "BR", ""));
allLocales.add(new Locale("", "BY", ""));
allLocales.add(new Locale("", "CA", ""));
allLocales.add(new Locale("", "CH", ""));
allLocales.add(new Locale("", "CL", ""));
allLocales.add(new Locale("", "CN", ""));
allLocales.add(new Locale("", "CO", ""));
allLocales.add(new Locale("", "CR", ""));
allLocales.add(new Locale("", "CS", ""));
allLocales.add(new Locale("", "CU", ""));
allLocales.add(new Locale("", "CY", ""));
allLocales.add(new Locale("", "CZ", ""));
allLocales.add(new Locale("", "DE", ""));
allLocales.add(new Locale("", "DK", ""));
allLocales.add(new Locale("", "DO", ""));
allLocales.add(new Locale("", "DZ", ""));
allLocales.add(new Locale("", "EC", ""));
allLocales.add(new Locale("", "EE", ""));
allLocales.add(new Locale("", "EG", ""));
allLocales.add(new Locale("", "ES", ""));
allLocales.add(new Locale("", "FI", ""));
allLocales.add(new Locale("", "FR", ""));
allLocales.add(new Locale("", "GB", ""));
allLocales.add(new Locale("", "GR", ""));
allLocales.add(new Locale("", "GT", ""));
allLocales.add(new Locale("", "HK", ""));
allLocales.add(new Locale("", "HN", ""));
allLocales.add(new Locale("", "HR", ""));
allLocales.add(new Locale("", "HU", ""));
allLocales.add(new Locale("", "ID", ""));
allLocales.add(new Locale("", "IE", ""));
allLocales.add(new Locale("", "IL", ""));
allLocales.add(new Locale("", "IN", ""));
allLocales.add(new Locale("", "IQ", ""));
allLocales.add(new Locale("", "IS", ""));
allLocales.add(new Locale("", "IT", ""));
allLocales.add(new Locale("", "JO", ""));
allLocales.add(new Locale("", "JP", ""));
allLocales.add(new Locale("", "KH", ""));
allLocales.add(new Locale("", "KR", ""));
allLocales.add(new Locale("", "KW", ""));
allLocales.add(new Locale("", "KZ", ""));
allLocales.add(new Locale("", "LB", ""));
allLocales.add(new Locale("", "LT", ""));
allLocales.add(new Locale("", "LU", ""));
allLocales.add(new Locale("", "LV", ""));
allLocales.add(new Locale("", "LY", ""));
allLocales.add(new Locale("", "MA", ""));
allLocales.add(new Locale("", "MD", ""));
allLocales.add(new Locale("", "ME", ""));
allLocales.add(new Locale("", "MK", ""));
allLocales.add(new Locale("", "MT", ""));
allLocales.add(new Locale("", "MX", ""));
allLocales.add(new Locale("", "MY", ""));
allLocales.add(new Locale("", "NI", ""));
allLocales.add(new Locale("", "NL", ""));
allLocales.add(new Locale("", "NO", ""));
allLocales.add(new Locale("", "NZ", ""));
allLocales.add(new Locale("", "OM", ""));
allLocales.add(new Locale("", "PA", ""));
allLocales.add(new Locale("", "PE", ""));
allLocales.add(new Locale("", "PH", ""));
allLocales.add(new Locale("", "PL", ""));
allLocales.add(new Locale("", "PR", ""));
allLocales.add(new Locale("", "PT", ""));
allLocales.add(new Locale("", "PY", ""));
allLocales.add(new Locale("", "QA", ""));
allLocales.add(new Locale("", "RO", ""));
allLocales.add(new Locale("", "RS", ""));
allLocales.add(new Locale("", "RU", ""));
allLocales.add(new Locale("", "SA", ""));
allLocales.add(new Locale("", "SD", ""));
allLocales.add(new Locale("", "SE", ""));
allLocales.add(new Locale("", "SG", ""));
allLocales.add(new Locale("", "SI", ""));
allLocales.add(new Locale("", "SK", ""));
allLocales.add(new Locale("", "SV", ""));
allLocales.add(new Locale("", "SY", ""));
allLocales.add(new Locale("", "TH", ""));
allLocales.add(new Locale("", "TN", ""));
allLocales.add(new Locale("", "TR", ""));
allLocales.add(new Locale("", "TW", ""));
allLocales.add(new Locale("", "UA", ""));
allLocales.add(new Locale("", "US", ""));
allLocales.add(new Locale("", "UY", ""));
allLocales.add(new Locale("", "VE", ""));
allLocales.add(new Locale("", "VN", ""));
allLocales.add(new Locale("", "YE", ""));
allLocales.add(new Locale("", "ZA", ""));
return allLocales;
}
}