5

We're working on an app that's localized only in the German language and want to add accessibility feature to it. Since the accessibilityLabels are in German, it would be great to always read it in German, regardless of what the user's default system language is.

I noticed one can set that with the accessibilityLanguage property. But it needs to be set on each control repeatedly.

Is there any way to set the accessibility language once globally for every control in the app?

cookie monster
  • 10,671
  • 4
  • 31
  • 45
zavié
  • 4,301
  • 2
  • 34
  • 46

3 Answers3

6

Just found out a way shortly after posting the question! :)

You can set accessibilityLanguage directly on UIApplication in AppDelegate. For example, in application:didFinishLaunchingWithOptions:,

application.accessibilityLanguage = @"de";

And it will be applied to all the controls. Tested on iOS 7.

zavié
  • 4,301
  • 2
  • 34
  • 46
1

You can do it by inheritance, and use your customised components which by default would have this value set in the way you want. But probably in the existing project it won't be so easy and quick to apply.

Julian
  • 9,299
  • 5
  • 48
  • 65
  • Thanks, but like you said it's an existing app and changing the hierarchy is complicated. Just found out it can be achieved by setting the property on UIApplication! – zavié Jan 22 '14 at 13:19
  • So please post answer for other if you find anything better. Btw some programmes always do some base classes on the cocoa components basis to be eligible to make quick changes like you need now :) – Julian Jan 22 '14 at 13:27
  • Yeah, nice idea! If you then print out the view hierarchy, the views have name too instead of the anonym UIView. – zavié Jan 22 '14 at 13:47
1

You can make a category on NSObject in a header file like this:

@implementation NSObject (Accessibility)

    - (NSString *)accessibilityLanguage {
        return @"de";
    }

@end

Then consider importing it in you prefix header (.pch file) so you don't have to import it everywhere you need it

Mikkel Selsøe
  • 1,171
  • 1
  • 11
  • 23
  • Thanks! In a similar fashion I tried setting it directly on the UIApplication object, which works as well and is less code :) – zavié Jan 22 '14 at 13:20