ich eine grundlegende Swift Datei Test.swift
haben diegenstrings Drosseln, wenn der Wert Parameter in Swift mit
import Foundation
import UIKit
class Test: NSObject {
let a: String
let b: String
override init() {
a = NSLocalizedString("key 1", tableName: nil,
bundle: NSBundle.mainBundle(), value: "value 1", comment: "comment 1")
b = NSLocalizedString("key 2", comment: "comment 2")
}
}
enthält Wenn ich genstrings
auf diese Datei ausgeführt erhalte ich eine unerwartete Warnung
$ genstrings -u Test.swift
Bad entry in file Test.swift (line = 9): Argument is not a literal string.
und die erzeugte Localizable.strings
Datei fehlt der Eintrag für "key 1"
$ cat Localizable.strings
??/* comment 2 */
"key 2" = "key 2";
Allerdings, wenn ich das äquivalent in Objective-C tun, um den folgenden Code in einer Datei mit Test.m
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Test: NSObject
@property (nonatomic, strong) NSString *a;
@property (nonatomic, strong) NSString *b;
@end
@implementation Test
- (id)init {
self = [super init];
if (self) {
self.a = NSLocalizedStringWithDefaultValue(@"key 1", nil, [NSBundle mainBundle], @"value 1", @"comment 1");
self.b = NSLocalizedString(@"key 2", @"comment 2");
}
return self;
}
@end
der genstrings
Befehl funktioniert wie erwartet und ich bekomme den Eintrag für "key 1"
.
$ genstrings -u Test.m
$ cat Localizable.strings
??/* comment 1 */
"key 1" = "value 1";
/* comment 2 */
"key 2" = "key 2";
Was mache ich falsch?
Für eine 'genstrings' Ersatz, das tatsächlich funktioniert und ist langsam, Check-out nicht tot https : //github.com/kayak/SwiftGenStrings. – hennes