Current Locale code France crash

I have the following code to find a local 2 letter country code. It works for what I want but crashes when I set the iPad to France. Any suggestions why?
Can you test this in the simulator? or does it always give en_us

Dim country, a As Text 
    country = Locale.Current.Identifier.ToText

    If country.IndexOf("@") > -1 Then
      country = country.Left(country.IndexOf("@"))
    End If

    If country.BeginsWith("zh_CN") or country.BeginsWith("zh-Hans") then
      //Chinese (Simplified)
      MessageBox("Current Languages and Dictionaries Avaliable are, English, French, Portugese and Spanish")
    Elseif country.BeginsWith("zh_TW") or country.BeginsWith("zh-Hant") then
      //Chinese (Traditional)
      MessageBox("Current Languages and Dictionaries Avaliable are, English, French, Portugese and Spanish")
      
    Elseif country.BeginsWith("zh") then
      //Assume it is Chinese (Simplified)
      MessageBox("Current Languages and Dictionaries Avaliable are, English, French, Portugese and Spanish")
      
    Elseif country.IndexOf("_") > -1 then
      country = country.Left(country.IndexOf("_"))
      
      //Identifier will be the language code
      //Note that it isn't necessarly a 2 letter code
      //Example: ko-Kore, ckb-Arab, fur-Latn, ms-Arab, fil, ain
      'MessageOk("Current Languages and Dictionaries set to",identifier ,"")
      
    Elseif country.length = 2 then
      //Identifier is a 2 letter code
      a = "Unknown Language" + country
      MessageBox(a)
      
    Else
      //Raise an exception to treat this special case
      a = "I don't know what country you are in?? Please select a different language."
      MessageBox(a)
      
    End If

    return country

I don’t know if you are aware of this but your function returns the user’s language code, not the country.

Yes, just a bad identifier name, I’m after the language “FR”, “ES”, “EN” or “PT”

I worked out that the simulator always returns “us_en” and when I go to a device the App drops out when I set the language to French. Works fine for Espanol and Portugese

Hi Martin, if I remember correctly, I had to change the time zone settings on my MacBook and only after that the simulator would return that value. Maybe that helps but it’s strange that Spanish & Portuguese works but French does not.

1 Like

I found an encoding problem in the French file :blush: