POLocalizedString 1.1.1

POLocalizedString 1.1.1

Maintained by Maxime Epain.



  • By
  • Maxime Epain

CI Status Version License Platform Carthage


POLocalizedString is a gettext translations framework in substitution of Apple translations system.

POLocalizedString is initially a fork of pomo-iphone.

Features

  • Supports mo and po format.
  • Supports plurals forms.
  • Supports multiple Bundles.

Basic usage

Objective-C
#import <POLocalizedString/POLocalizedString.h>

NSInteger numApples = 10;

// Translate single string
NSLog(@"Gettext translated string: %@", POLocalizedString(@"Hi, this is gettext!") );

// Translate plural string
NSLog(@"Gettext translated plural: %@", POLocalizedPluralFormat(@"%d apple", @"%d apples", numApples) );

// Translate and format altogether
NSLog(@"Gettext translated plural: %@", [NSString stringWithFormat:POLocalizedPluralFormat(@"%d apple", @"%d apples", numApples), numApples]);
Swift
@import POLocalizedString

let numApples = 10

// Translate single string
print("Gettext translated string: %@", "Hi, this is gettext!".localized);

// Translate plural string
print("Gettext translated plural: %@", "%d apple".localized(plural: "%d apples", n: numApples) );

// Translate and format altogether
print("Gettext translated plural: %@", "%d apple".localized(plural: "%d apples", n: numApples, with: numApples);

POLocalizedString looks for .mo or .po files with the following pattern:

%app-bundle-path/%language.%extension

where %language is a language two letter code (e.g. ru, en, es, etc..) %extension is usually mo or po. mo files have higher priority since it's more compact format and supposed to be used for distribution.

Example path may look like that:

/MyApp.app/es.mo

Installation

POLocalizedString is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "POLocalizedString"

Poedit

Settings

If you use Poedit, follow the instructions below to setup Objective-C parser.

Go to Poedit > Preferences and add new parser with the following settings:

  • List of extensions: *.m;*.mm;*.h;*.swift;

  • Parser command: xgettext --force-po -o %o %C %K %F -L ObjectiveC

  • An item in keywords list: -k%k

  • An item in input files: %f

  • Source code charset: --from-code=%c

Also you can use --add-comments=/ flag in Parser commands to enable translators' comments. In this example all comments starting with triple slash will be treated as translators' comments.

Catalog

Setup the following keywords for your catalog to make Poedit work with your source code:

_
POLocalizedString
POLocalizedStringFromContext:2c,1
POLocalizedPluralString:3c,1,2
POLocalizedPluralStringFromContext:4c,1,2
POLocalizedStringInBundle:2
POLocalizedStringFromContextInBundle:3c,2
POLocalizedPluralStringInBundle:2,3
POLocalizedPluralStringFromContextInBundle:5c,2,3

License

POLocalizedString is available under the MIT license. See the LICENSE file for more info.