Domanda

I need to know what language(s) is spoken in a given CLPlacemark. Any idea?

È stato utile?

Soluzione 2

I've ended up with the following, 100% automatic solution, and you don't need to collect any ISO code at all.

+ (NSString*)detectBestLanguageBCP47:(CLPlacemark *)placemark {

    NSString * countryCode = placemark.ISOcountryCode;

    for (AVSpeechSynthesisVoice *voice in AVSpeechSynthesisVoice.speechVoices) {

        NSString *langCode = [voice.language substringWithRange:NSMakeRange(0, 2)];
        NSString *cc = [voice.language substringWithRange:NSMakeRange(3, 2)];

        int c = [cc compare:countryCode];

        if (c==0) {
             NSString *bcp47 =[ NSString stringWithFormat:@"%@-%@", langCode, cc];

            return bcp47;
        }

    }

    return nil; // Not found
}

Altri suggerimenti

you can get the country from the place mark and use its primary language -- it isn't a 100% solution but i n 90% of the cases it should work

NSString *countryIso = [self countryIsoFromPlacemark:placemark]; 
NSString *languageIso = [self languageIsoFroPrimaryLanguageOfCountry:countryIso];

put a plist of the iso code mappings in your app and you're done

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top