2 * Copyright (C) 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android;
19 import java.util.Locale;
21 import java.util.HashMap;
24 * Handles any locale-specific logic for the client.
28 public final class LocaleManager {
29 private static final String DEFAULT_TLD = "com";
30 private static final Map<Locale,String> GOOGLE_COUNTRY_TLD;
32 GOOGLE_COUNTRY_TLD = new HashMap<Locale,String>();
33 GOOGLE_COUNTRY_TLD.put(Locale.CANADA, "ca");
34 GOOGLE_COUNTRY_TLD.put(Locale.CHINA, "cn");
35 GOOGLE_COUNTRY_TLD.put(Locale.FRANCE, "fr");
36 GOOGLE_COUNTRY_TLD.put(Locale.GERMANY, "de");
37 GOOGLE_COUNTRY_TLD.put(Locale.ITALY, "it");
38 GOOGLE_COUNTRY_TLD.put(Locale.JAPAN, "co.jp");
39 GOOGLE_COUNTRY_TLD.put(Locale.KOREA, "co.kr");
40 GOOGLE_COUNTRY_TLD.put(Locale.TAIWAN, "de");
41 GOOGLE_COUNTRY_TLD.put(Locale.UK, "co.uk");
44 // Google Product Search for mobile is available in fewer countries than web search.
45 private static final Map<Locale,String> GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD;
47 GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD = new HashMap<Locale,String>();
48 GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.UK, "co.uk");
49 GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD.put(Locale.GERMANY, "de");
52 private static final Map<Locale,String> GOOGLE_BOOK_SEARCH_COUNTRY_TLD;
54 GOOGLE_BOOK_SEARCH_COUNTRY_TLD = new HashMap<Locale,String>();
55 GOOGLE_BOOK_SEARCH_COUNTRY_TLD.putAll(GOOGLE_COUNTRY_TLD);
56 GOOGLE_BOOK_SEARCH_COUNTRY_TLD.remove(Locale.CHINA);
59 private LocaleManager() {}
62 * @return country-specific TLD suffix appropriate for the current default locale
63 * (e.g. "co.uk" for the United Kingdom)
65 public static String getCountryTLD() {
66 return doGetTLD(GOOGLE_COUNTRY_TLD);
70 * The same as above, but specifically for Google Product Search.
71 * @return The top-level domain to use.
73 public static String getProductSearchCountryTLD() {
74 return doGetTLD(GOOGLE_PRODUCT_SEARCH_COUNTRY_TLD);
78 * The same as above, but specifically for Google Book Search.
79 * @return The top-level domain to use.
81 public static String getBookSearchCountryTLD() {
82 return doGetTLD(GOOGLE_BOOK_SEARCH_COUNTRY_TLD);
86 private static String doGetTLD(Map<Locale,String> map) {
87 Locale locale = Locale.getDefault();
91 String tld = map.get(locale);