简体   繁体   中英

Under what conditions does VoiceOver automatically switch language in an iOS app

My phone is set to en_us as system language, and I have added Swedish and French to the VoiceOver rotor languages.

After adding the languages I find that the VoiceOver/Safari combo automatically starts in the appropriate language when browsing web pages where the document contains a language setting.

After examining various non-English AppStore apps that I have installed, one of them triggers an automatic language change in the screen reader when I open it.

I experimented with language and localization settings in a very simple iOS app to see if I can trigger such a switch. The app contains a single view controller with a UILabel, created in the storyboard editor.

I tried to change the value of "Localization native development region" in Info.plist. Swedish is not available on the dropdown in the the graphical editor, so I changed it with "Open as Source Code". This simply reads the Swedish label as if it were English text, that is, no difference from doing nothing.

Then I tried ahbou's solution of editing project.pbxproj, replacing the references to "en" with "sv". I redeployed and with this change, but it makes no difference.

I experimented with adding a second non-English locale, and also with checking and unchecking the "Use base localization" option, but this does not make a difference either.

With all the faffing around, it very briefly did start in Swedish, but after turning the rotor back I was never able to trigger the change again.

It occurred to me that there could be a difference between deploying from Xcode and deploying an IPA, so I tried that, no luck.

I tried seeing if I could trigger a VoiceOver language change in a non-minimal app which does not rely on storyboards and which is localised to both English and Swedish. If I edit the schema prior to deploying through Xcode, setting "Application Language" to Swedish and "Application Region" to Sweden causes VoiceOver to start in Swedish for the app, but only setting the Application language does not.

On looking at the AppStore app I have installed that triggers Swedish speech, it looks like the app might be web content displaying inside a web view. Even if that is the case, the fact that it works suggests that there ought to be some way to trigger an automatic switch in a standard iOS app.

Grateful for any ideas!

---- Edited Wednesday February 6, 2019 ----

I experimented with the accessibilityLanguage setting per Mats's helpful suggestion. Setting the language on the UIApplication does propagate it to all elements in the application. I modified the app delegate as follows:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        application.accessibilityLanguage = "sv"
        return true
    }

Note that the value of isAccessibilityElement is false by default for UIApplication (unlike for the components that users are normally expected to see or interact with). It is not necessary to change it to true in order for the language setting to apply, and I'm not sure what the value of changing it would be as users do not interact with the application directly. I did try setting it to true, which does not appear to make any difference as far as VoiceOver is concerned.

You can change your preferred language by inspecting the Info.plist file (XCode's GUI editor only allows a few languages), once there modify the next property

<key>CFBundleLocalizations</key>
<array>
    <string>sp</string>
</array>

Instead of sp (code for Spanish), use the locale code you want use. I did this and now VoiceOver language is ubiquitous along the app.

You can change the VoiceOver language with the accessibilityLanguage property on any accessibility element. It is documented in the UIAccessibility additions to NSObject .

I think it also affects all sub-elements, so you should only need to set it for your app window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM