am 8f526c9a
: Use the complete Locale in generating the dictionary id.
* commit '8f526c9a55e0b30f81dcca07dc4f5f4fd341bdb1': Use the complete Locale in generating the dictionary id.
This commit is contained in:
commit
f24e19741f
2 changed files with 20 additions and 25 deletions
|
@ -313,35 +313,12 @@ public class DictionaryInfoUtils {
|
|||
* unique ID to them. This ID is just the name of the language (locale-wise) they
|
||||
* are for, and this method returns this ID.
|
||||
*/
|
||||
public static String getMainDictId(final Locale locale) {
|
||||
public static String getMainDictId(@Nonnull final Locale locale) {
|
||||
// This works because we don't include by default different dictionaries for
|
||||
// different countries. This actually needs to return the id that we would
|
||||
// like to use for word lists included in resources, and the following is okay.
|
||||
return BinaryDictionaryGetter.MAIN_DICTIONARY_CATEGORY +
|
||||
BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + locale.getLanguage().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a main dictionary is readily available for this locale.
|
||||
*
|
||||
* This does not query the content provider.
|
||||
*
|
||||
* @param context context to open files upon
|
||||
* @param locale dictionary locale
|
||||
* @return true if a dictionary is available right away, false otherwise
|
||||
*/
|
||||
public static boolean hasReadilyAvailableMainDictionaryForLocale(final Context context,
|
||||
final Locale locale) {
|
||||
final Resources res = context.getResources();
|
||||
if (0 != getMainDictionaryResourceIdIfAvailableForLocale(res, locale)) {
|
||||
return true;
|
||||
}
|
||||
final String fileName = getCacheFileName(getMainDictId(locale), locale.toString(), context);
|
||||
return new File(fileName).exists();
|
||||
}
|
||||
|
||||
public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file) {
|
||||
return getDictionaryFileHeaderOrNull(file, 0, file.length());
|
||||
BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + locale.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file,
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.res.Resources;
|
|||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.android.inputmethod.latin.common.LocaleUtils;
|
||||
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -44,4 +45,21 @@ public class DictionaryInfoUtilsTests extends AndroidTestCase {
|
|||
sp));
|
||||
assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp));
|
||||
}
|
||||
|
||||
public void testGetMainDictId() {
|
||||
assertEquals("main:en",
|
||||
DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en")));
|
||||
assertEquals("main:en_us",
|
||||
DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en_US")));
|
||||
assertEquals("main:en_gb",
|
||||
DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en_GB")));
|
||||
|
||||
assertEquals("main:es",
|
||||
DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("es")));
|
||||
assertEquals("main:es_us",
|
||||
DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("es_US")));
|
||||
|
||||
assertEquals("main:en_us_posix", DictionaryInfoUtils.getMainDictId(
|
||||
LocaleUtils.constructLocaleFromString("en_US_POSIX")));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue