MLKitTranslate Framework Reference

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.

    Declaration

    Swift

      func 
     translate 
     ( 
     _ 
     text 
     : 
     String 
     , 
     completion 
     : 
     @escaping 
      TranslatorCallback 
     
     ) 
     
    

    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.

    Declaration

    Swift

      func 
     downloadModelIfNeeded 
     ( 
     completion 
     : 
     @escaping 
      TranslatorDownloadModelIfNeededCallback 
     
     ) 
     
    

    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.

    Declaration

    Swift

      func 
     downloadModelIfNeeded 
     ( 
     with 
     conditions 
     : 
     MLKModelDownloadConditions 
     , 
     completion 
     : 
     @escaping 
      TranslatorDownloadModelIfNeededCallback 
     
     ) 
     
    

    Parameters

    conditions

    The downloading conditions for the translate model.

    completion

    Handler to call back on the main queue with an error, if any.

  • Unavailable.

Create a Mobile Website
View Site in Mobile | Classic
Share by: