Fix some obvious errors in TLD mappings. Key on country, not country-language, so it actually works in most cases!

git-svn-id: https://zxing.googlecode.com/svn/trunk@1888 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-08-17 19:52:50 +00:00
parent b27dc8eb28
commit e9bcd9befb

View file

@ -26,64 +26,78 @@ import java.util.HashMap;
* @author Sean Owen
*/
public final class LocaleManager {
private static final String DEFAULT_TLD = "com";
private static final String DEFAULT_COUNTRY = "US";
// Locales where Google web search is available. These should be kept in sync with our
// translations. The format for the manual countries is:
// Language, Country, unused, Google domain suffix
private static final Map<Locale,String> GOOGLE_COUNTRY_TLD;
private static final String COUNTRY;
static {
GOOGLE_COUNTRY_TLD = new HashMap<Locale,String>();
GOOGLE_COUNTRY_TLD.put(new Locale("en", "AU", ""), "com.au"); // AUSTRALIA
GOOGLE_COUNTRY_TLD.put(new Locale("bg", "BG", ""), "com.br"); // BULGARIA
GOOGLE_COUNTRY_TLD.put(Locale.CANADA, "ca");
GOOGLE_COUNTRY_TLD.put(Locale.CHINA, "cn");
GOOGLE_COUNTRY_TLD.put(new Locale("cs", "CZ", ""), "cz"); // CZECH REPUBLIC
GOOGLE_COUNTRY_TLD.put(new Locale("da", "DK", ""), "dk"); // DENMARK
GOOGLE_COUNTRY_TLD.put(new Locale("fi", "FI", ""), "fi"); // FINLAND
GOOGLE_COUNTRY_TLD.put(Locale.FRANCE, "fr");
GOOGLE_COUNTRY_TLD.put(Locale.GERMANY, "de");
GOOGLE_COUNTRY_TLD.put(new Locale("hu", "HU", ""), "hu"); // HUNGARY
GOOGLE_COUNTRY_TLD.put(new Locale("he", "IL", ""), "co.il"); // ISRAEL
GOOGLE_COUNTRY_TLD.put(Locale.ITALY, "it");
GOOGLE_COUNTRY_TLD.put(Locale.JAPAN, "co.jp");
GOOGLE_COUNTRY_TLD.put(Locale.KOREA, "co.kr");
GOOGLE_COUNTRY_TLD.put(new Locale("nl", "NL", ""), "nl"); // NETHERLANDS
GOOGLE_COUNTRY_TLD.put(new Locale("pl", "PL", ""), "pl"); // POLAND
GOOGLE_COUNTRY_TLD.put(new Locale("pt", "PT", ""), "pt"); // PORTUGAL
GOOGLE_COUNTRY_TLD.put(new Locale("ru", "RU", ""), "nl"); // RUSSIA
GOOGLE_COUNTRY_TLD.put(new Locale("sk", "SK", ""), "sk"); // SLOVAK REPUBLIC
GOOGLE_COUNTRY_TLD.put(new Locale("sl", "SI", ""), "si"); // SLOVENIA
GOOGLE_COUNTRY_TLD.put(new Locale("es", "ES", ""), "es"); // SPAIN
GOOGLE_COUNTRY_TLD.put(new Locale("sv", "SE", ""), "se"); // SWEDEN
GOOGLE_COUNTRY_TLD.put(Locale.TAIWAN, "de");
GOOGLE_COUNTRY_TLD.put(new Locale("tr", "TR", ""), "com.tr"); // TURKEY
GOOGLE_COUNTRY_TLD.put(Locale.UK, "co.uk");
Locale locale = Locale.getDefault();
COUNTRY = locale == null ? DEFAULT_COUNTRY : locale.getCountry();
}
// Google Product Search for mobile is available in fewer countries than web search. See here:
// http://www.google.com/support/merchants/bin/answer.py?answer=160619
private static final Map<Locale,String> GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD;
/**
* Locales (well, countries) where Google web search is available.
* These should be kept in sync with our translations.
*/
private static final Map<String,String> GOOGLE_COUNTRY_TLD;
static {
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD = new HashMap<Locale,String>();
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(new Locale("en", "AU", ""), "com.au"); // AUSTRALIA
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.CHINA, "cn");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.FRANCE, "fr");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.GERMANY, "de");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.ITALY, "it");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.JAPAN, "co.jp");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(new Locale("nl", "NL", ""), "nl"); // NETHERLANDS
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(new Locale("es", "ES", ""), "es"); // SPAIN
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.UK, "co.uk");
GOOGLE_COUNTRY_TLD = new HashMap<String,String>();
GOOGLE_COUNTRY_TLD.put("AR", "com.ar"); // ARGENTINA
GOOGLE_COUNTRY_TLD.put("AU", "com.au"); // AUSTRALIA
GOOGLE_COUNTRY_TLD.put("BG", "com.br"); // BULGARIA
GOOGLE_COUNTRY_TLD.put(Locale.CANADA.getCountry(), "ca");
GOOGLE_COUNTRY_TLD.put(Locale.CHINA.getCountry(), "cn");
GOOGLE_COUNTRY_TLD.put("CZ", "cz"); // CZECH REPUBLIC
GOOGLE_COUNTRY_TLD.put("DK", "dk"); // DENMARK
GOOGLE_COUNTRY_TLD.put("FI", "fi"); // FINLAND
GOOGLE_COUNTRY_TLD.put(Locale.FRANCE.getCountry(), "fr");
GOOGLE_COUNTRY_TLD.put(Locale.GERMANY.getCountry(), "de");
GOOGLE_COUNTRY_TLD.put("GR", "gr"); // GREECE
GOOGLE_COUNTRY_TLD.put("HU", "hu"); // HUNGARY
GOOGLE_COUNTRY_TLD.put("ID", "co.id"); // INDONESIA
GOOGLE_COUNTRY_TLD.put("IL", "co.il"); // ISRAEL
GOOGLE_COUNTRY_TLD.put(Locale.ITALY.getCountry(), "it");
GOOGLE_COUNTRY_TLD.put(Locale.JAPAN.getCountry(), "co.jp");
GOOGLE_COUNTRY_TLD.put(Locale.KOREA.getCountry(), "co.kr");
GOOGLE_COUNTRY_TLD.put("NL", "nl"); // NETHERLANDS
GOOGLE_COUNTRY_TLD.put("PL", "pl"); // POLAND
GOOGLE_COUNTRY_TLD.put("PT", "pt"); // PORTUGAL
GOOGLE_COUNTRY_TLD.put("RU", "ru"); // RUSSIA
GOOGLE_COUNTRY_TLD.put("SK", "sk"); // SLOVAK REPUBLIC
GOOGLE_COUNTRY_TLD.put("SI", "si"); // SLOVENIA
GOOGLE_COUNTRY_TLD.put("ES", "es"); // SPAIN
GOOGLE_COUNTRY_TLD.put("SE", "se"); // SWEDEN
GOOGLE_COUNTRY_TLD.put(Locale.TAIWAN.getCountry(), "tw");
GOOGLE_COUNTRY_TLD.put("TR", "com.tr"); // TURKEY
GOOGLE_COUNTRY_TLD.put(Locale.UK.getCountry(), "co.uk");
GOOGLE_COUNTRY_TLD.put(Locale.US.getCountry(), "com");
}
// Book search is offered everywhere that web search is available.
private static final Map<Locale,String> GOOGLE_BOOK_SEARCH_COUNTRY_TLD;
/**
* Google Product Search for mobile is available in fewer countries than web search. See here:
* http://www.google.com/support/merchants/bin/answer.py?answer=160619
*/
private static final Map<String,String> GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD;
static {
GOOGLE_BOOK_SEARCH_COUNTRY_TLD = new HashMap<Locale,String>();
GOOGLE_BOOK_SEARCH_COUNTRY_TLD.putAll(GOOGLE_COUNTRY_TLD);
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD = new HashMap<String,String>();
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("AU", "com.au"); // AUSTRALIA
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.CHINA.getCountry(), "cn");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.FRANCE.getCountry(), "fr");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.GERMANY.getCountry(), "de");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.ITALY.getCountry(), "it");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.JAPAN.getCountry(), "co.jp");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("NL", "nl"); // NETHERLANDS
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put("ES", "es"); // SPAIN
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.UK.getCountry(), "co.uk");
GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.US.getCountry(), "com");
}
/**
* Book search is offered everywhere that web search is available.
*/
private static final Map<String,String> GOOGLE_BOOK_SEARCH_COUNTRY_TLD = GOOGLE_COUNTRY_TLD;
private LocaleManager() {}
/**
@ -120,15 +134,8 @@ public final class LocaleManager {
return url.startsWith("http://google.com/books") || url.startsWith("http://books.google.");
}
private static String doGetTLD(Map<Locale,String> map) {
Locale locale = Locale.getDefault();
if (locale == null) {
return DEFAULT_TLD;
}
String tld = map.get(locale);
if (tld == null) {
return DEFAULT_TLD;
}
return tld;
private static String doGetTLD(Map<String,String> map) {
String tld = map.get(COUNTRY);
return tld == null ? DEFAULT_TLD : tld;
}
}