如何强制"尊重语言方向和QUOT;从RTL到LTR,反之亦然 [英] How to force "Respect Language Direction" from RTL to LTR and vice versa

查看:281
本文介绍了如何强制"尊重语言方向和QUOT;从RTL到LTR,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用自动布局的应用程序。

I have an application which uses Auto Layouts.

该应用程序切换RTL和LTR语言完美,当用户选择他或她的设备手机语言。所有的文本本地化和语言方向工作。

The app switches RTL and LTR languages perfectly when the user selects he's or her's device phone language. All texts are localized, and language directions are working.

我也有在应用程序中的一个按钮,改变它的语言而无需重新启动应用程序。
这也伟大工程,所有文本都被替换。

I also have a button inside the app, to change it's language without restarting the app. This also works great, and all texts are being replaced.

问题是,当用户从应用程序内改变的语言,在限制尊重语言方向选项,我有pre定义具有讽刺意味的​​是不尊重。

The problem is that when the user changes the language from within the app, "Respect Language Direction" option in the constraints i have pre-defined is ironically not respected.

任何想法?

推荐答案

最后,我设法解决这个问题。

Eventually, I have managed to solve this issue.

我无法找到一个方法来强制改变RTL - LTR汽车布局限制,所以我决定复制为每种语言方向的2个额外的故事板。
所以,其实我的应用程序现在包含3情节串连图板 - Main.storyboard,StoryboardRTL.storyboard和StoryboardLTR.storyboard

I couldn't find a way to force the change the RTL - LTR auto layout constraints, so i have decided to duplicate 2 additional storyboards for each language direction. So, actually my app now contains 3 storyboards - Main.storyboard, StoryboardRTL.storyboard and StoryboardLTR.storyboard.

当它从设置上的iDevice执行主处理语言方向的变化,和RTL / LTR是有它自己的定位,以支持从应用程序内改变应用程序的语言。

Main handles changes in language direction when it is performed from the settings on the iDevice, and RTL / LTR is has it's own orientation, to support changing the app language from inside the app.

当用户选择更改为一个RTL语言,我设置所选择的语言中UserDefaults:

When the user selects to change to an RTL language, I set the selected language in the UserDefaults:

    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"he", nil] forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];

和右后我叫我写在AppDelegate中,根据语言布局,改变了故事板。方法

and right after i call a method i have written in the AppDelegate, which changes the storyboard according to the language layout.

- (void)reloadStoryboard
{
    UIStoryboard *storyboard;

    switch ([AALanguageManager getCurrentLanguage]) {

        case CurrentLanguageRTL:
            storyboard = [UIStoryboard storyboardWithName:@"StoryboardRTL" bundle:[NSBundle mainBundle]];
            break;
        default:
            storyboard = [UIStoryboard storyboardWithName:@"StoryboardLTR" bundle:[NSBundle mainBundle]];
            break;
    }

    self.window.rootViewController = [storyboard instantiateInitialViewController];
    [self.window makeKeyAndVisible];
}

这看起来好像重新启动应用程序的用户,并显示与RTL / LTR布局适当的故事板。
当用户再次重新启动应用程序,选择的语言会根据选择的语言已经设置,并显示在主故事板,所有的布局是否正确。

This looks to the user as if the app restarted, and display the proper storyboard with the RTL / LTR layout. When the user restarts the app again, the selected language is already set, and the main storyboard is displayed, with all the correct layout according to selected language.

这篇关于如何强制"尊重语言方向和QUOT;从RTL到LTR,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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