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

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

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: Added some error handling. 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_controller.m
diff --git a/ios/web_view/shell/translate_controller.m b/ios/web_view/shell/translate_controller.m
index e28d0089282d7c3dfb9a593a323ecc0a0a81c229..9cbf875670c8aa96516d32f7e54c380e8a797057 100644
--- a/ios/web_view/shell/translate_controller.m
+++ b/ios/web_view/shell/translate_controller.m
@@ -14,54 +14,60 @@
@interface TranslateController ()
// Action Sheet to prompt user whether or not the page should be translated.
@property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet;
-// Manager which performs the translation of the content.
-@property(nonatomic, strong) id<CWVTranslateManager> translateManager;
@end
@implementation TranslateController
@synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet;
-@synthesize translateManager = _translateManager;
- (void)dealloc {
[_beforeTranslateActionSheet dismissViewControllerAnimated:YES
completion:nil];
}
-#pragma mark CWVTranslateDelegate methods
+#pragma mark - CWVTranslationDelegate methods
-- (void)translateStepChanged:(CRIWVTransateStep)step
- manager:(id<CWVTranslateManager>)manager {
- if (step == CRIWVTransateStepBeforeTranslate) {
- self.translateManager = manager;
- self.beforeTranslateActionSheet = [UIAlertController
- alertControllerWithTitle:nil
- message:@"Translate?"
- preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction* cancelAction =
- [UIAlertAction actionWithTitle:@"Nope."
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction* action) {
- self.beforeTranslateActionSheet = nil;
- self.translateManager = nil;
- }];
- [_beforeTranslateActionSheet addAction:cancelAction];
+- (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;
- [_translateManager translate];
- self.translateManager = nil;
- }];
- [_beforeTranslateActionSheet addAction:translateAction];
+ UIAlertAction* translateAction = [UIAlertAction
+ actionWithTitle:@"Yes!"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action) {
+ self.beforeTranslateActionSheet = nil;
+ CWVTranslationLanguage* source = result.sourceLanguage;
+ CWVTranslationLanguage* target = result.targetLanguage;
+ [controller translatePageFromLanguage:source toLanguage:target];
+ }];
+ [_beforeTranslateActionSheet addAction:translateAction];
- [[UIApplication sharedApplication].keyWindow.rootViewController
- presentViewController:_beforeTranslateActionSheet
- animated:YES
- completion:nil];
- }
+ [[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/shell_view_controller.m ('K') | « ios/web_view/shell/translate_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698