Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LC_ALL; (awk setlocale?); normal POSIX shell? #521

Open
sdaoden opened this issue Aug 28, 2024 · 3 comments
Open

LC_ALL; (awk setlocale?); normal POSIX shell? #521

sdaoden opened this issue Aug 28, 2024 · 3 comments

Comments

@sdaoden
Copy link

sdaoden commented Aug 28, 2024

Hello!
I just got pointed to this program by noone else but Nelson H. F. Beebe (after noting that dict.cc is so slow to access with the lynx text mode browser on the lynx list), who says he uses this for many purposes for many years, and so i tried it, and it is a really great tool to have. Thank you! (I have created a CRUX Linux package now, but i am no longer in "official" contrib, it is only in my private user repository .. that some people seem to access; anyhow).

So you can very well ignore the rest and close this "issue", i only stumbled upon it and thought i share that.

Iooked into the script, and i saw it looks for $LANG. Whereas that is ok, since many in the Linux world (GNU etc) document users should set that, $LANG is only a secondary switch, and i for example do not set it, but LC_ALL (this is also much much much faster). (C.UTF-8 is coming along, too, but checking for it would make installation more lengthy.)

It also seems bash is not really needed. Ie the following snippet should work just fine in any POSIX shell, and since the /usr/bin/trans thing is a cumulation generated via script the (possibly) necessary quoting in the manual page could very easily be done. This is just a quick hack, of course.

Ciao! And thanks for this tool!

y=en_US.UTF-8
if [ -n "$LC_ALL" ]; then x=$LC_ALL
elif [ -n "$LANG" ]; then x=$LANG
else x=
fi
if [ -n "$x" ] && [ "$x" != "${x%UTF*}" ]; then
        x=${x#*UTF}
        x=${x#*-}
        [ "$x" != 8 ] && x=$y || x=
else
        x=$y
fi
if [ -n "$x" ]; then
        LC_ALL=$x
        export LC_ALL
fi

TRANS_MANPAGE='
.TH "TRANS" "1" "2023\-02\-08" "0.9.7.1" ""
.hy
.SH NAME
.PP
trans \- yeah
.SH SYNOPSIS
dudia
'
export TRANS_MANPAGE

cat <<'EOT' | gawk -f - "$@"
function initPager() { Pager = "less" }
function showMan(    temp) {
PIPE=" | "
if (ENVIRON["TRANS_MANPAGE"]) {
initPager()
Groff = "/usr/bin/groff"
if (Pager && Groff) {
temp = "printf '%s' \"${TRANS_MANPAGE}\""
temp = temp PIPE\
Groff " -Wall -mtty-char -mandoc -Tutf8 "
temp = temp PIPE\
Pager " -s -P\"\\ \\Manual page " Command "(1) line %lt (press h for help or q to quit)\""
}
system(temp)
}
}
BEGIN{showMan()}
EOT
@sdaoden
Copy link
Author

sdaoden commented Aug 28, 2024

(And have you ever thought on asking Arnold Robbins of gawk whether he would be interested to support switching the locale? If he does not do that already. He is a very friendly and helpful person. Btw on some boxes there is "mandoc" as a replacement of groff, just say "mandoc -Tutf8" and it will do the rest.)
But now really Ciao!

@sdaoden
Copy link
Author

sdaoden commented Aug 28, 2024

(Ah please wait, just one tiny addition: one can in fact "exec gawk" to pass execution over.)

@sdaoden
Copy link
Author

sdaoden commented Aug 29, 2024

(Oh, and one very very last final thing, even the cat is not needed, one can simply say

 ( <<'EOT' exec gawk -f -
> BEGIN{print "hi"}
> EOT
)
hi

so even that process is not necessary.
translate-shell is cool :) Ciao!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant