[ios][tts] Fixed non-working pt-BR and es-MX TTS selection in OM

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2023-05-11 09:39:26 +02:00 committed by Alexander Borsuk
parent cef52854d1
commit e1b7de9f08

View file

@ -2,22 +2,22 @@
namespace locale_translator
{
std::string bcp47ToTwineLanguage(NSString const * bcp47LangName)
std::string bcp47ToTwineLanguage(NSString const * bcp47)
{
if (bcp47LangName == nil || [bcp47LangName length] < 2)
if (bcp47 == nil || bcp47.length < 2)
return {};
if ([bcp47LangName isEqualToString:@"zh-CN"] || [bcp47LangName isEqualToString:@"zh-CHS"]
|| [bcp47LangName isEqualToString:@"zh-SG"])
{
return "zh-Hans"; // Chinese simplified
}
// Update this array if new bcp47 languages are added into data/strings/sound.txt
if ([@[@"pt-BR", @"es-MX"] containsObject:bcp47])
return bcp47.UTF8String; // Unchanged original bcp47 string
if ([bcp47LangName hasPrefix:@"zh"])
if ([@[@"zh-CN", @"zh-CHS", @"zh-SG"] containsObject:bcp47])
return "zh-Hans"; // Chinese simplified
if ([bcp47 hasPrefix:@"zh"])
return "zh-Hant"; // Chinese traditional
// Taking two first symbols of a language name. For example ru-RU -> ru
return [bcp47LangName substringToIndex:2].UTF8String;
return [bcp47 substringToIndex:2].UTF8String;
}
} // namespace locale_translator