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

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

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: merge Created 3 years, 7 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
« no previous file with comments | « ios/web_view/shell/shell_translation_delegate.h ('k') | ios/web_view/shell/shell_view_controller.m » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/shell/shell_translation_delegate.m
diff --git a/ios/web_view/shell/shell_translation_delegate.m b/ios/web_view/shell/shell_translation_delegate.m
new file mode 100644
index 0000000000000000000000000000000000000000..a16515ce7719d704f830fe9c10fe35597a3b45f0
--- /dev/null
+++ b/ios/web_view/shell/shell_translation_delegate.m
@@ -0,0 +1,63 @@
+// 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/shell_translation_delegate.h"
+
+#import <UIKit/UIKit.h>
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface ShellTranslationDelegate ()
+// Action Sheet to prompt user whether or not the page should be translated.
+@property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet;
+@end
+
+@implementation ShellTranslationDelegate
+
+@synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet;
+
+- (void)dealloc {
+ [_beforeTranslateActionSheet dismissViewControllerAnimated:YES
+ completion:nil];
+}
+
+#pragma mark - CWVTranslationDelegate methods
+
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
+ error:(NSError*)error {
+ __weak ShellTranslationDelegate* weakSelf = self;
+
+ self.beforeTranslateActionSheet = [UIAlertController
+ alertControllerWithTitle:nil
+ message:@"Translate?"
+ preferredStyle:UIAlertControllerStyleActionSheet];
+ UIAlertAction* cancelAction =
+ [UIAlertAction actionWithTitle:@"Nope."
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction* action) {
+ weakSelf.beforeTranslateActionSheet = nil;
+ }];
+ [_beforeTranslateActionSheet addAction:cancelAction];
+
+ UIAlertAction* translateAction = [UIAlertAction
+ actionWithTitle:@"Yes!"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ weakSelf.beforeTranslateActionSheet = nil;
+ CWVTranslationLanguage* source = result.pageLanguage;
+ CWVTranslationLanguage* target = result.suggestedTargetLanguage;
+ [controller translatePageFromLanguage:source toLanguage:target];
+ }];
+ [_beforeTranslateActionSheet addAction:translateAction];
+
+ [[UIApplication sharedApplication].keyWindow.rootViewController
+ presentViewController:_beforeTranslateActionSheet
+ animated:YES
+ completion:nil];
+}
+
+@end
« no previous file with comments | « ios/web_view/shell/shell_translation_delegate.h ('k') | ios/web_view/shell/shell_view_controller.m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698