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

Side by Side Diff: ios/web_view/public/cwv_translation_controller.h

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: change error codes and renamed some things 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
6 #define IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
7
8 #import <ChromeWebView/cwv_export.h>
9 #import <Foundation/Foundation.h>
10
11 NS_ASSUME_NONNULL_BEGIN
12
13 @class CWVTranslationController;
14 @class CWVLanguageDetectionResult;
15 @class CWVTranslationLanguage;
16
17 // The error domain for translation errors.
18 extern NSErrorDomain const kCWVTranslationErrorDomain;
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 Per Style Guide we don't need k prefix for public
jzw1 2017/04/28 05:43:36 Done
19 // Possible error codes during translation.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 nit: Add a linebreak after kCWVTranslationErrorDom
jzw1 2017/04/28 05:43:36 Done.
20 // No connectivity.
21 extern const NSInteger kCWVTranslationErrorNetwork;
22 // The translation script failed to initialize.
23 extern const NSInteger kCWVTranslationErrorInitializationError;
24 // The page's language could not be detected.
25 extern const NSInteger kCWVTranslationErrorUnknownLanguage;
26 // The server detected a language that the browser
27 // does not know.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 No need for linebreak. This code fits 80 symbols
jzw1 2017/04/28 05:43:36 Done.
28 extern const NSInteger kCWVTranslationErrorUnsupportedLanguage;
29 // The original and target languages are the same.
30 extern const NSInteger kCWVTranslationErrorIdenticalLanguages;
31 // An error was reported by the translation script
32 // during translation.
33 extern const NSInteger kCWVTranslationErrorTranslationError;
34 // The library doesn't finish the translation.
35 extern const NSInteger kCWVTranslationErrorTranslationTimeout;
36 // The library raises an unexpected exception.
37 extern const NSInteger kCWVTranslationErrorUnexpectedScriptError;
38 // The library is blocked because of bad origin.
39 extern const NSInteger kCWVTranslationErrorBadOrigin;
40 // Loader fails to load a dependent JavaScript.
41 extern const NSInteger kCWVTranslationErrorScriptLoadError;
42
43 // Updates delegate on translation progress.
44 CWV_EXPORT
45 @protocol CWVTranslationControllerDelegate<NSObject>
46 @optional
47 // Called when language detection is completed. Contains information on the
48 // detected language, the assumed target language for translation, as well as
49 // all languages supported by this translation controller.
50 // |error| will be filled if language detection failed.
51 - (void)translationController:(CWVTranslationController*)controller
52 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
53 error:(nullable NSError*)error;
54
55 // Called when a translation has started.
56 - (void)translationController:(CWVTranslationController*)controller
57 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
58 toLanguage:(CWVTranslationLanguage*)targetLanguage;
59
60 // Called when translation finishes. |error| will be filled if it failed.
61 - (void)translationController:(CWVTranslationController*)controller
62 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
63 toLanguage:(CWVTranslationLanguage*)targetLanguage
64 error:(nullable NSError*)error;
65
66 @end
67
68 // Exposes everything needed for translation features.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 nit: Do you want to explain what this class allows
jzw1 2017/04/28 05:43:36 Done.
69 CWV_EXPORT
70 @interface CWVTranslationController : NSObject
71
72 // Delegate to receive translation callbacks.
73 @property(nullable, nonatomic, weak) id<CWVTranslationControllerDelegate>
74 delegate;
75
76 // Begins translation on the current page from |sourceLanguage| to
77 // |targetLanguage|. These language parameters must be chosen from
78 // a CWWLanguageDetectionResult's |supportedLanguages|.
79 // This must not be called before the |delegate| receives
80 // |translationController:didFinishLanguageDetectionWithResult:error:|.
81 // TODO(crbug.com/706289): Document what happens if you call this out of order
82 // or many times.
83 - (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage
84 toLanguage:(CWVTranslationLanguage*)targetLanguage;
85
86 // Reverts any translations done back to the original page language.
87 // Note that the original page language may be different from |sourceLanguage|
88 // passed to |translatePageFromLanguage:toLanguage:| above.
89 // This must not be called before the |delegate| receives
90 // |translationController:didFinishLanguageDetectionWithResult:error:|.
91 // TODO(crbug.com/706289): Document what happens if you call this out of order.
92 - (void)revertTranslation;
93
94 @end
95
96 NS_ASSUME_NONNULL_END
97
98 #endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698