MLKitTranslate Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
MLKTranslator
@interface
MLKTranslator
:
NSObject
A class that translates the given input text.
-
Gets a Translator
instance for the specified options. This method is thread safe.
Declaration
Objective-C
+
(
nonnull
MLKTranslator
*
)
translatorWithOptions
:
(
nonnull
MLKTranslatorOptions
*
)
options
;
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.
Declaration
Objective-C
-
(
void
)
translateText
:(
nonnull
NSString
*
)
text
completion
:(
nonnull
MLKTranslatorCallback
)
completion
;
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.
|
-
Declaration
Objective-C
-
(
nonnull
instancetype
)
init
;
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\u003eMLKTranslator\u003c/code\u003e is an Objective-C class that provides on-device translation capabilities.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to translate text, download necessary model files, and manage download conditions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etranslatorWithOptions:\u003c/code\u003e method is used to obtain an instance of the translator with specified options.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003etranslateText:completion:\u003c/code\u003e translates the given text from the source language to the target language.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003edownloadModelIfNeededWithCompletion:\u003c/code\u003e or \u003ccode\u003edownloadModelIfNeededWithConditions:completion:\u003c/code\u003e can be used to download the required language model files if they are not already available on the device.\u003c/p\u003e\n"]]],["The `MLKTranslator` class translates text between languages. Key actions include: obtaining a `Translator` instance via `translatorWithOptions:`, providing translator options; translating text using `translateText:completion:`, which takes a text string and a completion handler; downloading necessary model files with `downloadModelIfNeededWithCompletion:`; and conditionally downloading files with `downloadModelIfNeededWithConditions:completion:`, specifying download criteria. If a model is not downloaded, the `translateText` action returns an error. Lastly, the default initializer `init` is unavailable.\n"],null,["# MLKitTranslate Framework Reference\n\nMLKTranslator\n=============\n\n\n @interface MLKTranslator : NSObject\n\nA class that translates the given input text.\n- `\n ``\n ``\n `\n\n ### [+translatorWithOptions:](#/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 Objective-C \n\n + (nonnull MLKTranslator *)translatorWithOptions:\n (nonnull ../Classes/MLKTranslatorOptions.html *)options;\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 ### [-translateText: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 Objective-C \n\n - (void)translateText:(nonnull NSString *)text\n completion:(nonnull ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorCallback)completion;\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 ### [-downloadModelIfNeededWithCompletion:](#/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 Objective-C \n\n - (void)downloadModelIfNeededWithCompletion:\n (nonnull ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorDownloadModelIfNeededCallback)completion;\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 ### [-downloadModelIfNeededWithConditions: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 Objective-C \n\n - (void)\n downloadModelIfNeededWithConditions:\n (nonnull MLKModelDownloadConditions *)conditions\n completion:\n (nonnull\n ../Type-Definitions.html#/c:MLKTranslator.h@T@MLKTranslatorDownloadModelIfNeededCallback)\n completion;\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. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull instancetype)init;"]]