LanguageSwitcher icon indicating copy to clipboard operation
LanguageSwitcher copied to clipboard

RTL layouts

Open bluemix opened this issue 7 years ago • 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.

bluemix avatar Apr 25 '17 12:04 bluemix

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

radianttap avatar Apr 27 '17 11:04 radianttap

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.

radianttap avatar Apr 27 '17 19:04 radianttap

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.

FadyAckad avatar Sep 12 '17 18:09 FadyAckad

Thanks, I'll have to try that

radianttap avatar Sep 14 '17 10:09 radianttap

@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)
}

mushthak avatar Mar 06 '18 04:03 mushthak