Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Niutrans support #222

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Easydict-debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEVELOPMENT_TEAM = 79NQA2XYHM
CODE_SIGN_IDENTITY = Apple Development
CODE_SIGN_STYLE = Automatic
3 changes: 3 additions & 0 deletions Easydict.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEVELOPMENT_TEAM = 79NQA2XYHM
CODE_SIGN_IDENTITY = Apple Development
CODE_SIGN_STYLE = Automatic
179 changes: 153 additions & 26 deletions Easydict.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file added Easydict/App/.DS_Store
Binary file not shown.
51 changes: 40 additions & 11 deletions Easydict/App/AppDelegate+EZURLScheme.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,80 @@
#import <JLRoutes.h>
#import "EZWindowManager.h"
#import "EZSchemeParser.h"
#import "EZConfiguration.h"

@implementation AppDelegate (EZURLScheme)

- (void)registerRouters {
// Reigster URL Scheme handler.
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

EZWindowManager *windowManager = [EZWindowManager shared];
[appleEventManager setEventHandler:self
andSelector:@selector(handleURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];

JLRoutes *routes = [JLRoutes globalRoutes];
[routes addRoute:@"/:action" handler:^BOOL(NSDictionary *parameters) {
NSString *action = parameters[@"action"];
NSString *queryText = parameters[@"text"];
NSURL *URL = parameters[JLRouteURLKey];

/**
Recommend use easydict://query?text=xxx, easydict://xxx is a bit ambiguous and complex.

easydict://good
easydict://query?text=good

easydictd://good
easydictd://query?text=good
easydictd://good%2Fgirl (easydictd://good/girl)
easydict://good%2Fgirl (easydict://good/girl)
*/
if (!([action isEqualToString:EZQueryKey] && queryText.length)) {
queryText = action;
// Ukraine may get another Patriot battery.
if (action.length == 0) {
/**
!!!: action may be nil if URL contains '.'
FIX https://github.com/tisfeng/Easydict/issues/207#issuecomment-1786267017
*/
queryText = [self extractQueryTextFromURL:URL];
} else {
queryText = action;
}
}
[windowManager showFloatingWindowType:EZWindowTypeFixed queryText:queryText actionType:EZActionTypeInvokeQuery];
[self showFloatingWindowAndAutoQueryText:queryText];

return YES; // return YES to say we have handled the route
}];

// good / girl
[routes addRoute:@"*" handler:^BOOL(NSDictionary *parameters) {
NSLog(@"parameters: %@", parameters);

NSURL *URL = parameters[JLRouteURLKey];
NSLog(@"URL: %@", URL);

// NSString *queryText = [URL.resourceSpecifier stringByReplacingOccurrencesOfString:@"//" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 2)];
// [windowManager showFloatingWindowType:EZWindowTypeFixed queryText:queryText];
NSString *queryText = [self extractQueryTextFromURL:URL];
[self showFloatingWindowAndAutoQueryText:queryText];

return YES;
}];
}

#pragma mark -

- (void)showFloatingWindowAndAutoQueryText:(NSString *)text {
EZWindowManager *windowManager = [EZWindowManager shared];
EZWindowType windowType = EZConfiguration.shared.shortcutSelectTranslateWindowType;

[windowManager showFloatingWindowType:windowType
queryText:text.trim
autoQuery:YES
actionType:EZActionTypeInvokeQuery];
}

/// Get query text from url scheme, easydict://good%2Fgirl --> good%2Fgirl
- (NSString *)extractQueryTextFromURL:(NSURL *)URL {
NSString *queryText = [URL.resourceSpecifier stringByReplacingOccurrencesOfString:@"//" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 2)];
return queryText.decode;
}

- (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSURL *URL = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];

Expand Down
1 change: 1 addition & 0 deletions Easydict/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Capturing crash logs must be placed first.
[MMCrash registerHandler];
[EZLog setupCrashLogService];
[EZLog logAppInfo];

[self setupAppLanguage];

Expand Down
Binary file added Easydict/App/Assets.xcassets/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "小牛翻译.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
14 changes: 7 additions & 7 deletions Easydict/App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
</dependencies>
<scenes>
<!--Application-->
Expand All @@ -22,9 +22,9 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="uLo-B5-Udn"/>
<menuItem title="Preferences…" keyEquivalent="," id="wgy-yj-uSV">
<menuItem title="Settings…" keyEquivalent="," id="wgy-yj-uSV">
<connections>
<action selector="preferenceAction:" target="qM9-fT-Fym" id="AQg-31-GQh"/>
<action selector="settingAction:" target="qM9-fT-Fym" id="Ygf-3h-5J7"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="srv-kw-Ziy"/>
Expand Down Expand Up @@ -718,10 +718,10 @@ DQ
<outlet property="helpItem" destination="ICB-w8-IqK" id="MdB-xe-fCz"/>
<outlet property="inputItem" destination="AWf-Ci-7QE" id="Isp-ch-8Q6"/>
<outlet property="menu" destination="A3F-ys-zOg" id="n6f-3z-A90"/>
<outlet property="preferencesItem" destination="Fzj-Rh-cL0" id="wnW-lJ-w5g"/>
<outlet property="quitItem" destination="JZ0-yT-1tw" id="SI7-X9-kea"/>
<outlet property="screenshotOCRItem" destination="bGs-JX-JVH" id="uki-N8-izc"/>
<outlet property="selectionItem" destination="lUI-Zn-Bwr" id="WVP-FO-jlf"/>
<outlet property="settingsItem" destination="Fzj-Rh-cL0" id="bo4-Ps-zfJ"/>
<outlet property="showMiniItem" destination="PmP-cO-1HF" id="z5W-Mb-1f4"/>
<outlet property="snipItem" destination="2TG-8C-8RM" id="NNT-OJ-7eY"/>
<outlet property="versionItem" destination="PkP-25-JBw" id="beL-5f-TOn"/>
Expand Down Expand Up @@ -772,9 +772,9 @@ DQ
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kkp-Wh-Cmv"/>
<menuItem title="偏好设置" keyEquivalent="," id="Fzj-Rh-cL0">
<menuItem title="设置..." keyEquivalent="," id="Fzj-Rh-cL0">
<connections>
<action selector="preferenceAction:" target="qM9-fT-Fym" id="Emg-Mm-dS5"/>
<action selector="settingAction:" target="qM9-fT-Fym" id="Hl3-VA-VEK"/>
</connections>
</menuItem>
<menuItem title="检查更新" id="GQ2-WA-9QB">
Expand Down
12 changes: 12 additions & 0 deletions Easydict/App/Easydict-debug.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
Binary file added Easydict/App/Icons/.DS_Store
Binary file not shown.
41 changes: 28 additions & 13 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sourceLanguage" : "en",
"sourceLanguage" : "zh-Hans",
"strings" : {
"about" : {
"comment" : "about",
Expand Down Expand Up @@ -109,7 +109,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "System Dictionary"
"value" : "Apple Dictionary"
}
},
"zh-Hans" : {
Expand All @@ -125,7 +125,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "System Translation"
"value" : "Apple Translation"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -924,7 +924,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Center of Screen"
"value" : "Center of screen"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -956,7 +956,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Mouse Position"
"value" : "Mouse position"
}
},
"zh-Hans" : {
Expand All @@ -972,7 +972,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Right Side of Screen"
"value" : "Right side of screen"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -1042,12 +1042,12 @@
}
}
},
"Github:" : {
"GitHub:" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
"value" : "GitHub:"
}
}
}
Expand Down Expand Up @@ -1379,6 +1379,22 @@
}
}
},
"niuTrans_translate" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "NiuTrans"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "小牛翻译"
}
}
}
},
"no_results_found" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1856,19 +1872,18 @@
}
}
},
"setting" : {
"comment" : "setting",
"setting_general" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Settings"
"value" : "General"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "设置"
"value" : "通用"
}
}
}
Expand Down Expand Up @@ -2223,4 +2238,4 @@
}
},
"version" : "1.0"
}
}
6 changes: 5 additions & 1 deletion Easydict/App/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ static void delay_block(dispatch_block_t block) {
void queryText(NSString *text) {
// ???: need to wait AppDelegate loaded.
delay_block(^{
[EZWindowManager.shared showFloatingWindowType:EZWindowTypeFixed queryText:text actionType:EZActionTypeInvokeQuery];
EZWindowManager *windowManager = [EZWindowManager shared];
[windowManager showFloatingWindowType:EZWindowTypeFixed
queryText:text.trim
autoQuery:YES
actionType:EZActionTypeInvokeQuery];
});
}

Expand Down
Loading