Test and fix Java to IANA country code mapping.

This commit is contained in:
Reece H. Dunn
2014-10-28 15:33:11 +00:00
parent 6576742917
commit 328f4cfdc9
2 changed files with 16 additions and 3 deletions
@@ -179,6 +179,14 @@ public class SpeechSynthesisTest extends TextToSpeechTestCase
}
}
public void testJavaToIanaCountryCode()
{
for (VoiceData.Voice data : VoiceData.voices)
{
assertThat(SpeechSynthesis.getIanaCountryCode(data.javaCountry), is(data.ianaCountry));
}
}
public void testAddedVoices()
{
getVoices(); // Ensure that the voice data has been populated.
@@ -320,7 +320,7 @@ public class SpeechSynthesis {
final Configuration config = context.getResources().getConfiguration();
final String language = getIanaLanguageCode(locale.getLanguage());
final String country = getIanaLocaleCode(locale.getCountry(), mJavaToIanaCountryCode);
final String country = getIanaCountryCode(locale.getCountry());
config.locale = new Locale(language, country, locale.getVariant());
Resources res = new Resources(context.getAssets(), metrics, config);
@@ -371,6 +371,10 @@ public class SpeechSynthesis {
return getIanaLocaleCode(code, mJavaToIanaLanguageCode);
}
public static String getIanaCountryCode(String code) {
return getIanaLocaleCode(code, mJavaToIanaCountryCode);
}
private static String getIanaLocaleCode(String code, final Map<String, String> javaToIana) {
final String iana = javaToIana.get(code);
if (iana != null) {
@@ -449,12 +453,13 @@ public class SpeechSynthesis {
mJavaToIanaLanguageCode.put("vie", "vi");
mJavaToIanaLanguageCode.put("zho", "zh");
mJavaToIanaCountryCode.put("JAM", "JM");
mJavaToIanaCountryCode.put("MEX", "MX");
mJavaToIanaCountryCode.put("BEL", "BE");
mJavaToIanaCountryCode.put("BRA", "BR");
mJavaToIanaCountryCode.put("FRA", "FR");
mJavaToIanaCountryCode.put("GBR", "GB");
mJavaToIanaCountryCode.put("HKG", "HK");
mJavaToIanaCountryCode.put("JAM", "JM");
mJavaToIanaCountryCode.put("MEX", "MX");
mJavaToIanaCountryCode.put("PRT", "PT");
mJavaToIanaCountryCode.put("USA", "US");
mJavaToIanaCountryCode.put("VNM", "VN");