Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 2.55 KB

File metadata and controls

54 lines (41 loc) · 2.55 KB

Template Information

Name Description
File names strings/objc-string-h.stencil & strings/objc-string-m.stencil
Configuration example
strings:
inputs: path/to/Localizable.strings
outputs:
- templateName: objc-h
output: Localizable.h
- templateName: objc-m
output: Localizable.m
Language Objective-C
Author Eric Slosser

When to use it

  • When you need to generate Objective-C code. Perhaps because you have a pure Objective-C project and don't want to add a Swift file to it (thus triggering the inclusion of the Swift runtime into your build). Or perhaps because you can't find a template that generates Swift that can be accessed from Objective-C.

Customization

You can customize some elements of this template by overriding the following parameters when invoking swiftgen. See the dedicated documentation.

Parameter Name Default Value Description
bundle [NSBundle bundleForClass:BundleToken.class] Allows you to set from which bundle strings are loaded from. By default, it'll point to the same bundle as where the generated code is. Note: ignored if lookupFunction parameter is set.
headerName "Localizable.h" The name of the ObjC header generated by the objc-string-h template. The generated .m file will #include "{{headerName}}". This parameter should have the same value as the output file name used for the template: objc-string-h entry in your config file.
noComments N/A Setting this parameter will disable the comments describing the translation of a key.

Generated Code

Extract:

@interface Localizable : NSObject
// alert__message --> "Some alert body there"
+ (NSString*)alertMessage;
// alert__title --> "Title of the alert"
+ (NSString*)alertTitle;
// ObjectOwnership --> "These are %3$@'s %1$d %2$@."
+ (NSString*)objectOwnershipWithValues:(NSInteger)p1 :(NSString*)p2 :(NSString*)p3;
// percent --> "This is a %% character."
+ (NSString*)percent;
...
@end

Full generated code

Usage example

// simple strings
NSString* message = Localizable.alertMessage
NSString* title = Localizable.alertTitle

// with parameters, note that each argument needs to be of the correct type
NSString*  apples = [Localizable.applesCountWithValue:3];
NSString*  bananas = [Localizable.bananasOwnerWithValues:5 :@"Olivier"];