I am developing an OSX app with very minimum UI. For internalization/localization, I used a 3rd party library to replace all my text with appropriate language (I detect the language using [NSLocale preferredLanguages]). The problem is my NSAlert always displays its content (including text, button layout...) in Left-to-Right direction, even when I switch the system language to, says, Arabic.
From my research it would seem that NSAlert should automatically switch the direction correctly (though no where it is explicitly said so). I also check this
NSUserInterfaceLayoutDirection direction = [NSApplication sharedApplication].userInterfaceLayoutDirection;
To support Arabic an empty ar-001.lproj folder in the Resources folder inside the app will do.
If you don't want to add folders for each language, you can force right to left writing direction by calling
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"AppleTextDirection"]; [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"NSForceRightToLeftWritingDirection"];
and to switch back to left to right
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleTextDirection"]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NSForceRightToLeftWritingDirection"];