This is something that screen reader users who are proficient in more that one language almost always need to change manually when they want to use an app that is not localised to the device's system locale.
However, it doesn't seem to be impossible to configure apps to trigger VoiceOver to switch language automatically. When using VoiceOver with Safari, it switches to the language specified in the document.
I decided to investigate what programmers need to do to in order to make the screen reader switch language automatically in an app. In fact, I was on the verge of promising to do so in my previous post about manually changing the language that VoiceOver uses. Luckily I came to my senses and remembered that I should never assume that I can perform a housekeeping task in Xcode, no matter how normal and straightforward I think the task should be. After a lot of experimentation and some helpful suggestions, I have finally found a solution, so here goes.
There is a setting called Localization native development region in Info.plist but the graphical editor has a short list of languages. You can change it to another language if you switch to the source editor, but it does not take effect in the project settings. So after changing Info.plist, you need to edit the project file as well:
- Close the project in Xcode and open the file project.pbxproj in an external editor.
- Search the file for properties called developmentRegion and knownRegions. Replace "en" with the actual locale.
The changes will be reflected on the project's info panel. Attempting to achieve the same result from the Xcode graphic editor does not seem to completely get rid of English in the settings above.
Now we've told the app what its locale is, and that it only has one known locale. Or? Frustratingly, though it seems highly plausible that the locale used to display strings in the app correlates with the desired VoiceOver language, it has no effect on what VoiceOver thinks it should do. It doesn't matter what you do with the project localization settings, having a base language or not - I tried. Short of providing support for the system locale, the correct language does not get picked.
After asking for help on stack overflow I got a tip from the user Mats which led to a solution: setting the accessibilityLanguage in code in the application. Modify didFinishLaunchingWithOptions with the following addition:
This finally triggers the screen reader to read the accessible elements in the app in the selected language.
Note that anybody who has written an accessible application should set the accessibilityLanguage, whether the app is localised or not, as you could have users who whose device's system locale is one that you do not support. For localised applications, you will need to detect which locale was used and match the accessibilityLanguage to that one.
Now we've told the app what its locale is, and that it only has one known locale. Or? Frustratingly, though it seems highly plausible that the locale used to display strings in the app correlates with the desired VoiceOver language, it has no effect on what VoiceOver thinks it should do. It doesn't matter what you do with the project localization settings, having a base language or not - I tried. Short of providing support for the system locale, the correct language does not get picked.
After asking for help on stack overflow I got a tip from the user Mats which led to a solution: setting the accessibilityLanguage in code in the application. Modify didFinishLaunchingWithOptions with the following addition:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Insert your application's locale
application.accessibilityLanguage = "sv"
return true
}
This finally triggers the screen reader to read the accessible elements in the app in the selected language.
Note that anybody who has written an accessible application should set the accessibilityLanguage, whether the app is localised or not, as you could have users who whose device's system locale is one that you do not support. For localised applications, you will need to detect which locale was used and match the accessibilityLanguage to that one.
No comments:
Post a Comment