1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
####################################################################
# Auto.awk #
####################################################################
BEGIN { provides("auto") }
function autoInit() {
}
function autoTTSUrl(text, tl) {
# TODO: support Bing
Option["engine"] = "google"
initHttpService()
return googleTTSUrl(text, tl)
# TODO: reset engine to auto
}
function autoWebTranslateUrl(uri, sl, tl, hl) {
# TODO: support Bing
Option["engine"] = "google"
initHttpService()
return googleWebTranslateUrl(uri, sl, tl, hl)
# TODO: reset engine to auto
}
function autoTranslate(text, sl, tl, hl,
isVerbose, toSpeech, returnPlaylist, returnIl,
####
engine, temp) {
if ((sl == "auto" || isSupportedByGoogle(sl)) && (tl == "auto" || isSupportedByGoogle(tl))) {
# both source and target languages are supported by Google
engine = Option["engine"] # auto
Option["engine"] = "google"
initHttpService()
temp = googleTranslate(text, sl, tl, hl, isVerbose, toSpeech, returnPlaylist, returnIl)
Option["engine"] = engine
} else if ((sl == "auto" || isSupportedByBing(sl)) && (tl == "auto" || isSupportedByBing(tl))) {
# both source and target languages are supported by Bing
engine = Option["engine"] # auto
Option["engine"] = "bing"
initHttpService()
temp = bingTranslate(text, sl, tl, hl, isVerbose, toSpeech, returnPlaylist, returnIl)
Option["engine"] = engine
} else {
# TODO: translate between Google-only and Bing-only languages
# fallback to Google
engine = Option["engine"] # auto
Option["engine"] = "google"
initHttpService()
temp = googleTranslate(text, sl, tl, hl, isVerbose, toSpeech, returnPlaylist, returnIl)
Option["engine"] = engine
}
return temp
}
|