GithubHelp home page GithubHelp logo

isabella232 / brlocalizable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blue-rocket/brlocalizable

0.0 0.0 0.0 129 KB

Simple localization toolkit for UIKit.

License: Apache License 2.0

Ruby 0.68% Objective-C 97.31% Shell 2.01%

brlocalizable's Introduction

BRLocalize

BRLocalize provides a way to store localized strings in a hierarchical JSON file and then have placeholder strings in NIB files automatically replaced by their localized value.

Here's an example JSON strings file, strings.json:

{
	"login" : {
		"title" : "Sign in"
	}
}

Now you can localize that just like any other file (i.e. move to a XX.lproj directory and include the localized varients of the JSON in your application.

Programmatic localization

You can localize stuff via code if you like. For example you might want to set a login view controller's title to login.title, like this:

- (void)viewDidLoad {
	[super viewDidLoad];
	[self localizeWithAppStrings:[NSBundle appStrings]];
}

- (void)localizeWithAppStrings:(NSDictionary *)strings {
	self.navigationItem.title = [strings stringForKeyPath:@"login.title"];
}

The appStrings method is provided as an extension on NSBundle, and stringForKeyPath: is provided as an extension on NSDictionary.

Automagical localization

BRLocalize provides some hooks into UI-related code to make the process of applying localized strings a bit easier for you. The hooks rely on the BRLocalizable protocol:

@protocol BRLocalizable <NSObject>

/**
Localize the receiver with a given dictionary of strings.

@param strings The strings data, typically loaded via the application's standard JSON strings file.
*/
- (void)localizeWithAppStrings:(NSDictionary *)strings;

@end

There are two main hooks provided:

  1. awakeFromNib - any object that conforms to BRLocalizable will have localizeWithAppStrings: called when awakeFromNib is invoked.
  2. willMoveToWindow: - any UIView class that conforms to BRLocalizable will have localizeWithAppStrings: called when willMoveToWindow: is invoked.

Building on those hooks, BRLocalize provides category-based implementations of the following classes so they conform to BRLocalizable:

  1. UIBarButtonItem
  2. UIButton
  3. UILabel
  4. UINavigationItem
  5. UISegmentedControl
  6. UITextField

All of these make use of a localizedStringWithAppStrings: method provided on NSString, which looks for strings in the form {some.key.path} and replaces that with a the value found at some.key.path in the JSON strings file.

brlocalizable's People

Contributors

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