File: Auto.awk

package info (click to toggle)
translate-shell 0.9.7.1-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 644 kB
  • sloc: awk: 7,183; lisp: 54; makefile: 38; sh: 22
file content (54 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (2)
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
}