App-Greple-xlate
view release on metacpan or search on metacpan
script/xlate view on Meta::CPAN
local make
(( $# == 0 )) && set make gmake gnumake
for make in "$@"
do
[[ $("$make" --version) =~ GNU ]] && { echo "$make"; return 0; }
done
return 1
}
##
## Make
##
if [[ ${make:-} ]]; 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=\""${to_lang:-}"\" \
XLATE_DEBUG=${debug:-} \
XLATE_MAXLEN=${maxlen:-} \
XLATE_USEAPI=${api:-} \
XLATE_UPDATE=${update:-} \
${engine:+XLATE_ENGINE=\""$engine"\"} \
${format:+XLATE_FORMAT=\""$format"\"} \
${files:+XLATE_FILES=\""$files"\"} \
"${opt[@]}" \
|| exit 1
fi
if [[ ! ${to_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="$to_lang" --xlate-format="$format" --xlate-cache=yes)
option+=(--all)
[[ ${from_lang:-} ]] && option+=(--xlate-from "$from_lang")
[[ ${api:-} ]] || use_clipboard=yes
[[ ${check:-} ]] || option+=(--xlate${use_clipboard:+-labor})
[[ ${wrap:-} ]] && option+=(--xlate-fold-line --xlate-fold-width=$wrap)
[[ ${trace:-} ]] && option+=(-dmo)
[[ ${refresh:-} ]] && option+=(--xlate-cache=clear)
[[ ${update:-} ]] && option+=(--xlate-update)
[[ ${silent:-} ]] && option+=(--no-xlate-progress)
[[ ${maxlen:-} ]] && option+=(--xlate-maxlen="$maxlen")
[[ ${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
# Build pattern options from -p and -f
declare -a pattern_opts=()
if (( ${#pattern[@]} > 0 )); then
for p in "${pattern[@]}"; do
pattern_opts+=(-E "$p")
done
fi
if (( ${#file[@]} > 0 )); then
for f in "${file[@]}"; do
pattern_opts+=(-f "$f")
done
fi
if (( ${#pattern_opts[@]} > 0 )); then
option+=("${pattern_opts[@]}")
else
option+=("${area[@]}")
fi
exec=(greple "${module[@]}" "${option[@]}" "$@")
[[ ${dryrun:-} ]] && exec=(echo "${exec[@]}")
exec "${exec[@]}"
exit 1
script/xlate view on Meta::CPAN
=item B<-O> I<option>, B<--other>=I<option>
Additional docker option. Repeatable.
=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>
L<App::dozo> - Generic Docker runner used by xlate for container operations
=head1 AUTHOR
Kazumasa Utashiro
=head1 LICENSE
Copyright © 2023-2026 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 0.474 second using v1.01-cache-2.11-cpan-2398b32b56e )