POLocalizedString is a gettext translations framework in substitution of Apple translations system.
POLocalizedString is initially a fork of pomo-iphone.
#import<POLocalizedString/POLocalizedString.h>NSInteger numApples = 10;
// Translate single stringNSLog(@"Gettext translated string: %@", POLocalizedString(@"Hi, this is gettext!") );
// Translate plural stringNSLog(@"Gettext translated plural: %@", POLocalizedPluralFormat(@"%d apple", @"%d apples", numApples) );
// Translate and format altogetherNSLog(@"Gettext translated plural: %@", [NSStringstringWithFormat:POLocalizedPluralFormat(@"%d apple", @"%d apples", numApples), numApples]);
@import POLocalizedString
letnumApples=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
POLocalizedString is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod"POLocalizedString"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 ObjectiveCAn item in keywords list:
-k%kAn item in input files:
%fSource 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.
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
POLocalizedString is available under the MIT license. See the LICENSE file for more info.