Skyscanner / SkyFloatingLabelTextField

A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.
Apache License 2.0
4.09k stars 542 forks source link

Text is not set to right while select arabic language from app #109

Closed ibhavin closed 7 years ago

ibhavin commented 7 years ago

I have implemented localization Internally(To change language inside app) in app by using this github repo : ios_language_manager

While changing language from app (Not iPhone language) from English to Arabic it is not changing UITextFiled's placeholder text and value to RTL. But if I change the iPhone language to Arabic then it works perfectly.

Both of the below textfield's text alignment is natural from storyboard. Without text input only placeholder text (Placeholder should come from right side) screen shot 2017-02-21 at 12 36 22 pm

With text input and floating placeholder (Text should come from right side) screen shot 2017-02-21 at 12 36 49 pm

If I change language from iPhone settings then it works perfectly.

Without text input only placeholder text (Perfect) screen shot 2017-02-21 at 12 46 53 pm

With text input and floating placeholder (Perfect) screen shot 2017-02-21 at 12 47 11 pm

bogren commented 7 years ago

As far as I understand ios_language_manager swaps out the bundle files but doesn't set the properties of the language LTR = true. I found this property of UIView semanticcontentattribute. Either you make a pull request the ios_language_manager to make sure the lib can handle LRT languages or as you change language in your app you set the semanticcontentattribute property. I think this works UIView.appearance().semanticContentAttribute = .forceRightToLeft :)

ibhavin commented 7 years ago

@bogren Placeholder change only after I close the app and restart it but other UI displays RTL without restart the app. I have tried UIView.appearance().semanticContentAttribute = .forceRightToLeft when I change to arabic from english but issue is not solved.

bogren commented 7 years ago

Ah okay. I'm looking at some of the previous issues we have reported, I'll try to read up on what is not working with LTR for SkyFloatingLabelTextField. If you find a solution to fix please submit a PR :)

k0nserv commented 7 years ago

I think this might relate to the fact that we explicitly set alignment rather than using natural alignment

Mehrdadmaskull commented 7 years ago

I'm having the same issue too. With or without setting the alignment.

k0nserv commented 7 years ago

Thanks for the PR @Mehrdadmaskull, can you retest against master?

k0nserv commented 7 years ago

The PR from @Mehrdadmaskull is merged and was released as part of 3.1.0. Please try this version

Maryom commented 7 years ago

Hey,

Thanks for this helpful issue. I have a problem: in Main.strings (Arabic) I wrote: "YGo-es-Lf5.placeholder" = "كلمة المرور";

But as you can see in the image below the field didn't change! how can I change it?

Thanks.

screen shot 2017-05-09 at 11 13 25 am
k0nserv commented 7 years ago

@bogren care to comment. I don't exactly remember the details of iOS localization anymore. Make sure the id matches the id of the textfield is all I can think of

shaileshnparkhi commented 5 years ago

Hi all, I am having the same issue , when I change Language from arabic to english or vice versa SkyFloatingLabelTextField is not updating according to LTR or RTL.After restarting the app LTR and RTL is working for SkyFloatingLabelTextField,but when I am changing language, runtime it is not updating.

My xcode version : 10.1 SkyFloatingLabelTextField version : 3.6.0

pranavpari commented 4 years ago

Hi all, I am having the same issue , when I change Language from arabic to english or vice versa SkyFloatingLabelTextField is not updating according to LTR or RTL.After restarting the app LTR and RTL is working for SkyFloatingLabelTextField,but when I am changing language, runtime it is not updating.

My xcode version : 10.1 SkyFloatingLabelTextField version : 3.6.0

Any solution for this?

shalithacodezync commented 3 years ago

This issue Still Exits On the Latest..As a workaround you will have to handle it by own .. i was able to handle this like this We only needed support for arabic language.


import UIKit

import SkyFloatingLabelTextField

class SkyFloatingUITextFeildWithRtl: SkyFloatingLabelTextField  {

    override func layoutSubviews() {
        super.layoutSubviews()
        checkForArabicLanguage()
    }

    private func checkForArabicLanguage(){
        if (ApplicationServiceProvider.shared.isCurrentAppLanguageArabic()){
            isLTRLanguage = false
        }else {
            isLTRLanguage = true
        }

    }

}

Then applied this Custom class as View on Storyboard and Outlet..Done

kishlaykishore1 commented 3 years ago

func textfieldAlingment(_ lang: String){ if lang == "en" { txtNewPassword.textAlignment = .natural txtReenterPassword.textAlignment = .natural } else { txtNewPassword.textAlignment = .right txtReenterPassword.textAlignment = .right } }

call it in View Will Appear override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if UserDefaults.standard.object(forKey: "appLanguage") as? String == "en" { UIView.appearance().semanticContentAttribute = .forceLeftToRight textfieldAlingment("en") }else if UserDefaults.standard.object(forKey: "appLanguage") as? String == "ar" { UIView.appearance().semanticContentAttribute = .forceRightToLeft textfieldAlingment("ar") } }