Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect right to left Language in Swift UITest

I am trying to setup my UITests for localisation. Especially for Arabic and any other Right to Left (RTL) language.

In my case I have a swipe(direction: SwipeDirection) function that takes a value of SwipeDirection (.up, .down, .left, .right).

If I now want to delete let's say a cell, I'd just do cell.swipe(.left) and my UITest would delete the cell. Since the UI is flipped on RTL languages this has to change to cell.swipe(.right).

I could not find any way of detecting the current device language, nor it's UILayoutDirection.

I've tried to check for it like this already:

let isLeftToRight = UIView.userInterfaceLayoutDirection(for: UIView().semanticContentAttribute) == .leftToRight

and also

let isLeftToRight = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight

But both of them always returning true, no matter the language. Are there any other ways of checking for the current UILayoutDirection I am not aware of?

Thank you!

like image 492
smnk Avatar asked Dec 07 '25 15:12

smnk


1 Answers

Not exactly that hard to find in the documentation

let locale = NSLocale.autoupdatingCurrent
let lang = locale.languageCode
let direction = NSLocale.characterDirection(forLanguage:lang!)
like image 198
adamfowlerphoto Avatar answered Dec 09 '25 05:12

adamfowlerphoto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!