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

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: added TODO 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;
19
20 // Possible error codes during translation.
21 typedef NS_ENUM(NSInteger, CWVTranslationError) {
22 // No errors.
23 CWVTranslationErrorNone = 0,
24 // No connectivity.
25 CWVTranslationErrorNetwork,
26 // The translation script failed to initialize.
27 CWVTranslationErrorInitializationError,
28 // The page's language could not be detected.
29 CWVTranslationErrorUnknownLanguage,
30 // The server detected a language that the browser
31 // does not know.
32 CWVTranslationErrorUnsupportedLanguage,
33 // The original and target languages are the same.
34 CWVTranslationErrorIdenticalLanguages,
35 // An error was reported by the translation script
36 // during translation.
37 CWVTranslationErrorTranslationError,
38 // The library doesn't finish the translation.
39 CWVTranslationErrorTranslationTimeout,
40 // The library raises an unexpected exception.
41 CWVTranslationErrorUnexpectedScriptError,
42 // The library is blocked because of bad origin.
43 CWVTranslationErrorBadOrigin,
44 // Loader fails to load a dependent JavaScript.
45 CWVTranslationErrorScriptLoadError
46 };
47
48 // Updates delegate on translation progress.
49 CWV_EXPORT
50 @protocol CWVTranslationControllerDelegate<NSObject>
51 @optional
52 // Called when language detection is completed. Contains information on the
53 // detected language, the assumed target language for translation, as well as
54 // all languages supported by this translation controller.
55 // |error| will be filled if language detection failed.
56 - (void)translationController:(CWVTranslationController*)controller
57 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
58 error:(nullable NSError*)error;
59
60 // Called when a translation has started.
61 - (void)translationController:(CWVTranslationController*)controller
62 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
63 toLanguage:(CWVTranslationLanguage*)targetLanguage;
64
65 // Called when translation finishes. |error| will be filled if it failed.
66 - (void)translationController:(CWVTranslationController*)controller
67 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
68 toLanguage:(CWVTranslationLanguage*)targetLanguage
69 error:(nullable NSError*)error;
70
71 @end
72
73 // Exposes everything needed for translation features.
74 CWV_EXPORT
75 @interface CWVTranslationController : NSObject
76
77 // Delegate to receive translation callbacks.
78 @property(nullable, nonatomic, weak) id<CWVTranslationControllerDelegate>
79 delegate;
80
81 // Begins translation on the current page from |sourceLanguage| to
82 // |targetLanguage|. These language parameters must be chosen from
83 // a CWWLanguageDetectionResult's |supportedLanguages|.
84 // This must not be called before the |delegate| receives
85 // |translationController:didFinishLanguageDetectionWithResult:error:|.
86 // TODO(jzw): Document what happens if you call this out of order or many times.
Eugene But (OOO till 7-30) 2017/04/27 13:08:08 In iOS code we use TODO(crbug.com/xxx) format, bec
jzw1 2017/04/28 02:34:54 Done.
87 - (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage
88 toLanguage:(CWVTranslationLanguage*)targetLanguage;
89
90 // Reverts any translations done back to the original page language.
91 // Note that the original page language may be different from |sourceLanguage|
92 // passed to |translatePageFromLanguage:toLanguage:| above.
93 // This must not be called before the |delegate| receives
94 // |translationController:didFinishLanguageDetectionWithResult:error:|.
95 // TODO(jzw): Document what happens if you call this out of order.
96 - (void)revertTranslation;
97
98 @end
99
100 NS_ASSUME_NONNULL_END
101
102 #endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698