1 // Copyright 2011 Google Inc. All Rights Reserved.
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
15 package com.hughes.android.dictionary.engine;
\r
17 import java.util.LinkedHashMap;
\r
18 import java.util.Locale;
\r
19 import java.util.Map;
\r
21 import com.ibm.icu.text.Collator;
\r
23 public class Language {
\r
25 static final Map<String, Language> symbolToLangauge = new LinkedHashMap<String, Language>();
\r
27 final String symbol;
\r
28 final Locale locale;
\r
30 private Collator collator;
\r
32 public Language(final Locale locale) {
\r
33 this.symbol = locale.getLanguage();
\r
34 this.locale = locale;
\r
36 symbolToLangauge.put(symbol.toLowerCase(), this);
\r
40 public String toString() {
\r
41 return locale.toString();
\r
44 public String getSymbol() {
\r
48 public synchronized Collator getCollator() {
\r
49 if (collator == null) {
\r
50 this.collator = Collator.getInstance(locale);
\r
51 this.collator.setStrength(Collator.IDENTICAL);
\r
56 public String getDefaultNormalizerRules() {
\r
57 return ":: Any-Latin; :: Lower; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC ;";
\r
59 // ----------------------------------------------------------------
\r
61 public static final Language en = new Language(Locale.ENGLISH);
\r
62 public static final Language fr = new Language(Locale.FRENCH);
\r
63 public static final Language it = new Language(Locale.ITALIAN);
\r
65 public static final Language de = new Language(Locale.GERMAN) {
\r
67 public String getDefaultNormalizerRules() {
\r
68 return ":: Lower; 'ae' > 'ä'; 'oe' > 'ö'; 'ue' > 'ü'; 'ß' > 'ss'; ";
\r
72 // ----------------------------------------------------------------
\r
74 public static synchronized Language lookup(final String symbol) {
\r
75 Language lang = symbolToLangauge.get(symbol.toLowerCase());
\r
77 lang = new Language(new Locale(symbol));
\r