App-Greple-xlate
view release on metacpan or search on metacpan
i18n/src/xlate.pod view on Meta::CPAN
=item B<ifdef>
Original and converted text are printed in L<cpp(1)> C<#ifdef>
format.
#ifdef ORIGINAL
original text
#endif
#ifdef JA
translated Japanese text
#endif
You can retrieve only Japanese text by the B<unifdef> command:
unifdef -UORIGINAL -DJA foo.ja.pm
=item B<space>
=item B<space+>
Original and converted text are printed separated by single blank
line. For C<space+>, it also outputs a newline after the converted
text.
=item B<xtxt>
If the format is C<xtxt> (translated text) or unkown, only translated
text is printed.
=back
=item B<--xlate-maxlen>=I<chars> (Default: 0)
Specify the maximum length of text to be sent to the API at once.
The default value 0 means the engine's own limit: for the free DeepL
account service that is 128K for the API (B<--xlate>) and 5000 for
the clipboard interface (B<--xlate-labor>). You may be able to
change these value if you are using Pro service.
=item B<--xlate-maxline>=I<n> (Default: 0)
Specify the maximum lines of text to be sent to the API at once.
Set this value to 1 if you want to translate one line at a time. This
option takes precedence over the C<--xlate-maxlen> option.
=item B<--xlate-prompt>=I<text>
Specify a custom prompt to be sent to the translation engine. This
option is available for the LLM engines (C<gpt3>, C<gpt4o>, C<gpt5>)
but not for DeepL. You can customize the translation behavior by
providing specific instructions to the AI model. If the prompt
contains C<%s>, it will be replaced with the target language name.
=item B<--xlate-context>=I<text>
Specify additional context information to be sent to the translation
engine. This option can be used multiple times to provide multiple
context strings. The context information helps the translation engine
understand the background and produce more accurate translations.
=item B<--xlate-context-window>=I<n>
(Context-aware engines only, e.g. C<gpt5> on the llm backend)
Number of surrounding translated blocks passed as reference context
when re-translating changed blocks (default 2). The context also
includes the raw source text around the changed region (headings,
list structure, captions) and, when available, the previous version
of the changed text recovered from the cache, so that unchanged
wording is preserved. Set to 0 to disable context-aware translation
entirely.
Note that each changed region is translated in its own API call and
the context can add up to about 8000 characters to the system
prompt, so context-aware translation trades some extra cost for
consistency.
=item B<--xlate-cache-seed>=I<file>
Initialize a new document's cache from another document's cache
file. Useful for periodic reports: seed the new issue's cache with
the previous issue's, so unchanged paragraphs are not re-translated
and edited paragraphs keep the previous issue's wording. The seed
is used only when the target cache is empty; otherwise it is
ignored with a warning. With the default C<--xlate-cache=auto>, specifying a seed also
implies creating the new document's cache file.
=item B<--xlate-anonymize>=I<file>
Anonymize sensitive strings before they are sent to the translation
API, and restore them in the output. The dictionary file gives one
entry per item: in JSON (canonical, machine-generatable)
[ { "category": "person", "text": "å±±ç°å¤ªé" },
{ "category": "company", "regex": "ã¢ã¯ã¡(æ ªå¼ä¼ç¤¾)?" } ]
or in a simple line format (C<category pattern>, C</.../> for regex).
Each item is replaced by a category tag such as C<< <person id=1 /> >>;
the same string always gets the same tag, so the model can keep track
of who is who. Unknown JSON fields are ignored, so generators (e.g. a
local LLM extracting entities) may add their own annotations.
Category C<lit> is reserved. Local cache files still store restored
plain text: the concealment target is API transmission only.
A dictionary can be generated by an external tool -- for example a
local model extracting sensitive entities:
llm -m <local-model> \
-s 'Extract sensitive entities as a JSON array of objects
with "category" and "text" fields.' \
< report.md > report.anon.json
greple -Mxlate --xlate-anonymize=report.anon.json ...
A UTF-8 BOM in the file is tolerated. Values in the front matter
line format may carry a trailing comment only on their own line, not
after the value.
=item B<--xlate-anonymize-mark>[=I<regex>]
Collect anonymization entries from inline marks in the document
itself. Mark the first occurrence like C<{{ person("å±±ç°å¤ªé") }}>
i18n/src/xlate.pod view on Meta::CPAN
document: a string marked in one input file is not concealed in
another file of the same run (unlike front matter values, which
accumulate across files).
=item B<--xlate-template>[=I<regex>]
Treat template expressions (default: Jinja2 C<{{ ... }}>,
C<{% ... %}>, C<{# ... #}>) as opaque placeholders: instruct the
model to copy them unchanged and verify, per block, that the response
contains exactly the same expressions, each the same number of times.
Their order may change, since translation legitimately reorders them
to follow the target language word order. A broken expression
aborts the run; the cache is checkpointed and frozen, so nothing paid
for is lost.
Note that with an optional-value option like this, a following
file argument would be taken as the value: write
C<--xlate-template=> (with a trailing C<=>) when using the
default notation.
=item B<--xlate-frontmatter>
Treat a leading C<---> ... C<---> block as YAML front matter: exclude
it from translation and from the phase-2 context slices, and add its
flat C<key: value> values to the anonymization rules (category
C<var>) as a safety net. With multiple input files the collected
values accumulate (erring on the side of concealment).
Always leave a blank line after the closing C<--->. With a
paragraph-style match pattern, front matter that runs directly into
the body text forms one straddling block that the exclusion cannot
suppress (a warning is printed in that case); the values are still
anonymized, but the front matter itself would be sent for
translation.
=item B<--xlate-glossary>=I<glossary>
Specify a glossary ID to be used for translation. This option is only
available when using the DeepL engine. The glossary ID should be obtained
from your DeepL account and ensures consistent translation of specific terms.
=item B<--xlate-dryrun>
Do not call the translation API; instead show, through the progress
display, each payload exactly as it would be transmitted (after
anonymization and masking). Useful for checking what leaves the
machine and for estimating the cost of a run.
=item B<-->[B<no->]B<xlate-progress> (Default: True)
See the translation result in real time in the STDERR output. The
C<From> payload is shown as transmitted, after anonymization and
masking.
=item B<--xlate-stripe>
Use L<App::Greple::stripe> module to show the matched part by zebra
striping fashion. This is useful when the matched parts are connected
back-to-back.
The color palette is switched according to the background color of the
terminal. If you want to specify explicitly, you can use
B<--xlate-stripe-light> or B<--xlate-stripe-dark>.
=item B<--xlate-mask>
Perform masking function and display the converted text as is without
restoration.
=item B<--match-all>
Set the whole text of the file as a target area.
=item B<--lineify-cm>
=item B<--lineify-colon>
In the case of the C<cm> and C<colon> formats, the output is split and
formatted line by line. Therefore, if only a portion of a line is to
be translated, the expected result cannot be obtained. These filters
fix output that is corrupted by translating part of a line into normal
line-by-line output.
In the current implementation, if multiple parts of a line are
translated, they are output as independent lines.
=back
=head1 CACHE OPTIONS
B<xlate> module can store cached text of translation for each file and
read it before execution to eliminate the overhead of asking to
server. With the default cache strategy C<auto>, it maintains cache
data only when the cache file exists for target file.
Use B<--xlate-cache=clear> to initiate cache management or to clean up
all existing cache data. Once executed with this option, a new cache
file will be created if one does not exist and then automatically
maintained afterward.
=over 7
=item --xlate-cache=I<strategy>
=over 4
=item C<auto> (Default)
Maintain the cache file if it exists.
=item C<create>
Create empty cache file and exit.
=item C<always>, C<yes>, C<1>
Maintain cache anyway as far as the target is normal file.
=item C<clear>
Clear the cache data first.
( run in 0.535 second using v1.01-cache-2.11-cpan-f4a522933cf )