MLKitTranslate Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
Translator
class
Translator
:
NSObject
A class that translates the given input text.
-
Gets a Translator
instance for the specified options. This method is thread safe.
Declaration
Swift
class
func
translator
(
options
:
MLKTranslatorOptions
)
->
Translator
Parameters
options
The options for the translator.
Return Value
A Translator
instance that provides translation with the given options.
-
Translates the given text from the source language into the target language.
This method will return an error if the model files have not been downloaded.
Parameters
text
|
A string in the source language.
|
completion
|
Handler to call back on the main queue with the translation result or error.
|
-
Downloads the model files required for translation, if they are not already downloaded.
Parameters
completion
Handler to call back on the main queue with an error, if any.
-
Downloads the model files required for translation when the given conditions are met. If model
has already been downloaded, completes without additional work.
Parameters
conditions
|
The downloading conditions for the translate model.
|
completion
|
Handler to call back on the main queue with an error, if any.
|
-
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eTranslator\u003c/code\u003e is a class that provides text translation capabilities between specified languages.\u003c/p\u003e\n"],["\u003cp\u003eYou can obtain a \u003ccode\u003eTranslator\u003c/code\u003e instance using the \u003ccode\u003etranslator(options:)\u003c/code\u003e method with desired configurations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etranslate(_:completion:)\u003c/code\u003e method performs the actual translation, returning the result or an error via a completion handler.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure model availability, utilize \u003ccode\u003edownloadModelIfNeeded(completion:)\u003c/code\u003e or \u003ccode\u003edownloadModelIfNeeded(with:completion:)\u003c/code\u003e to download necessary files before translating.\u003c/p\u003e\n"]]],[],null,["# MLKitTranslate Framework Reference\n\nTranslator\n==========\n\n class Translator : NSObject\n\nA class that translates the given input text.\n- `\n ``\n ``\n `\n\n ### [translator(options:)](#/c:objc(cs)MLKTranslator(cm)translatorWithOptions:)\n\n `\n ` \n Gets a `Translator` instance for the specified options. This method is thread safe. \n\n #### Declaration\n\n Swift \n\n class func translator(options: MLKTranslatorOptions) -\u003e Translator\n\n #### Parameters\n\n |-----------------|---------------------------------|\n | ` `*options*` ` | The options for the translator. |\n\n #### Return Value\n\n A `Translator` instance that provides translation with the given options.\n- `\n ``\n ``\n `\n\n ### [translate(_:completion:)](#/c:objc(cs)MLKTranslator(im)translateText:completion:)\n\n `\n ` \n Translates the given text from the source language into the target language.\n\n This method will return an error if the model files have not been downloaded. \n\n #### Declaration\n\n Swift \n\n func translate(_ text: String, completion: @escaping ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorCallback)\n\n #### Parameters\n\n |--------------------|------------------------------------------------------------------------------|\n | ` `*text*` ` | A string in the source language. |\n | ` `*completion*` ` | Handler to call back on the main queue with the translation result or error. |\n\n- `\n ``\n ``\n `\n\n ### [downloadModelIfNeeded(completion:)](#/c:objc(cs)MLKTranslator(im)downloadModelIfNeededWithCompletion:)\n\n `\n ` \n Downloads the model files required for translation, if they are not already downloaded. \n\n #### Declaration\n\n Swift \n\n func downloadModelIfNeeded(completion: @escaping ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorDownloadModelIfNeededCallback)\n\n #### Parameters\n\n |--------------------|---------------------------------------------------------------|\n | ` `*completion*` ` | Handler to call back on the main queue with an error, if any. |\n\n- `\n ``\n ``\n `\n\n ### [downloadModelIfNeeded(with:completion:)](#/c:objc(cs)MLKTranslator(im)downloadModelIfNeededWithConditions:completion:)\n\n `\n ` \n Downloads the model files required for translation when the given conditions are met. If model\n has already been downloaded, completes without additional work. \n\n #### Declaration\n\n Swift \n\n func downloadModelIfNeeded(with conditions: MLKModelDownloadConditions, completion: @escaping ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorDownloadModelIfNeededCallback)\n\n #### Parameters\n\n |--------------------|---------------------------------------------------------------|\n | ` `*conditions*` ` | The downloading conditions for the translate model. |\n | ` `*completion*` ` | Handler to call back on the main queue with an error, if any. |\n\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)MLKTranslator(im)init)\n\n `\n ` \n Unavailable."]]