App-xlate
view release on metacpan or search on metacpan
script/xlate view on Meta::CPAN
done
return 1
}
##
## Make
##
if [[ $run_make == yes ]]
then
declare -a opt
for m in "$@"
do
if [[ -f $m ]]
then
# GNU Make behaves differently in different versions with
# respect to double-quoted strings and spaces within them.
files="${files:+$files|||}$m"
else
opt+=("$m")
fi
done
unset MAKELEVEL
gmake=$(find_gmake) || { warn "GNU Make is required."; exit 1; }
exec $gmake -f $share/XLATE.mk \
${dryrun:+-n} \
XLATE_LANG=\""$tgt_lang"\" \
XLATE_DEBUG=$debug \
XLATE_MAXLEN=$max \
XLATE_USEAPI=$use_api \
XLATE_UPDATE=$update \
${engine:+XLATE_ENGINE=\""$engine"\"} \
${format:+XLATE_FORMAT=\""$format"\"} \
${files:+XLATE_FILES=\""$files"\"} \
${opt[@]} \
|| exit 1
fi
if [[ ! $tgt_lang ]]
then
warn "$myname: -t option is required."
exit 1
fi
: ${format:=xtxt}
: ${engine:=deepl}
if [[ $format =~ ^(.+)-fold$ ]]
then
format=${BASH_REMATCH[1]}
: ${wrap:=76}
fi
declare -a module option
module+=(-Mxlate)
option+=(--xlate-engine="$engine")
option+=(--xlate-to="$tgt_lang" --xlate-format="$format" --xlate-cache=yes)
option+=(--all)
[[ $base_lang ]] && option+=(--xlate-from "$base_lang")
[[ $use_api == yes ]] || use_clipboard=yes
[[ $check == yes ]] || option+=(--xlate${use_clipboard:+-labor})
[[ $wrap ]] && option+=(--xlate-fold-line --xlate-fold-width=$wrap)
[[ $debug == yes ]] && option+=(-dmo)
[[ $refresh == yes ]] && option+=(--xlate-cache=clear)
[[ $update == yes ]] && option+=(--xlate-update)
[[ $silent == yes ]] && option+=(--no-xlate-progress)
[[ $max ]] && option+=(--xlate-maxlen="$max")
[[ $maskfile ]] && option+=(--xlate-setopt "maskfile=$maskfile")
[[ $glossary ]] && option+=(--xlate-glossary "$glossary")
declare -a area
case $1 in
*.txt)
area=(-E '^(.+\n)+')
;;
*.md)
area=(-E '(?x) ^[-+#].*\n | ^\h+\K.*\n | ^(.+\n)+ ')
;;
*.pm|*.pod)
module+=(-Mperl)
option+=(--pod)
option+=(--exclude '^=head\d +(VERSION|AUTHOR|LICENSE|COPYRIGHT|SEE.?ALSO).*\n(?s:.*?)(?=^=|\z)')
area=(-E '^([\w\pP].+\n)+')
;;
*.doc|*.docx|*.pptx|*.xlsx)
module+=(-Mmsdoc)
;&
*.stxt)
option+=(--exclude '^\[.*\b(doc|docx|pptx|xlsx)\b.*\]\n')
area=(-E '^.+\n')
;;
*)
area=(-E '^(.+\n)+')
;;
esac
if (( ${#pattern[@]} > 0))
then
option+=("${pattern[@]}")
else
option+=("${area[@]}")
fi
exec=(greple "${module[@]}" "${option[@]}" ${1+"$@"})
[[ $dryrun ]] && exec=(echo "${exec[@]}")
exec "${exec[@]}"
exit 1
: <<'=cut'
=head1 DESCRIPTION
B<XLATE> is a versatile command-line tool designed as a user-friendly
frontend for the B<greple> C<-Mxlate> module, simplifying the process
of multilingual automatic translation using various API services. It
streamlines the interaction with the underlying module, making it
easier for users to handle diverse translation needs across multiple
file formats and languages.
script/xlate view on Meta::CPAN
existing container is removed.
=end comment
=back
=head1 ENVIRONMENT
=over 4
=item DEEPL_AUTH_KEY
DeepL API key.
=item OPENAI_API_KEY
OpenAI API key.
=item ANTHROPIC_API_KEY
Anthropic API key.
=item LLM_PERPLEXITY_KEY
Perplexity API key.
=back
=head1 FILES
=over 4
=item F<*.LANG>
Specifies translation languages.
=item F<*.FORMAT>
Specifies translation format.
=item F<*.ENGINE>
Specifies translation engine.
=back
=head1 EXAMPLES
1. Translate a Word document to English:
xlate -DMa -t EN-US example.docx
2. Translate to multiple languages and formats:
xlate -M -o 'xtxt ifdef' -t 'EN-US KO ZH' example.docx
3. Run a command in Docker container:
xlate -C sdif -V --nocdif example.EN-US.cm
4. Translate without using API (via clipboard):
xlate -t JA README.md
=head1 SEE ALSO
L<App::Greple::xlate>
=head1 AUTHOR
Kazumasa Utashiro
=head1 LICENSE
Copyright © 2023-2025 Kazumasa Utashiro.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# LocalWords: xlate ubuntu
( run in 2.229 seconds using v1.01-cache-2.11-cpan-2398b32b56e )