Localize-Swift
Localize-Swift copied to clipboard
Does not work with Obj-C Code.
Code should work with mix project Obj-C and Swift, Please check
Out of the box it seems not, but you can add an extension so that it can. refer to #52. Although this suggests editing the library directly, i would advise against that and just write an extension like so
extension Localize {
@objc open class func thisString(_ wantedString: String) -> String {
return wantedString.localized()
}
}
@varun-naharia
After some consideration of usage and syntax i came up with the following very simple extension for using localized in Objc.
extension NSString {
@objc var localized: NSString {
let string = self as String
return string.localized() as NSString
}
}
this allows for using it like so @"Hello world".localized;
Now this is a little atypical for Objc code but I was not so keen on some of the alternatives which were
[Localize string:@"Hello World"];
[@"Hello World" localized];
Also would this work with the genstrings
script @marmelroy?
I created a pr for the obj-c support at genstrings here Still waiting to be merged.