我的OSX应用无法检测RTL语言 [英] My OSX app cannot detect RTL language

查看:93
本文介绍了我的OSX应用无法检测RTL语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发具有最低UI的OSX应用程序.为了进行内部化/本地化,我使用了第3方库将所有文本替换为适当的语言(我使用[NSLocale preferredLanguages]检测到该语言).问题是,即使我将系统语言切换为阿拉伯语,我的NSAlert也会始终从左向右显示其内容(包括文本,按钮布局...).

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.

从我的研究看来,NSAlert应该自动正确切换方向(尽管没有明确说明).我也检查

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;

direction始终(即使在系统语言设置为阿拉伯语的情况下)也等于 NSUserInterfaceLayoutDirection::NSUserInterfaceLayoutDirectionLeftToRight.我怀疑这是问题所在,但不太了解如何解决.

and direction would always (even in the case of system language being set to Arabic), equal to NSUserInterfaceLayoutDirection::NSUserInterfaceLayoutDirectionLeftToRight. I suspect this is the problem, but don't quite know how to address this.

任何人都知道如何:

  • 确定NSApplication知道正确的布局方向吗?

  • 确定NSAlert的显示方向正确(尤其是RLF语言)?

注意:

  • I look at this question, NSAlert for right to left languages (reversed layout), but the answer is not helpful at all for me.

我也在这里查看此指南:

I also look at this guide here:

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/Introduction/Introduction.html#//apple_ref/doc/uid/10000171i-CH1-SW1

仍然没有帮助,因为为了增加对语言的支持,本指南似乎要求我具有xib或情节提要文件.我的项目恰好没有这两个.

and it still does not help, because in order to add support for languages, it looks like this guide requires that I have xib or a storyboard file. My project happens to not have either of these.

谢谢大家.

推荐答案

要支持阿拉伯语,可以在应用程序内Resources文件夹中使用一个空的ar-001.lproj文件夹.

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"];

并切换回从左到右

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleTextDirection"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NSForceRightToLeftWritingDirection"];

这篇关于我的OSX应用无法检测RTL语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆