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

Unified 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, 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/public/cwv_translation_controller.h
diff --git a/ios/web_view/public/cwv_translation_controller.h b/ios/web_view/public/cwv_translation_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..dfbe74bbbe0759b671e1179989f792238619a5c3
--- /dev/null
+++ b/ios/web_view/public/cwv_translation_controller.h
@@ -0,0 +1,102 @@
+// Copyright 2017 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.
+
+#ifndef IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
+#define IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
+
+#import <ChromeWebView/cwv_export.h>
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class CWVTranslationController;
+@class CWVLanguageDetectionResult;
+@class CWVTranslationLanguage;
+
+// The error domain for translation errors.
+extern NSErrorDomain const kCWVTranslationErrorDomain;
+
+// Possible error codes during translation.
+typedef NS_ENUM(NSInteger, CWVTranslationError) {
+ // No errors.
+ CWVTranslationErrorNone = 0,
+ // No connectivity.
+ CWVTranslationErrorNetwork,
+ // The translation script failed to initialize.
+ CWVTranslationErrorInitializationError,
+ // The page's language could not be detected.
+ CWVTranslationErrorUnknownLanguage,
+ // The server detected a language that the browser
+ // does not know.
+ CWVTranslationErrorUnsupportedLanguage,
+ // The original and target languages are the same.
+ CWVTranslationErrorIdenticalLanguages,
+ // An error was reported by the translation script
+ // during translation.
+ CWVTranslationErrorTranslationError,
+ // The library doesn't finish the translation.
+ CWVTranslationErrorTranslationTimeout,
+ // The library raises an unexpected exception.
+ CWVTranslationErrorUnexpectedScriptError,
+ // The library is blocked because of bad origin.
+ CWVTranslationErrorBadOrigin,
+ // Loader fails to load a dependent JavaScript.
+ CWVTranslationErrorScriptLoadError
+};
+
+// Updates delegate on translation progress.
+CWV_EXPORT
+@protocol CWVTranslationControllerDelegate<NSObject>
+@optional
+// Called when language detection is completed. Contains information on the
+// detected language, the assumed target language for translation, as well as
+// all languages supported by this translation controller.
+// |error| will be filled if language detection failed.
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
+ error:(nullable NSError*)error;
+
+// Called when a translation has started.
+- (void)translationController:(CWVTranslationController*)controller
+ didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage;
+
+// Called when translation finishes. |error| will be filled if it failed.
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage
+ error:(nullable NSError*)error;
+
+@end
+
+// Exposes everything needed for translation features.
+CWV_EXPORT
+@interface CWVTranslationController : NSObject
+
+// Delegate to receive translation callbacks.
+@property(nullable, nonatomic, weak) id<CWVTranslationControllerDelegate>
+ delegate;
+
+// Begins translation on the current page from |sourceLanguage| to
+// |targetLanguage|. These language parameters must be chosen from
+// a CWWLanguageDetectionResult's |supportedLanguages|.
+// This must not be called before the |delegate| receives
+// |translationController:didFinishLanguageDetectionWithResult:error:|.
+// 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.
+- (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage;
+
+// Reverts any translations done back to the original page language.
+// Note that the original page language may be different from |sourceLanguage|
+// passed to |translatePageFromLanguage:toLanguage:| above.
+// This must not be called before the |delegate| receives
+// |translationController:didFinishLanguageDetectionWithResult:error:|.
+// TODO(jzw): Document what happens if you call this out of order.
+- (void)revertTranslation;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H

Powered by Google App Engine
This is Rietveld 408576698