| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
SPLocalizedString is a library to help iOS developers to localize their apps.
Features:
Features of spgenstrings:
Let's face the truth: genstrings and the key-based NSLocalizedString with comments are not the best tools to localize your apps. Some reasons:
Add SPLocalizedString to your Podfile:
platform :ios, "6.0" pod 'SPLocalizedString'
Run the following command:
pod install
Static Library
Clone the project or add it as a submodule. Drag SPLocalizedString.xcodeproj to your project, add it as a target dependency and link libSPLocalizedString.a. Then, you can simply do:
#import <SPLocalizedString/SPLocalizedString.h>
Manually
Clone the project or add it as a submodule. Drag the whole SPLocalizedString folder to your project.
Its usage is very similar to NSLocalizedString, but with a fundamental change: aside from the key you don't provide a comment, you provide a context. Example:
someLabel.text = SPLocalizedString(@"Name", @"Name label in login screen")
...
otherLabel.text = SPLocalizedString(@"Name", @"Name label in registration screen")Depending on your UI layout, the target languages and other factors, you may need different texts for those two labels even if they have the same text in the beginning. Therefore, SPLocalizedString considers the context as part of the key.
In order to fulfill these strings properly, you'll need a Localizable.strings file with the following lines:
"(Name label in login screen)Name" = "Name"; "(Name label in registration screen)Name" = "Name";
As you can see, for each string the actual key is made of the context and the key you specified with SPLocalizedString.
This file can be automatically generated with spgenstrings. If you don't have a strings file yet, the default value will be the given key (in this case Name).
SPLocalizedString provides some useful functions to manage plurals: SPLocalizedStringPlural, which accepts an additional parameter after the context indicating the number of elements referenced in the string. For example:
NSString *formatString = SPLocalizedStringPlural(@"You have %d followers.", @"Number of followers label", numberOfFollowers);
followersLabel.text = [NSString stringWithFormat:formatString, numberOfFollowers];In order to fulfill these strings properly, you'll need a Localizable.strings file with the following lines:
"(Number of followers label##one)You have %d followers." = "You have %d followers."; "(Number of followers label##other)You have %d followers." = "You have %d followers.";
Again, this file can be automatically generated with spgenstrings. If you don't have a strings file yet, the default value will be the given key (in this case You have %d followers.).
If you look closely, for one key and context you need 2 strings: one when you have 1 follower (with the ##one suffix in the context), another one for the rest of cases (with the ##other suffix in the context). An example would be:
"(Number of followers label##one)You have %d followers." = "You have just one follower."; "(Number of followers label##other)You have %d followers." = "You have %d followers.";
Place that file wherever you need it :)
spgenstrings is a command line tool. It's based on genstrings2 (an open source implementation of genstrings by Cocoanetics), so it shares most of the options with the original genstrings.
The most common way to use it is:
spgenstrings -deleteUnusedEntries -deleteUnusedTables -o <output dir> <source files to process...>The -deleteUnusedEntries and -deleteUnusedTables options removes old entries and strings files that are not referenced anymore in your source code.
SPLocalizedString was created by Sergio Padrino: @sergiou87, based on the work of Cocoanetics on DTLocalizableStringScanner.
If you want to contribute to the project just follow this steps:
SPLocalizedString is available under the MIT license. See the LICENSE file for more info.
| Back | FazBrowse Home | New Git URL |