1

I am trying to build a translator application in swift and for that I have decided to go with Google Translate Api. I was searching for ways to provide user with offline translation functionality. I was unable to find any documentation about the same.

Can anyone help me explore more on this issue and how to achieve it?

Him bhatt
  • 49
  • 5
  • Does this answer your question? [Offline language translation API](https://stackoverflow.com/questions/41425218/offline-language-translation-api) –  Jan 29 '20 at 10:24

1 Answers1

2

I believe you need to download the language files.

Have a look at this google translate Download languages to use offline

After a bit of research Google provide some thing called on-device translation. ML Kit's on-device translation API

According to the documentation you can download the files following

// Download the French model.
let frModel = TranslateRemoteModel.translateRemoteModel(language: .fr)

// Keep a reference to the download progress so you can check that the model
// is available before you use it.
progress = ModelManager.modelManager().download(
    frModel,
    conditions: ModelDownloadConditions(
        allowsCellularAccess: false,
        allowsBackgroundDownloading: true
    )
)

And to translate

englishGermanTranslator.translate(text) { translatedText, error in
    guard error == nil, let translatedText = translatedText else { return }

    // Translation succeeded.
}

References = Translate text with ML Kit on iOS

Also have a look at the Example Project Provided by google - Swift 5

chirag90
  • 2,211
  • 1
  • 22
  • 37
  • That documentation is for the Google translate Application and not for API as far as I understood it. I need to know if I can provide a download option for specific language pack to the user so that he can do translation without using internet . @chirag90 – Him bhatt Jan 29 '20 at 10:40
  • Well i would assume, you should ask the user which language do they need translating from, and use the downloaded file. Also this way you would supply the files with the application and not having to ask the user to download the file. If the user could download the file at the current time then why not just use the API with internet connection? – chirag90 Jan 29 '20 at 10:42
  • @chirag90 how to use downloaded language. if you have any documentation link or idea then suggest me. Thanks – ikbal Jan 29 '20 at 11:39
  • @Himbhatt does this answer your question? – chirag90 Jan 29 '20 at 13:26
  • @chirag90 Yeah thanks it kind off does. But I was looking for this feature with google translate api – Him bhatt Jan 30 '20 at 12:17