radianttap/LanguageSwitcher

RTL layouts

bluemix opened this issue · 5 comments

Hello,
thanks for the example your provided.

I have this old problem, that I want to switch
the layout direction for RTL languages, e.g., Arabic.

simulator screen shot apr 25 2017 15 01 25

As you can see from the screenshot, the Arabic text is switched, but the direction remains the same.

Leading, trailing constraints should do this automatically. Will see what's going on

This seems out of reach, for now.

Main.storyboard seems to be loaded and rendered using Locale.preferredLanguages.first before any swizzling can take place. I even tried to swizzle that, but no use.

I found a workaround by unloading the main bundle.

Bundle.main.unload()

Not sure if it has any performance drawbacks, but it's working fine for me till now.

Thanks, I'll have to try that

@FadyAckad
Were did you called this method?

Below update did the fix for me:

static func updateLanguage(code: String, regionCode: String? = nil) {

    if(code == "ar"){
        UIView.appearance().semanticContentAttribute = .forceRightToLeft
    }else{
        UIView.appearance().semanticContentAttribute = .forceLeftToRight
    }
    
	enforceLanguage(code: code, regionCode: regionCode)

	//	post notification so the app views can update themselves
	NotificationCenter.default.post(name: NSLocale.currentLocaleDidChangeNotification, object: Locale.current)
}