Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support right-to-left languages #55

Open
MontakOleg opened this issue Nov 19, 2016 · 0 comments
Open

Support right-to-left languages #55

MontakOleg opened this issue Nov 19, 2016 · 0 comments

Comments

@MontakOleg
Copy link
Contributor

I think a little bit about that.
As a basis idea we can take AutoLayout approach:
.leading means .left on left-to-right languages and means .right on right-to-left languages;
.trailing means .right on left-to-right languages and means .left on right-to-left languages.

We can implement this by simple adding factory functions to our enums(Edge, Corner, Align), for example for Edge:

public enum Edge {
    case top
    case left
    case bottom
    case right

    static func leading() -> Edge {
        return isRightToLeft() ? .right : .left
    }

    static func trailing() -> Edge {
        return isRightToLeft() ? .left : .right
    }
}

Then if client code wants to respect language direction, it should use .leading() and .trailing() functions instead .left and .right:

func isRightToLeft() -> Bool {
//    return UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
    return true
}

func bar(edge: Edge) {
    switch edge {
    case .left:
        print("left")
    case .right:
        print("right")
    case .top:
        print("top")
    case .bottom:
        print("bottom")
    }
}

bar(edge: .leading()) // prints 'right'

@mamaral what you think about this approach? Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant