Git Product home page Git Product logo

onlinel10n's Introduction

OnlineL10n - an online localization library written in Swift

The OnlineL10n library uses data binding technologies to bind interface elements to localization variables. All you have to do is implement a simple language provider protocol and bind your interface elements by key. When languages are switched, the databinding mechanism automatically switches all text elements.

If you need an example, simply clone the library and run the application in simulator. An example language switching interface is part of the library and can be included via storyboard reference.

Data binding is implemented using ReactiveObjC library. So even if you don't need online localization, at least you have a miniature example for how to use data binding with ReactiveObjC ๐Ÿ˜‰

Installation

The recommended approach for installing OnlineL10n is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Change to the directory of your Xcode project, and Create and Edit your Podfile and add RestKit:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :ios, '8.0'

pod 'OnlineL10n'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Examples

You might want to implement a shared LocalizationManager like this:

import OnlineL10n

class SharedManager {
    static let sharedInstance = LocalizationManager(languageProvider: UILanguageProvider(), defaultLanguage: "de", language: "de")

    private init() {}
}

And provide your own class implementing the LanguageProvider protocol, like the UILanguageProvider in the example below:

import OnlineL10n

class UILanguageProvider: LanguageProvider {
	// get languages
    func languages() -> [String] {
        return ["de", "en"]
    }

    // get all language keys for one specified language
    func languageKeys(language: String) -> [String : String] {
        if language == "de" {
            return ["top_label" : "Top Label Text auf Deutsch", "button" : "Ein Knopf"]
        } else {
            return ["top_label" : "Top label text in English", "button" : "A button"]
        }
    }

    // check for one specified language
    func has(language: String) -> Bool {
        return language == "de" || language == "en"
    }

    // do we provide flags for countries?
    func hasFlags() -> Bool {
        return true
    }

    // provide a flag for a country/language
    func flag(language: String) -> Data? {
        if (language == "de") {
            return UIImagePNGRepresentation(UIImage(named: "Germany")!)
        } else {
            return UIImagePNGRepresentation(UIImage(named: "England")!)
        }
    }
}

Bind your interface elements like this:

// bind to language keys
self.labelTop.subscribeToLanguage(self, manager: SharedManager.sharedInstance, key: "top_label")

Credits

Example flag icons taken from icondrawer.

License :

The code is available as github project under MIT licence.

onlinel10n's People

Contributors

swesteme 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.