Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Unified Diff: ios/web_view/shell/translate_delegate.m

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: added TODO Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web_view/shell/translate_delegate.m
diff --git a/ios/web_view/shell/translate_delegate.m b/ios/web_view/shell/translate_delegate.m
new file mode 100644
index 0000000000000000000000000000000000000000..4c52f6658861252f8b0ecc0ad5b3fb3a2475d97f
--- /dev/null
+++ b/ios/web_view/shell/translate_delegate.m
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/web_view/shell/translate_delegate.h"
+
+#import <ChromeWebView/ChromeWebView.h>
+#import <UIKit/UIKit.h>
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface TranslateDelegate ()
+// Action Sheet to prompt user whether or not the page should be translated.
+@property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet;
+@end
+
+@implementation TranslateDelegate
+
+@synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet;
+
+- (void)dealloc {
+ [_beforeTranslateActionSheet dismissViewControllerAnimated:YES
+ completion:nil];
+}
+
+#pragma mark - CWVTranslationDelegate methods
+
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
+ error:(NSError*)error {
+ self.beforeTranslateActionSheet = [UIAlertController
+ alertControllerWithTitle:nil
+ message:@"Translate?"
+ preferredStyle:UIAlertControllerStyleActionSheet];
+ UIAlertAction* cancelAction =
+ [UIAlertAction actionWithTitle:@"Nope."
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction* action) {
+ self.beforeTranslateActionSheet = nil;
+ }];
+ [_beforeTranslateActionSheet addAction:cancelAction];
+
+ UIAlertAction* translateAction = [UIAlertAction
+ actionWithTitle:@"Yes!"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ self.beforeTranslateActionSheet = nil;
+ CWVTranslationLanguage* source = result.pageLanguage;
+ CWVTranslationLanguage* target = result.OSLanguage;
+ [controller translatePageFromLanguage:source toLanguage:target];
+ }];
+ [_beforeTranslateActionSheet addAction:translateAction];
+
+ [[UIApplication sharedApplication].keyWindow.rootViewController
+ presentViewController:_beforeTranslateActionSheet
+ animated:YES
+ completion:nil];
+}
+
+- (void)translationController:(CWVTranslationController*)controller
+ didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage {
+}
+
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage
+ error:(NSError*)error {
+}
+
+@end
« ios/web_view/shell/translate_delegate.h ('K') | « ios/web_view/shell/translate_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698