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]

molh's People

Contributors

abdallahnh avatar ahmedk92 avatar basantashraf avatar dark2torch avatar dependabot[bot] avatar deya-eldeen avatar diyaa-hamza avatar moathothman avatar moathothman89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

molh's Issues

Issue in Swift4

When we change current Language to another language (english to arabic), it works fine . but now when we change language to previous one.(arabic to english) Its not working fine. UIApplication.isRTL() is false first time, when we change language , UIApplication.isRTL() is now true. but now when we change no matter in which language UIApplication.isRTL() is always true. but when we quit app and start it will change value give false and all wil work good. Can you please update it for Swift 4 or provide me the solution ?

App is lagging after language change

Hii , thanks for your great work.

I got a performance issue with the pushing of new viewcontrollers after switching the langugaes. The pushing seems to be laggy. I have tried to use the main thread, but the issue is still there. Any solution for this??

The "fr" language is not a RTL language

Hi,
In your class MOLHLanguage, the RTL language array contains the "fr" language, you should remove it, as you know the fr isn't a RTL language,

Best Regards.

RTL Design

Is it okay to use .forceRightToLeft for right to left language instead of localize the app ??

UIButton action not appear

After downloading your awesome pod I faced problem where I can't add Action connection for button from storyboard I get only outlet and collection outlet connections , But After searching I get the error is that in MOLHFontLocalizableViews.swift file you conforms MOLHFontable protocol and after delete conform of protocol the action connect return again , so please check this issue.
Thanks

Language of UIActivityViewController Does not change when Reset

When Change Language from english to Arabic Or reverse UIAlertViewController does not localized unless i restart the app please i need fix i faced this issue and tried alot but can not find solution.

`let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)

    if let avc = activityViewController.popoverPresentationController {
        avc.sourceView = sView
    }
    sender.present(activityViewController, animated: true, completion: nil)`

Image from iOS (1)
Image from iOS

some subviews didn't flip

i have in my view a navigation view ... mostly on all pages ..
strangely some of these navigation views didn't flip when change language when most of them did flip .. why?

Theres 13 issues in the library

Hi,
Thank you so much for this amazing library ...
i want to use it in my project but i got 13 issues in the library...

screen shot 2018-05-28 at 10 31 28 am

would you please solve them?

thanks! :)

Kurdish language corrupted text

I tried to use the Kurdish language ckb-IQ in my app and when I switch to this language some characters are not connected to each other, and when I used ku it is connected, so after doing some debugs and when I added ku to the iSRTLLanguage() it behave same as ckb-IQ so I guess when we forceRightToLeft for Kurdish language it is corrupting the text.

First, I thought it was an Xcode issue so I created this StackOverflow question

https://stackoverflow.com/questions/59967897/xcode-kurdish-localization-issue

layoutsubview instead of swizzling

we may override layoutsubviews in the extensions instead of swizzling ,

AC
Try that out and if it does not break things , consider using it.
we need yet to make it optional as with swizzling.

issues

  • textField placeholder stop showing

uibarbutton item, support

form medium :

Really it helped localize my app beautyfully but the issue isthat system inbuilt classes like Bar Button Item,UIPrinter Window the text language in that only changes when app is relaunced like if change language to spanish then also the inbuilt classes language will be english but if we launch app again then it will chage to spanish. Any solution for that will be great.

Tableview and collection view not updated when language changed

I have view controller with tableview and collectionview included so in cellForItemfor indexpath I grabbed out the item and use property observer to fill in cell components

var store: Store? {
didSet {
storeNameLbl.text = store?.name.localized
if let url = store?.logoURL {
storeImage.contentMode = .scaleAspectFill
storeImage.sd_imageIndicator = SDWebImageActivityIndicator.grayLarge
storeImage.sd_imageIndicator?.startAnimatingIndicator()
storeImage.sd_setImage(with: url)
}
}
}
in func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.store = self.stores[indexPath.row]
}

so all things changes correctly except tableview cells labels and collectionview labels

App Getting Crashed for iOS 13

The app is getting crashed on .reset() function. You are using delegate.window there but "window" has been moved to SceneDelegate in iOS 13.
UIView.transition(with: ((delegate.window)!)!, duration: 0.5, options: transition, animations: {}) { (f) in }

So, I tried to change it to sceneDelegate.window but it is still getting crashed.

Here is the screenshot for your reference: https://imgur.com/ZuPr4RW

Any workaround for now? Please let me know.

Regards,

Supporting Swift 4

So far, it works in conjunction of letting the "Swift Language Version" to be 3.2 even with Swift 4 projects, otherwise I will start seeing compile errors in many library files. However, shall we migrate it to support Swift 4?

Prevent UIStackView from flipping

I tried using the maximumLocalizableTag option for stackview, and it never worked, I can't prevent it from flipping, i also looked up MOLH and didn't see any integration with stackviews, How can i prevent MOLH from flipping a stackview ? not even setting semanticContentAttribute works.

RTL and LTR is not working with TabbarController.

Hey moath

Thanks for your awesome library :)

My Project have slide menu and tabbar controller. So My app rootviewcontroller is slide menu and that side menu have center and left view controller.

So when I am trying to change language from app then side menu left and center viewcontroller's alignment is not working. All other viewcontroller's alignment is working fine.

When I relaunch app then left and center viewcontroller's alignment is working fine. but its not working when I call reset function from app.

I thinks that view's are not updating.

Please help me.

Thanks,
Ekta

need to restart to see language change

i have used your library and its working just awesome!
but my problem is that i need to restart to see the language change .. how to to see language change without a restart just like your demo?

select collection cell or tableview cell

I have problem when i active swizzling by this line

MOLH.shared.activate(true)

with some collection view or table view selection give me this error

2018-05-17 12:48:19.391146+0200 TestApp[3370:61813] -[UIButton _tvUpdateContentBackdropView]: unrecognized selector sent to instance 0x7f9993f36460
2018-05-17 12:48:19.409001+0200 TestApp[3370:61813] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton _tvUpdateContentBackdropView]: unrecognized selector sent to instance 0x7f9993f36460'
*** First throw call stack:
(
0 CoreFoundation 0x000000010957f12b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000108c13f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000109600024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010ad20f51 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x0000000109501f78 forwarding + 1432
5 CoreFoundation 0x0000000109501958 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010b81be88 -[UITextField layoutSubviews] + 264
7 MOLH 0x00000001084ef881 _T0So9UIControlC4MOLHE18cstmlayoutSubviewsyyF + 33
8 MOLH 0x00000001084ef8c4 _T0So9UIControlC4MOLHE18cstmlayoutSubviewsyyFTo + 36
9 UIKit 0x000000010af7d81c -[UINib instantiateWithOwner:options:] + 2425
10 UIKit 0x000000010ac943ff -[UIViewController _loadViewFromNibNamed:bundle:] + 383
11 UIKit 0x000000010ac94d2b -[UIViewController loadView] + 177
12 UIKit 0x000000010ac9505c -[UIViewController loadViewIfRequired] + 195
13 UIKit 0x000000010ac958b9 -[UIViewController view] + 27
14 UIKit 0x000000010acc794a -[UINavigationController _startCustomTransition:] + 954
15 UIKit 0x000000010acde3b4 -[UINavigationController _startDeferredTransitionIfNeeded:] + 686
16 UIKit 0x000000010acdf6d3 -[UINavigationController __viewWillLayoutSubviews] + 150
17 UIKit 0x000000010af3a4e2 -[UILayoutContainerView layoutSubviews] + 231
18 UIKit 0x000000010abbea6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439
19 QuartzCore 0x000000010a92761c -[CALayer layoutSublayers] + 159
20 QuartzCore 0x000000010a92b7ad _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
21 QuartzCore 0x000000010a8b286c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 364
22 QuartzCore 0x000000010a8df946 _ZN2CA11Transaction6commitEv + 500
23 QuartzCore 0x000000010a8e0694 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
24 CoreFoundation 0x0000000109521c07 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
25 CoreFoundation 0x0000000109521b5e __CFRunLoopDoObservers + 430
26 CoreFoundation 0x0000000109506124 __CFRunLoopRun + 1572
27 CoreFoundation 0x0000000109505889 CFRunLoopRunSpecific + 409
28 GraphicsServices 0x00000001121059c6 GSEventRunModal + 62
29 UIKit 0x000000010aaed5d6 UIApplicationMain + 159
30 Aoun 0x0000000107d8c247 main + 55
31 libdyld.dylib 0x000000010ea51d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

but with menu tableView not get this error

and when i comment this line in active method
swizzle(class:UIControl.self, sel: #selector(UIControl.awakeFromNib), override: #selector(UIControl.cstmlayoutSubviews))

the problem was solving , but what will happen when this line is still commented ?

UnFlip a UIView

While switching the language to Arabic, I need a specific UIView and the UIControls inside it not to be flipped. I had tried setting the tag as -1. But it didn't worked. How to make it out?

Arabic is always the defaults language

Hi,
could you help me, what is the best way to define Arabic as the default language?

I did this in App delegate
MOLH.shared.activate(true)
MOLH.setLanguageTo("ar")
MOLH.reset()

but the problem with the TextView is not RTL, I have justified and centre text attributed alignment

I need to restart the app to see the correct alignment

adding an option to change animation when changing language

Hello, some people asked me to change the animation transition when switching language....

I managed to make it as easy as
MOLH.resetWithCrossDissolve()

please make this a feature available for all :) , thanks.

the simplest way is to extend MOLH with a new reset function.... and call it
MOLH.resetWithCrossDissolve()
for example

extension MOLH {
    open class func resetWithCrossDissolve() {
        let transition = UIViewAnimationOptions.transitionCrossDissolve
        if let delegate = UIApplication.shared.delegate {
            if delegate is MOLHResetable {
                (delegate as!MOLHResetable).reset()
            }
            UIView.transition(with: ((delegate.window)!)!, duration: 0.5, options: transition, animations: {}) { (f) in
            }
        }
    }
}

Language Change Design not working

I have applied the language reset option. But the language change not applied exactly as needed. Change the language using set language option, and the design applied only when i close the app & reopen the app. Also some times Arabic to English change some layout changing from LTR to RTL. But the language text not updated.Keep the same language text.

Label inside the Tableview cell not aligned the correct language Direction. It affect only after restart the app.

Images is not mirrored in first view controller in navigation

Hi @MoathOthman, firstly thanks for this great library,
There is a problem in the pod example, when change language to be arabic, image view in first ViewController not mirrored, if we set image view with tag = -1 in second view controller works fine, I see that if controller in navigation controller so it will loop on subviews in a navigation controller rather than a controller, I modified mirroringviewDidLoad method to handle.
This is my code:

@objc func mirroringviewDidLoad() {
        mirroringviewDidLoad()
        if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft {
            if self is UINavigationController {
                if let viewController = (self as! UINavigationController).viewControllers.first {
                    loopThroughSubViewAndFlipTheImageIfItsNeeded(viewController.view.subviews)
                }
            } else {
                loopThroughSubViewAndFlipTheImageIfItsNeeded(self.view.subviews)
            }
        }
        // Do any additional setup after loading the view.
    }

Font Isuus

Hi

I would like to ask about MOLHFontLocalizableViews, how the library deals with two font localization.
is it possible to change the font type as the language of the app change from Arabic to English, keeping the same labels,textFiled..etc text size?

thanks in advance

set Default Language to Arabic not working right on first run

on didFinishLaunchingWithOptions

       MOLH.reset()
       MOLHLanguage.setDefaultLanguage("ar")
       MOLH.shared.activate(true)

UITextField, UITextView, UINavigationController's swipe gesture for back are not flipped right on the first run.
and I did uncheck 'Respect language direction' in one or two places in storyboard, but it was flipped to left as if I didn't uncheck this option.

I tried to change semanticContentAttribute, but it didn't work either :

UITextField.appearance().semanticContentAttribute = .forceRightToLeft
UINavigationBar.appearance().semanticContentAttribute = .forceRightToLeft
UITextView.appearance().semanticContentAttribute = .forceRightToLeft

is that normal on first run? any thoughts on it?

@MoathOthman

Language Not Change

I use google map and dates and my app when change language my address not change to selected language and also date..
but when restart app its work why ??

images flip even I forced it to LTR

Hello,
I have a problem when changing the language to Arabic at runtime without re-opening the app.
The two images inside UIStackView

Thanks

This is before changing the language:
en

This after changing the language to Arabic:
ar

how to set language

i have two buttons arabic and english .. when clicked on arabic i want to change language to arabic and same with english ...

so i cannot use MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar" : "en")

i tried MOLH.setLanguageTo("en") but it didn't do anything ... how to do it?

set default language to arabic

Hi there..

is there is a way i can set the default language of my app to Arabic rather than English?

Thanks in advance.

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.