TextTranslator provides a common interface for Text translation services implementing the TextTranslationService
protocol.
The TextTranslator does not work on it's own but needs an implementation of TextTranslationService
. Right now there is only one known implementation:
Name | Package |
---|---|
MSTTS | included in https://github.com/helsingborg-stad/spm-ms-cognitive-services |
You can either use TextTranslator
singleton or use a concrete implementation of TextTranslatorService
as is.
let translator = TextTranslator(service: MyTextTranslatorService())
let strings = ["My untranslated text"]
let dictionary = ["my_key":"My untranslated text"]
translator.translate(strings, from: "se", to: ["en"]).sink { compl in
if case let .failure(error) = compl {
debugPrint(error)
}
} receiveValue: { table in
print(table.value(forKey:"My untranslated text", in:"en"))
}.store(in: &cancellables)
translator.translate(dictionary, from: "se", to: ["en"]).sink { compl in
if case let .failure(error) = compl {
debugPrint(error)
}
} receiveValue: { table in
print(table.value(forKey:"my_key", in:"en"))
}.store(in: &cancellables)
If you wish to take your translations to the next level you should have a look at Dragoman.
The tests does not cover a concrete implementation of a TextTranslationService
, only the TextTranslationTable
and the TextTranslator
singleton.
- add list of available services
- code-documentation
- write tests
- complete package documentation