Reputation: 49
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?
Upvotes: 1
Views: 2256
Reputation: 2240
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
Upvotes: 2