Giter Site home page Giter Site logo

moathothman / molh Goto Github PK

View Code? Open in Web Editor NEW
117.0 11.0 36.0 317 KB

Localization helper for iOS apps mainly focusing on the LTR/RTL issue

License: MIT License

Swift 98.27% Ruby 1.73%
swift localization internationalization language rtl-issue switch-language

molh's Introduction

MOLH

Localization helper for iOS apps mainly focusing on the LTR/RTL issue

Install

Add pod 'MOLH' to your podfile. (check https://cocoapods.org/ for more info about cocoapods)

You can install it through Swift package manager as well.

How To Use

import MOLH

Start

When you start the app

MOLH.shared.activate(true)

Make sure this method is called only once and not on every reset

or

MOLH.shared.activate(false) to not use swizzling and use subclassing from MOLH* UI classes.

To reset the language

MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar" : "en")
MOLH.reset()

Set default

Before .activate set

MOLHLanguage.setDefaultLanguage("ar")

using without swizzling (prefered)

you can choose to not use swizzling MOLH.shared.activate(false) , in that case you subclass MOLH-UI Subclasses , like MOLHTextField , this will give you more controlability as you can by-pass the tag requirement by using forceSwitchingRegardlessOfTag and set it to true.

Images

To make sure an image is flipped when switching to RTL or to LTR, you can use flipIfNeeded() function on image or UIImage().imageFlippedForRightToLeftLayoutDirection()

Fonts

Its better to have the app fonts in one place in your app, e.g. a FontManager. and there you can decide which font to use based on the chosen language, this would be the eaiser way.

Other Frameworks and bundles

Some controls such as ActionSheetDatePicker have locale property so you can set them appropriately e.g.

actionSheetDatePicker?.locale = Locale(identifier: MOLHLanguage.currentLocaleIdentifier())

Common Issues

Collection view content are flipped in a non readable way

use this line to solve it collectionView.semanticContentAttribute = .unspecified Thanks to didats

you may check this post.

uilabel/uitextfield are not reflecting

make sure to set the tag and make sure the .activate method is only called once and not on every reset

Author

Support the library

If you enjoy MOLH and I want to say thank you, you can (buy me a coffee)[https://www.buymeacoffee.com/moathothman]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.