Locale / Identifier during test on device show always the same

  1. 5 weeks ago

    Christian J

    Feb 18 Pre-Release Testers

    Hello Community,

    I am testing an iOS app on a iPhone SE (iOS 12.1.2). I am using Xojo 2018r4 on macOS 10.14.3.

    The goal is to show text of labels in the proper language.

    I am using the following code to determine the language and the region.

    Dim buttons() As Text
    buttons.Append("Yes")
    buttons.Append("No")
    
    dim wobinich as Xojo.Core.Locale
    wobinich = Xojo.Core.Locale.Current
    Lang = wobinich.Identifier
    
    MessageBox1.Buttons = buttons
    MessageBox1.Message = Lang
    
    MessageBox1.Show

    In my test

    • I switch in the iOS settings to different languages (German, Englisch, French). The region is always Germany
    • confirm the new language
    • The system is switching to the new language
    • Press Home Button
    • Open my App
    • Press the button with MessageBox1.Message

    The result in "Lang" is always en_DE.

    I have placed this code in the Event Handlers "Activate" and "Open". It makes no difference to the result.
    I have restarted the iPhone SE several times. No change.

    Do I have an error in the code or placed it in the wrong location?

    Best regards

    Update.

    It seems to be a bug. iOS 10.3.1 show the correct value for the language. iOS 12.1.2 and 12.1.4 does not (thanks to Paul for his help).
    I have created Feedback case 54977.

    As a workaround I use only the region to define the language of the labels and the buttons.

    E.G.

    ...
    dim tmptext(-1) As Text
    tmptext = Lang.Split("_")
    
    MessageBox1.Buttons = buttons
    
    'tmptext(0) contain the value for the language
    'tmptext(1) contain the value for the region
    If tmptext(1) = "DE" Then 
    MessageBox1.Message = "Sprache DE gefunden " + tmptext(1) 
    Else
    MessageBox1.Message = "Sprache DE nicht gefunden "
    End If
    
    MessageBox1.Show
    ...
  2. @ChristianJeannot — Are you sure your app was not still running from a previous test? If you launched it before setting the new language, you should force-quit it before.

  3. Jeremie L

    Feb 18 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 5 weeks ago

    Hi Christian,

    Adding a language in your iPhone settings might not be enough. You need to make sure the selected language is at the top in the list of preferred languages.

    Stéphane is correct, you need to close the app then re-open it to make sure the language is correctly switched.

    Minimal setup

    To show text of labels in the correct language this is what I highly recommend:

    1. Xojo Navigator (on the left) > Build Settings > Shared > Inspector (on the right) > Language > Set it to English

    2. All Text displayed to the user should be stored in Text constants, activate the Dynamic switch. Then write each constant's translation for each language, and the Default value in English.

    -image-

    3. Selection of language will then be automatic based on the users iPhone / iPad. The default language will be English for all locales that aren't translated (Chinese people will see the app in English for example).

    Advanced setup

    If you need your app users to be able to change the language of the app it is possible in two ways.

    1. Store the language code the user chooses in a persistant storage (database, nsuserdefaults, text file...)

    2. Refer to each Text constant as constantName(langcode) forcing the selected langcode to be displayed.

    Advantage
    This solution enables the user to switch language without closing the app. You will need to build the appropriate UI for the user to select a language.
    Drawback
    Absolutely each text constant must be used with the language code as parameter. This is prone to error.

    OR

    1. Store the language code the user chooses with the following code (needs iOSKit by Jason King)

    Dim Str As New Foundation.NSString(langcode)
    Dim obj() As Foundation.NSObject
    obj.Append Str
    
    Dim arr As New Foundation.NSArray(obj)
    
    Foundation.NSUserDefaults.StandardUserDefaults.SetObjectForKey(arr, "AppleLanguages")
    Call Foundation.NSUserDefaults.StandardUserDefaults.Synchronize

    2. Refer to each Text constant as constantName. No need to refer to the selected language code.

    Advantage
    This solution is easier for the developer because you refer to each constant as constantName. You will also need to build the appropriate UI for the user to change language.
    Drawback
    You need to inform the user to close the app and re-open it to apply change of language.

  4. Christian J

    Feb 18 Pre-Release Testers

    @Stephane
    I thought that it is not allowed to quit an App, only to use the Home Button.
    I had also removed the app from the device and installed it new.
    I will test the forced quit.

    @Jeremie
    The wanted language was on top and also I deleted the other language so that only the one remained I wanted to test.
    I will test the Minimal Setup. What I have seen so far is that I have not the scope global. Only public, protected and private.

  5. @ChristianJeannot — I do not know about quitting an app being allowed or not... just that it is useful sometimes that the end-user can do it

  6. Jeremie L

    Feb 18 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io

    The global scope is because I place language constants in a module.
    If you place them in a class or an iOSView, the possible scopes will be public, protected and private.

  7. Christian J

    Feb 18 Pre-Release Testers

    I have continuing testing with closing my app properly. I used the procedure described by Apple to close my app.

    There is only one language (German) configured in the settings of the iPhone SE.
    The region is set to Germany.

    Expected result: de_DE
    Result: en_DE

    From my understanding the code above should work as it is described in the Xojo documentation and used in other posts in the forum here.

    Has someone running a properly detection of language and region with Xojo 2018r4 and iOS 12.1.2?

  8. Christian J

    Feb 20 Pre-Release Testers

    Update.

    I made some more tests.

    The region is properly recognized. Only the language is not recognized properly. It is always "en".

  9. Christian J

    Feb 21 Pre-Release Testers Answer

    Update.

    It seems to be a bug. iOS 10.3.1 show the correct value for the language. iOS 12.1.2 and 12.1.4 does not (thanks to Paul for his help).
    I have created Feedback case 54977.

    As a workaround I use only the region to define the language of the labels and the buttons.

    E.G.

    ...
    dim tmptext(-1) As Text
    tmptext = Lang.Split("_")
    
    MessageBox1.Buttons = buttons
    
    'tmptext(0) contain the value for the language
    'tmptext(1) contain the value for the region
    If tmptext(1) = "DE" Then 
    MessageBox1.Message = "Sprache DE gefunden " + tmptext(1) 
    Else
    MessageBox1.Message = "Sprache DE nicht gefunden "
    End If
    
    MessageBox1.Show
    ...
  10. Jeremie L

    Feb 21 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 5 weeks ago

    Using the region to define language is not a good idea.
    From my user base 20-30% of users have a different language than preferred language for country.

    And what about a region like Austria AT or Belgium BE?
    Will those be set respectfully to German and French / Dutch?

  11. Christian J

    Feb 21 Pre-Release Testers

    @Jeremie L
    I understand your point. I will think about a language switch in the app.

or Sign Up to reply!