Giter VIP home page Giter VIP logo

Comments (7)

PiXeL16 avatar PiXeL16 commented on June 5, 2024

Hey @gmarm. Thats nice! sure, that would be something that people will like to have I think.
How would you image it it will work in IB? With a couple of checkbox with Uppercased and Capitalized along with the text?

from iblocalizable.

gmarm avatar gmarm commented on June 5, 2024

Yes that's how I initially approached it, however it didn't work.

I tried adding a capitalized and uppercased property to the Localizable protocol and then using their values in the applyLocalizableString(_ localizableString: String?) method to set the text according to their values. This couldn't work however, because Swift does not allow for stored properties in extensions (unless you do it in a hacky way that I really didn't want to go for), therefore I couldn't create functional @IBInspectable properties for capitalized and uppercased in the UI element extensions.

I did manage to make it work in a quick and less elegant way as can be seen here https://github.com/gmarm/IBLocalizable/pull/1, however I'm not happy with result. There are now three @IBInspectable properties (two more than before, for capitalized and uppercase localizable strings) and the consumer can set any one of them. The disadvantage of this is that as mentioned there are three properties and the consumer is supposed to only set one, which is not made clear. Since I wasn't really content with the result, I didn't create a PR for your repo.

I would very much prefer to somehow get it working with an approach similar to the first one. If you have any ideas, lets discuss.

from iblocalizable.

PiXeL16 avatar PiXeL16 commented on June 5, 2024

Yes, like you mention you cant do stored properties in extensions without being hacky.

How about instead of using localizableStringToCapitalize we have boolean properties as capitalized and uppercased defaulting to false and then the applyLocalizableString method will just check those values and modify the localized text accordingly.?

Thats a little better, no?

from iblocalizable.

gmarm avatar gmarm commented on June 5, 2024

As I said, that's what I initially tried, unless I'm missing something you're pointing out.

My main problem was the implementation of

@IBInspectable public var capitalized: Bool {
    // implementation?
}

for example in the UIView's Localizable protocol conformance.

from iblocalizable.

HamzaGhazouani avatar HamzaGhazouani commented on June 5, 2024

@gmarm may be you can try something like that ;)

 @IBInspectable public var uppercased: Bool {
        get {
            return false
        }
        set {
            if newValue == true {
               localizableString = localizableString.uppercaseString
            }
        }
    }

from iblocalizable.

gmarm avatar gmarm commented on June 5, 2024

@HamzaGhazouani Thanks, that's interesting.

Although, is there any guarantee that setting uppercased will get called after setting localizableString? 😕

from iblocalizable.

HamzaGhazouani avatar HamzaGhazouani commented on June 5, 2024

Hi @gmarm, you should be sure that the uppercased is below localizableString in the User Defined Runtime attirbutes. it's not a real solution but a workaround... :/

from iblocalizable.

Related Issues (11)

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.