Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/Help.awk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getVersion( build, gitHead) {
sprintf("%-22s%s\n", "terminal type", ENVIRON["TERM"]) \
sprintf("%-22s%s (%s)\n", "user locale", UserLocale, getName(UserLang)) \
sprintf("%-22s%s\n", "home language", Option["hl"]) \
sprintf("%-22s%s\n", "source language", Option["sl"]) \
sprintf("%-22s%s\n", "source language", join(Option["sls"], "+")) \
sprintf("%-22s%s\n", "target language", join(Option["tl"], "+")) \
sprintf("%-22s%s\n", "translation engine", Option["engine"]) \
sprintf("%-22s%s\n", "proxy", Option["proxy"] ? Option["proxy"] :
Expand All @@ -42,7 +42,7 @@ function getVersion( build, gitHead) {
function getHelp() {
return "Usage: " ansi("bold", Command) \
" [" ansi("underline", "OPTIONS") "]" \
" [" ansi("underline", "SOURCE") "]" \
" [" ansi("underline", "SOURCES") "]" \
":[" ansi("underline", "TARGETS") "]" \
" [" ansi("underline", "TEXT") "]..." RS \
RS "Information options:" RS \
Expand Down Expand Up @@ -166,13 +166,13 @@ function getHelp() {
", " ansi("bold", "-hl ") ansi("underline", "CODE") \
", " ansi("bold", "-lang ") ansi("underline", "CODE")) RS \
ins(2, "Specify your home language.") RS \
ins(1, ansi("bold", "-s ") ansi("underline", "CODE") \
", " ansi("bold", "-sl ") ansi("underline", "CODE") \
", " ansi("bold", "-source ") ansi("underline", "CODE") \
", " ansi("bold", "-from ") ansi("underline", "CODE")) RS \
ins(2, "Specify the source language.") RS \
ins(1, ansi("bold", "-s ") ansi("underline", "CODES") \
", " ansi("bold", "-sl ") ansi("underline", "CODES") \
", " ansi("bold", "-source ") ansi("underline", "CODES") \
", " ansi("bold", "-from ") ansi("underline", "CODES")) RS \
ins(2, "Specify the source language(s), joined by '+'.") RS \
ins(1, ansi("bold", "-t ") ansi("underline", "CODES") \
", " ansi("bold", "-tl ") ansi("underline", "CODE") \
", " ansi("bold", "-tl ") ansi("underline", "CODES") \
", " ansi("bold", "-target ") ansi("underline", "CODES") \
", " ansi("bold", "-to ") ansi("underline", "CODES")) RS \
ins(2, "Specify the target language(s), joined by '+'.") RS \
Expand Down
22 changes: 14 additions & 8 deletions include/Main.awk
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function init() {
# Language preference
Option["hl"] = ENVIRON["HOME_LANG"] ? ENVIRON["HOME_LANG"] : UserLang
Option["sl"] = ENVIRON["SOURCE_LANG"] ? ENVIRON["SOURCE_LANG"] : "auto"
Option["sls"][1] = Option["sl"]
Option["tl"][1] = ENVIRON["TARGET_LANG"] ? ENVIRON["TARGET_LANG"] : UserLang
}

Expand Down Expand Up @@ -632,12 +633,14 @@ BEGIN {
continue
}

# -s CODE, -sl CODE, -source CODE, -f CODE, -from CODE
# -s CODES, -sl CODES, -source CODES, -f CODES, -from CODES
match(ARGV[pos], /^--?(s(o(u(r(ce?)?)?)?|l)?|f|from)(=(.*)?)?$/, group)
if (RSTART) {
Option["sl"] = group[6] ?
(group[7] ? group[7] : Option["sl"]) :
ARGV[++pos]
if (group[6]) {
if (group[7]) split(group[7], Option["sls"], "+")
} else
split(ARGV[++pos], Option["sls"], "+")
Option["sl"] = Option["sls"][1]
continue
}

Expand All @@ -653,10 +656,13 @@ BEGIN {

# Shortcut format
# 'CODE:CODE+...' or 'CODE=CODE+...'
match(ARGV[pos], /^[{(\[]?([[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?(:|=)((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)[})\]]?$/, group)
match(ARGV[pos], /^[{(\[]?((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)?(:|=)((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)[})\]]?$/, group)
if (RSTART) {
if (group[1]) Option["sl"] = group[1]
if (group[4]) split(group[4], Option["tl"], "+")
if (group[1]) {
split(group[1], Option["sls"], "+")
Option["sl"] = Option["sls"][1]
}
if (group[7]) split(group[7], Option["tl"], "+")
continue
}

Expand Down Expand Up @@ -748,7 +754,7 @@ BEGIN {
if (Option["verbose"] && i > pos)
p(prettify("source-seperator", replicate(Option["chr-source-seperator"], Option["width"])))

translate(noargv[i], 1) # inline mode
translates(noargv[i], 1) # inline mode
}

# If input not specified, we're done
Expand Down
32 changes: 22 additions & 10 deletions include/REPL.awk
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ function prompt( i, p, temp) {
if (p ~ /%L/)
gsub(/%L/, getName(Option["hl"]), p)

# %s : source language
# %s : source languages, separated by "+"
# 's' is the format-control character for string

# %S : source language (English name)
if (p ~ /%S/)
gsub(/%S/, getName(Option["sl"]), p)
# %S : source languages (English names), seperated by "+"
if (p ~ /%S/) {
temp = getName(Option["sls"][1])
for (i = 2; i <= length(Option["sls"]); i++)
temp = temp "+" getName(Option["sls"][i])
gsub(/%S/, temp, p)
}

# TODO: source languages separated by "," and "/"

# %t : target languages, separated by "+"
if (p ~ /%t/) {
Expand Down Expand Up @@ -120,8 +126,11 @@ function prompt( i, p, temp) {
gsub(/%\?/, temp, p)
}

# %s : source language
printf(prettify("prompt", p), getDisplay(Option["sl"])) > STDERR
# %s : source languages, separated by "+"
temp = getDisplay(Option["sls"][1])
for (i = 2; i <= length(Option["sls"]); i++)
temp = temp "+" getDisplay(Option["sls"][i])
printf(prettify("prompt", p), temp) > STDERR
}

# REPL.
Expand All @@ -143,16 +152,19 @@ function repl(line, command, group, name, i, value, words) {
Option["engine"] = value
initHttpService()
} else {
match(command, /^[{(\[]?([[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?(:|=)((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)[})\]]?$/, group)
match(command, /^[{(\[]?((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)?(:|=)((@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?\+)*(@?[[:alpha:]][[:alpha:]][[:alpha:]]?(-[[:alpha:]][[:alpha:]][[:alpha:]]?[[:alpha:]]?)?)?)[})\]]?$/, group)
if (RSTART) {
if (group[1]) Option["sl"] = group[1]
if (group[4]) split(group[4], Option["tl"], "+")
if (group[1]) {
split(group[1], Option["sls"], "+")
Option["sl"] = Option["sls"][1]
}
if (group[7]) split(group[7], Option["tl"], "+")
line = words[2]
for (i = 3; i <= length(words); i++)
line = line " " words[i]
}
if (line) {
translate(line)
translates(line)

# Interactive verbose mode: newline after each translation
if (Option["verbose"]) printf RS
Expand Down
20 changes: 19 additions & 1 deletion include/Translate.awk
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ function translate(text, inline,
PROCINFO["sorted_in"] = saveSortedIn
}

# Translate the source text (from all source languages).
function translates(text, inline,
####
i) {
saveSortedIn = PROCINFO["sorted_in"]
PROCINFO["sorted_in"] = "@ind_num_asc"
for (i in Option["sls"]) {
# Non-interactive verbose mode: separator between sources
if (!Option["interactive"])
if (Option["verbose"] && i > 1)
p(prettify("target-seperator", replicate(Option["chr-target-seperator"], Option["width"])))

Option["sl"] = Option["sls"][i]
translate(text, inline)
}
PROCINFO["sorted_in"] = saveSortedIn
}

# Read from input and translate each line.
function translateMain( i, line) {
if (Option["interactive"])
Expand All @@ -342,7 +360,7 @@ function translateMain( i, line) {
if (Option["interactive"])
repl(line)
else
translate(line)
translates(line)
} else {
# Non-interactive brief mode: preserve line breaks
if (!Option["interactive"])
Expand Down
16 changes: 8 additions & 8 deletions man/trans.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.4
.\" Automatically generated by Pandoc 2.5
.\"
.TH "TRANS" "1" "2018\-12\-23" "0.9.6.9" ""
.hy
Expand Down Expand Up @@ -311,12 +311,13 @@ This option is optional.
When its setting is omitted, English will be used.
.PP
This option overrides the setting of environment variables
$\f[B]LANGUAGE\f[R], $\f[B]LC_ALL\f[R], $\f[B]LANG\f[R] and
$\f[B]HOME_LANG\f[R].
$\f[B]LC_ALL\f[R], $\f[B]LANG\f[R], and $\f[B]HOME_LANG\f[R].
.RE
.TP
.B \f[B]\-s\f[R] \f[I]CODE\f[R], \f[B]\-sl\f[R] \f[I]CODE\f[R], \f[B]\-source\f[R] \f[I]CODE\f[R], \f[B]\-from\f[R] \f[I]CODE\f[R]
Specify the source language (the language of original text).
.B \f[B]\-s\f[R] \f[I]CODES\f[R], \f[B]\-sl\f[R] \f[I]CODES\f[R], \f[B]\-source\f[R] \f[I]CODES\f[R], \f[B]\-from\f[R] \f[I]CODES\f[R]
Specify the source language(s) (the language(s) of original text).
When specifying two or more language codes, concatenate them by plus
sign \[dq]+\[dq].
.RS
.PP
This option is optional.
Expand All @@ -327,7 +328,7 @@ This option overrides the setting of environment variable
$\f[B]SOURCE_LANG\f[R].
.RE
.TP
.B \f[B]\-t\f[R] \f[I]CODES\f[R], \f[B]\-tl\f[R] \f[I]CODE\f[R], \f[B]\-target\f[R] \f[I]CODES\f[R], \f[B]\-to\f[R] \f[I]CODES\f[R]
.B \f[B]\-t\f[R] \f[I]CODES\f[R], \f[B]\-tl\f[R] \f[I]CODES\f[R], \f[B]\-target\f[R] \f[I]CODES\f[R], \f[B]\-to\f[R] \f[I]CODES\f[R]
Specify the target language(s) (the language(s) of translated text).
When specifying two or more language codes, concatenate them by plus
sign \[dq]+\[dq].
Expand All @@ -337,8 +338,7 @@ This option is optional.
When its setting is omitted, everything will be translated into English.
.PP
This option overrides the setting of environment variables
$\f[B]LANGUAGE\f[R], $\f[B]LC_ALL\f[R], $\f[B]LANG\f[R] and
$\f[B]TARGET_LANG\f[R].
$\f[B]LC_ALL\f[R], $\f[B]LANG\f[R], and $\f[B]TARGET_LANG\f[R].
.RE
.TP
.B [\f[I]SOURCE\f[R]]:[\f[I]TARGETS\f[R]]
Expand Down
10 changes: 5 additions & 5 deletions man/trans.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,21 @@ If neither *TEXT* nor the input file is specified by command-line arguments, the

This option is optional. When its setting is omitted, English will be used.

This option overrides the setting of environment variables $**LANGUAGE**, $**LC_ALL**, $**LANG** and $**HOME_LANG**.
This option overrides the setting of environment variables $**LC_ALL**, $**LANG**, and $**HOME_LANG**.

**-s** *CODE*, **-sl** *CODE*, **-source** *CODE*, **-from** *CODE*
: Specify the source language (the language of original text).
**-s** *CODES*, **-sl** *CODES*, **-source** *CODES*, **-from** *CODES*
: Specify the source language(s) (the language(s) of original text). When specifying two or more language codes, concatenate them by plus sign "+".

This option is optional. When its setting is omitted, the language of original text will be identified automatically (with a possibility of misidentification).

This option overrides the setting of environment variable $**SOURCE_LANG**.

**-t** *CODES*, **-tl** *CODE*, **-target** *CODES*, **-to** *CODES*
**-t** *CODES*, **-tl** *CODES*, **-target** *CODES*, **-to** *CODES*
: Specify the target language(s) (the language(s) of translated text). When specifying two or more language codes, concatenate them by plus sign "+".

This option is optional. When its setting is omitted, everything will be translated into English.

This option overrides the setting of environment variables $**LANGUAGE**, $**LC_ALL**, $**LANG** and $**TARGET_LANG**.
This option overrides the setting of environment variables $**LC_ALL**, $**LANG**, and $**TARGET_LANG**.

[*SOURCE*]:[*TARGETS*]
: A simpler, alternative way to specify the source language and target language(s) is to use a shortcut formatted string:
Expand Down
10 changes: 5 additions & 5 deletions man/trans.1.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,21 @@ If neither *TEXT* nor the input file is specified by command-line arguments, the

This option is optional. When its setting is omitted, English will be used.

This option overrides the setting of environment variables $**LANGUAGE**, $**LC_ALL**, $**LANG** and $**HOME_LANG**.
This option overrides the setting of environment variables $**LC_ALL**, $**LANG**, and $**HOME_LANG**.

**-s** *CODE*, **-sl** *CODE*, **-source** *CODE*, **-from** *CODE*
: Specify the source language (the language of original text).
**-s** *CODES*, **-sl** *CODES*, **-source** *CODES*, **-from** *CODES*
: Specify the source language(s) (the language(s) of original text). When specifying two or more language codes, concatenate them by plus sign "+".

This option is optional. When its setting is omitted, the language of original text will be identified automatically (with a possibility of misidentification).

This option overrides the setting of environment variable $**SOURCE_LANG**.

**-t** *CODES*, **-tl** *CODE*, **-target** *CODES*, **-to** *CODES*
**-t** *CODES*, **-tl** *CODES*, **-target** *CODES*, **-to** *CODES*
: Specify the target language(s) (the language(s) of translated text). When specifying two or more language codes, concatenate them by plus sign "+".

This option is optional. When its setting is omitted, everything will be translated into English.

This option overrides the setting of environment variables $**LANGUAGE**, $**LC_ALL**, $**LANG** and $**TARGET_LANG**.
This option overrides the setting of environment variables $**LC_ALL**, $**LANG**, and $**TARGET_LANG**.

[*SOURCE*]:[*TARGETS*]
: A simpler, alternative way to specify the source language and target language(s) is to use a shortcut formatted string:
Expand Down