Giter Club home page Giter Club logo

localizedswift's Introduction

Localizable: Localize UI Components in a simple and declarative way

Installation

Version License Platform

Pods

pod 'LocalizedSwift'

Swift package manager

From Xcode, select File → Swift Packages → Add Package Dependency → Select your project → Search LocalizedSwift

Usage

It is possible to localize a class that conforms Localizable adding @Localized("YouKey") before the component declaration. UILabel, UIButton and UITextField already conform Localizable.

// In the following example the string for the key "Label.Title" will be searched in the file "Localizable.strings".
@Localized("Label.Title")
@IBOutlet private var label: UILabel!

If the strings are defined in a file different from Localizable.strings set the parameter stringsFileName with the name of the file.

// In the following example the string for the key "Label.Title" will be searched in the file "AFile.strings".
@Localized("Label.Title", stringsFileName: "AFile") 
@IBOutlet private var label: UILabel!

If the .strings file is in a bundle other than .main set the parameter bundle with the bundle where the file is embedded.

// In the following example the string for the key "Label.Title" will be searched in the file "AFile.strings" in the bundle `.anotherBundle`.
@Localized("Label.Title", stringsFileName: "AFile", bundle: .anotherBundle) 
@IBOutlet private var label: UILabel!

Set strings for state

It is possible to set different localized strings for different UIControl.State using the declaration @Localized(.key(, for:), .key(, for:) ..., stringsFileName:, bundle:).

The method .key(:, for: ) is a factory method to instantiate the object that associate a key to a state LocalizedConfiguration.

// In the following example the string for the key "Button.Title" will be set for the normal state and the string for the key "Button.Highlighted.Title" will be set for the highlighted state.
@Localized(.key("Button.Title", for: .normal),
           .key("Button.Highlighted.Title", for: .highlighted))
@IBOutlet private var button: UIButton!

It is possible to set stringsFileName and bundle just like in the examples above.

Info

Made with ❤️ and ☕️ by @MarioIannotta

localizedswift's People

Contributors

marioiannotta avatar

Stargazers

 avatar

Watchers

 avatar

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.