This commit is contained in:
2025-11-17 20:07:39 +08:00
parent ee433db4ad
commit 005e3c7581
43 changed files with 529 additions and 172 deletions

View File

@@ -52,7 +52,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
parameters:parameters
error:&serror];
if (serror || !req) {
if (completion) completion(nil, nil, serror ?: [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorInvalidURL userInfo:@{NSLocalizedDescriptionKey: @"无效的URL"}]);
if (completion) completion(nil, nil, serror ?: [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorInvalidURL userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid URL")}]);
return nil;
}
[self applyHeaders:headers toMutableRequest:req contentType:nil];
@@ -83,7 +83,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
- (BOOL)ensureEnabled:(KBNetworkCompletion)completion {
if (!self.isEnabled) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorDisabled userInfo:@{NSLocalizedDescriptionKey: @"网络未启用(可能未开启完全访问)"}];
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorDisabled userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Network disabled (Full Access may be off)")}];
if (completion) completion(nil, nil, e);
return NO;
}
@@ -127,7 +127,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
}
NSData *data = (NSData *)responseObject;
if (![data isKindOfClass:[NSData class]]) {
if (completion) completion(nil, response, [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorInvalidResponse userInfo:@{NSLocalizedDescriptionKey:@"无数据"}]);
if (completion) completion(nil, response, [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorInvalidResponse userInfo:@{NSLocalizedDescriptionKey:KBLocalized(@"No data")}]);
return;
}
NSString *ct = nil;
@@ -150,7 +150,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
if (looksJSON) {
NSError *jsonErr = nil;
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonErr];
if (jsonErr) { if (completion) completion(nil, response, [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorDecodeFailed userInfo:@{NSLocalizedDescriptionKey:@"JSON解析失败"}]); return; }
if (jsonErr) { if (completion) completion(nil, response, [NSError errorWithDomain:KBNetworkErrorDomain code:KBNetworkErrorDecodeFailed userInfo:@{NSLocalizedDescriptionKey:KBLocalized(@"Failed to parse JSON")}]); return; }
if (completion) completion(json, response, nil);
} else {
if (completion) completion(data, response, nil);
@@ -178,12 +178,12 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
#pragma mark - Private helpers
- (void)fail:(KBNetworkError)code completion:(KBNetworkCompletion)completion {
NSString *msg = @"网络错误";
NSString *msg = KBLocalized(@"Network error");
switch (code) {
case KBNetworkErrorDisabled: msg = @"网络未启用(可能未开启完全访问)"; break;
case KBNetworkErrorInvalidURL: msg = @"无效的URL"; break;
case KBNetworkErrorInvalidResponse: msg = @"无效的响应"; break;
case KBNetworkErrorDecodeFailed: msg = @"解析失败"; break;
case KBNetworkErrorDisabled: msg = KBLocalized(@"Network disabled (Full Access may be off)"); break;
case KBNetworkErrorInvalidURL: msg = KBLocalized(@"Invalid URL"); break;
case KBNetworkErrorInvalidResponse: msg = KBLocalized(@"Invalid response"); break;
case KBNetworkErrorDecodeFailed: msg = KBLocalized(@"Parse failed"); break;
default: break;
}
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain

View File

@@ -51,7 +51,7 @@
del.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
del.layer.cornerRadius = 14; del.layer.masksToBounds = YES;
del.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
[del setTitle:@"删除" forState:UIControlStateNormal];
[del setTitle:KBLocalized(@"Delete") forState:UIControlStateNormal];
[del setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[del addTarget:self action:@selector(onTapClose) forControlEvents:UIControlEventTouchUpInside];
_closeButton = del;
@@ -77,4 +77,3 @@
- (KBStreamTextView *)textView { return self.textViewInternal; }
@end

View File

@@ -47,7 +47,7 @@
}];
UILabel *title = [UILabel new];
title.text = @"开启【允许完全访问】,体验完整功能";
title.text = KBLocalized(@"Turn on Allow Full Access to experience all features");
title.font = [UIFont boldSystemFontOfSize:16];
title.textColor = [UIColor blackColor];
title.textAlignment = NSTextAlignmentCenter;
@@ -70,7 +70,7 @@
}];
UILabel *row1 = [UILabel new]; row1.text = AppName; row1.textColor = [UIColor blackColor];
UILabel *row2 = [UILabel new]; row2.text = @"允许完全访问"; row2.textColor = [UIColor blackColor];
UILabel *row2 = [UILabel new]; row2.text = KBLocalized(@"Allow Full Access"); row2.textColor = [UIColor blackColor];
[box addSubview:row1]; [box addSubview:row2];
[row1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(box).offset(16); make.top.equalTo(box).offset(14); }];
UIView *line = [UIView new]; line.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
@@ -98,7 +98,7 @@
UIButton *go = [UIButton buttonWithType:UIButtonTypeSystem];
go.backgroundColor = [UIColor blackColor];
[go setTitle:@"去开启" forState:UIControlStateNormal];
[go setTitle:KBLocalized(@"Go enable") forState:UIControlStateNormal];
[go setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
go.titleLabel.font = [UIFont boldSystemFontOfSize:18];
go.layer.cornerRadius = 12;
@@ -168,10 +168,10 @@
// Universal Link AASA/Associated Domains KB_UL_BASE
NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=kb_extension", KB_UL_SETTINGS]];
void (^finish)(BOOL) = ^(BOOL ok){
void (^finish)(BOOL) = ^(BOOL ok){
if (ok) { [self dismiss]; }
else {
NSString *showInfo = [NSString stringWithFormat:@"请按路径:设置→通用→键盘→键盘→%@→允许完全访问",AppName];
NSString *showInfo = [NSString stringWithFormat:KBLocalized(@"Follow: Settings → General → Keyboard → Keyboards → %@ → Allow Full Access"),AppName];
[KBHUD showInfo:showInfo];
}
};

View File

@@ -60,7 +60,7 @@
- (UILabel *)placeholderLabelInternal {
if (!_placeholderLabelInternal) {
_placeholderLabelInternal = [[UILabel alloc] init];
_placeholderLabelInternal.text = @"点击粘贴TA的话";
_placeholderLabelInternal.text = KBLocalized(@"Tap to paste their message");
_placeholderLabelInternal.textColor = [UIColor colorWithRed:0.20 green:0.64 blue:0.54 alpha:1.0];
_placeholderLabelInternal.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
}

View File

@@ -176,7 +176,16 @@
- (void)reloadDemoData {
//
self.itemsInternal = @[@"高情商", @"暖味拉扯", @"风趣幽默", @"撩女生", @"社交惬匿", @"情场高手", @"一枚暖男", @"聊天搭子", @"表达爱意", @"更多话术"];
self.itemsInternal = @[KBLocalized(@"高情商"),
KBLocalized(@"暖味拉扯"),
KBLocalized(@"风趣幽默"),
KBLocalized(@"撩女生"),
KBLocalized(@"社交惬匿"),
KBLocalized(@"情场高手"),
KBLocalized(@"一枚暖男"),
KBLocalized(@"聊天搭子"),
KBLocalized(@"表达爱意"),
KBLocalized(@"更多话术")];
[self.tagListView setItems:self.itemsInternal];
}
@@ -257,7 +266,7 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
[self.tagListView setLoading:NO atIndex:self.loadingTagIndex.integerValue];
self.loadingTagIndex = nil; self.loadingTagTitle = nil;
}
if (error) { [KBHUD showInfo:@"拉取失败"]; }
if (error) { [KBHUD showInfo:KBLocalized(@"拉取失败")]; }
if (self.streamOverlay) { [self.streamOverlay finish]; }
};
self.streamFetcher = fetcher;
@@ -296,7 +305,7 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
// 1) 访
if (![[KBFullAccessManager shared] hasFullAccess]) {
// 访
[KBHUD showInfo:@"处理中…"];
[KBHUD showInfo:KBLocalized(@"处理中…")];
[[KBFullAccessManager shared] ensureFullAccessOrGuideInView:self];
return;
}
@@ -330,7 +339,7 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
#pragma clang diagnostic pop
} @catch (__unused NSException *e) { bridged = NO; }
if (!bridged) {
[KBHUD showInfo:@"请切换到主App完成登录"];
[KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")];
}
}];
});
@@ -362,7 +371,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
return;
}
[KBHUD showInfo:@"处理中…"];
[KBHUD showInfo:KBLocalized(@"处理中…")];
UIInputViewController *ivc = KBFindInputViewController(self);
if (!ivc) return;
@@ -482,13 +491,13 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
- (void)kb_fullAccessChanged {
dispatch_async(dispatch_get_main_queue(), ^{ [self kb_refreshPasteboardMonitor]; });
}
- (void)onTapDelete {
- (void)onTapDelete {
NSLog(@"点击:删除");
UIInputViewController *ivc = KBFindInputViewController(self);
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
[proxy deleteBackward];
}
- (void)onTapClear {
- (void)onTapClear {
NSLog(@"点击:清空");
// pasteView
UIInputViewController *ivc = KBFindInputViewController(self);
@@ -505,7 +514,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
guard += count;
}
}
- (void)onTapSend {
- (void)onTapSend {
NSLog(@"点击:发送");
// App
UIInputViewController *ivc = KBFindInputViewController(self);
@@ -572,7 +581,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
- (UIButton *)pasteButtonInternal {
if (!_pasteButtonInternal) {
_pasteButtonInternal = [self buildRightButtonWithTitle:@"粘贴" color:[UIColor colorWithRed:0.13 green:0.73 blue:0.60 alpha:1.0]];
_pasteButtonInternal = [self buildRightButtonWithTitle:KBLocalized(@"Paste") color:[UIColor colorWithRed:0.13 green:0.73 blue:0.60 alpha:1.0]];
[_pasteButtonInternal addTarget:self action:@selector(onTapPaste) forControlEvents:UIControlEventTouchUpInside];
}
return _pasteButtonInternal;
@@ -586,7 +595,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
_deleteButtonInternal.layer.cornerRadius = 12.0;
_deleteButtonInternal.layer.masksToBounds = YES;
_deleteButtonInternal.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
[_deleteButtonInternal setTitle:@"删除" forState:UIControlStateNormal];
[_deleteButtonInternal setTitle:KBLocalized(@"删除") forState:UIControlStateNormal];
[_deleteButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_deleteButtonInternal addTarget:self action:@selector(onTapDelete) forControlEvents:UIControlEventTouchUpInside];
}
@@ -600,16 +609,16 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
_clearButtonInternal.layer.cornerRadius = 12.0;
_clearButtonInternal.layer.masksToBounds = YES;
_clearButtonInternal.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
[_clearButtonInternal setTitle:@"清空" forState:UIControlStateNormal];
[_clearButtonInternal setTitle:KBLocalized(@"Clear") forState:UIControlStateNormal];
[_clearButtonInternal setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_clearButtonInternal addTarget:self action:@selector(onTapClear) forControlEvents:UIControlEventTouchUpInside];
}
return _clearButtonInternal;
}
- (UIButton *)sendButtonInternal {
- (UIButton *)sendButtonInternal {
if (!_sendButtonInternal) {
_sendButtonInternal = [self buildRightButtonWithTitle:@"发送" color:[UIColor colorWithRed:0.13 green:0.73 blue:0.60 alpha:1.0]];
_sendButtonInternal = [self buildRightButtonWithTitle:KBLocalized(@"Send") color:[UIColor colorWithRed:0.13 green:0.73 blue:0.60 alpha:1.0]];
[_sendButtonInternal addTarget:self action:@selector(onTapSend) forControlEvents:UIControlEventTouchUpInside];
}
return _sendButtonInternal;

View File

@@ -125,7 +125,7 @@
NSArray *r4 = @[ [KBKey keyWithTitle:@"abc" type:KBKeyTypeModeChange],
[KBKey keyWithTitle:@"AI" type:KBKeyTypeCustom],
[KBKey keyWithTitle:@"space" type:KBKeyTypeSpace],
[KBKey keyWithTitle:@"发送" type:KBKeyTypeReturn] ];
[KBKey keyWithTitle:KBLocalized(@"Send") type:KBKeyTypeReturn] ];
return @[r1, r2, r3, r4];
}
@@ -159,7 +159,7 @@
NSArray *row4 = @[ [KBKey keyWithTitle:@"123" type:KBKeyTypeModeChange],
[KBKey keyWithTitle:@"AI" type:KBKeyTypeCustom],
[KBKey keyWithTitle:@"space" type:KBKeyTypeSpace],
[KBKey keyWithTitle:@"发送" type:KBKeyTypeReturn] ];
[KBKey keyWithTitle:KBLocalized(@"Send") type:KBKeyTypeReturn] ];
return @[row1.copy, row2.copy, row3.copy, row4];
}

View File

@@ -26,7 +26,7 @@
}];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.text = @"设置";
self.titleLabel.text = KBLocalized(@"设置");
self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
self.titleLabel.textColor = [UIColor blackColor];
[self addSubview:self.titleLabel];
@@ -37,7 +37,7 @@
//
UILabel *place = [[UILabel alloc] init];
place.text = @"这里是设置内容占位";
place.text = KBLocalized(@"这里是设置内容占位");
place.textColor = [UIColor darkGrayColor];
place.font = [UIFont systemFontOfSize:14];
[self addSubview:place];
@@ -68,4 +68,3 @@
- (UIButton *)backButton { return self.backButtonInternal; }
@end