mirror of
https://github.com/tappollo/Xcode-Quick-Localization.git
synced 2026-01-13 08:00:53 +08:00
Update QuickLocalization.m
Update QuickLocalization.m Added support for using nil for NSLocalizedString's comment argument. revert xcheckout change
This commit is contained in:
committed by
Zitao Xiong
parent
ce3a98e1e3
commit
94522b6c10
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "QuickLocalization.h"
|
||||
#import "RCXcode.h"
|
||||
|
||||
static NSString *localizeRegexs[] = {
|
||||
@"NSLocalizedString\\s*\\(\\s*@\"(.*)\"\\s*,\\s*(.*)\\s*\\)",
|
||||
@"localizedStringForKey:\\s*@\"(.*)\"\\s*value:\\s*(.*)\\s*table:\\s*(.*)",
|
||||
@@ -15,8 +16,18 @@ static NSString *localizeRegexs[] = {
|
||||
@"NSLocalizedStringFromTableInBundle\\s*\\(\\s*@\"(.*)\"\\s*,\\s*(.*)\\s*,\\s*(.*)\\s*,\\s*(.*)\\s*\\)",
|
||||
@"NSLocalizedStringWithDefaultValue\\s*\\(\\s*@\"(.*)\"\\s*,\\s*(.*)\\s*,\\s*(.*)\\s*,\\s*(.*)\\s*,\\s*(.*)\\s*\\)"
|
||||
};
|
||||
|
||||
static NSString *stringRegexs = @"@\"[^\"]*\"";
|
||||
static NSString * const QLShouldUseNilForComment = @"QLShouldUseNilForComment";
|
||||
|
||||
@interface QuickLocalization ()
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldUseNilForComment;
|
||||
|
||||
@end
|
||||
|
||||
@implementation QuickLocalization
|
||||
|
||||
static id sharedPlugin = nil;
|
||||
|
||||
|
||||
@@ -36,6 +47,9 @@ static id sharedPlugin = nil;
|
||||
[sample setKeyEquivalentModifierMask:NSShiftKeyMask | NSAlternateKeyMask];
|
||||
[sample setTarget:self];
|
||||
[[viewMenuItem submenu] addItem:sample];
|
||||
NSMenuItem *nilToggle = [[NSMenuItem alloc] initWithTitle:@"Use nil for NSLocalizedString comment" action:@selector(toggleNilOption) keyEquivalent:@""];
|
||||
[nilToggle setTarget:self];
|
||||
[[viewMenuItem submenu] addItem:nilToggle];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@@ -71,7 +85,15 @@ static id sharedPlugin = nil;
|
||||
}
|
||||
NSString *string = [line substringWithRange:matchedRangeInLine];
|
||||
// NSLog(@"string index:%d, %@", i, string);
|
||||
NSString *outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, %@)", string, string];
|
||||
NSString *outputString;
|
||||
|
||||
if ([self shouldUseNilForComment]) {
|
||||
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, nil)", string];
|
||||
}
|
||||
else {
|
||||
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, %@)", string, string];
|
||||
}
|
||||
|
||||
addedLength = addedLength + outputString.length - string.length;
|
||||
if ([textView shouldChangeTextInRange:matchedRangeInDocument replacementString:outputString]) {
|
||||
[textView.textStorage replaceCharactersInRange:matchedRangeInDocument
|
||||
@@ -97,4 +119,27 @@ static id sharedPlugin = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)toggleNilOption {
|
||||
[self setShouldUseNilForComment:![self shouldUseNilForComment]];
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||
if ([menuItem action] == @selector(toggleNilOption)) {
|
||||
[menuItem setState:[self shouldUseNilForComment] ? NSOnState : NSOffState];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark Preferences
|
||||
|
||||
- (BOOL)shouldUseNilForComment
|
||||
{
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:QLShouldUseNilForComment];
|
||||
}
|
||||
|
||||
- (void)setShouldUseNilForComment:(BOOL)shouldUseNilForComment
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] setBool:shouldUseNilForComment forKey:QLShouldUseNilForComment];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user