Skip to content

Support right-to-left languages #55

Description

@MontakOleg

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions