App-Greple-xlate

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

to compare on a per-string basis, the `--no-cdif` option is
recommended.  If you do not need to color the text, specify
`--no-textcolor` (or `--no-tc`).

    sdif -V --no-filename --no-tc --no-cdif data_shishin.deepl-EN-US.cm

<div>
    <p>
    <img width="750" src="https://raw.githubusercontent.com/kaz-utashiro/App-Greple-xlate/main/images/sdif-cm-view.png">
    </p>
</div>

# NORMALIZATION

Processing is done in specified units, but in the case of a sequence
of multiple lines of non-empty text, they are converted together into
a single line.  This operation is performed as follows:

- Remove white space at the beginning and end of each line.
- If a line ends with a full-width punctuation character, concatenate
with next line.
- If a line ends with a full-width character and the next line begins
with a full-width character, concatenate the lines.
- If either the end or the beginning of a line is not a full-width
character, concatenate them by inserting a space character.

Cache data is managed based on the normalized text, so even if
modifications are made that do not affect the normalization results,
the cached translation data will still be effective.

This normalization process is performed only for the first (0th) and
even-numbered pattern.  Thus, if two patterns are specified as
follows, the text matching the first pattern will be processed after
normalization, and no normalization process will be performed on the
text matching the second pattern.

    greple -Mxlate -E normalized -E not-normalized

Therefore, use the first pattern for text that is to be processed by
combining multiple lines into a single line, and use the second
pattern for pre-formatted text.  If there is no text to match in the
first pattern, use a pattern that does not match anything, such as
`(?!)`.

# MASKING

Occasionally, there are parts of text that you do not want translated.
For example, tags in markdown files. DeepL suggests that in such
cases, the part of the text to be excluded be converted to XML tags,
translated, and then restored after the translation is complete.  To
support this, it is possible to specify the parts to be masked from
translation.

    --xlate-setopt maskfile=MASKPATTERN

This will interpret each line of the file `MASKPATTERN` as a regular
expression, translate strings matching it, and revert after
processing.  Lines beginning with `#` are ignored.

Complex pattern can be written on multiple lines with backslash
escaped newline.

How the text is transformed by masking can be seen by **--xlate-mask**
option.

Masking protects markup from being translated.  To conceal sensitive
strings from the translation service itself, see ["ANONYMIZATION AND
TEMPLATES"](#anonymization-and-templates); both can be used together.

This interface is experimental and subject to change in the future.

# ANONYMIZATION AND TEMPLATES

Sensitive strings can be concealed before they are sent to the
translation API and restored in the output.  Three sources of
anonymization rules are available: a dictionary file
(**--xlate-anonymize**), inline marks in the document itself
(**--xlate-anonymize-mark**), and YAML front matter values
(**--xlate-frontmatter**).  Each string is replaced by a category tag
such as `<person id=1 />` during transmission.  The concealment
target is API transmission only: local cache files store restored
plain text.  Use **--xlate-dryrun** to inspect exactly what would be
transmitted.

For form documents (quarterly reports and the like), define the
actors up front and reference them in the body:

    ---
    報告者: 山田太郎
    発注会社: アクメ株式会社
    ---
    本件について {{ 報告者 }} が調査を行った。

Translate the template once per language with `--xlate-template`
(and `--xlate-frontmatter` when the values are kept in the file),
then render each case with **pandoc-embedz** standalone mode --
values under `global:` in an external config never reach the
translation API at all:

    greple -Mxlate --xlate --xlate-engine=gpt5 --xlate-to=EN-US \
           --xlate-template= --xlate-format=xtxt \
           --match-paragraph --all --need=0 \
           report-template.md > report-template.EN.md
    pandoc-embedz --standalone report-template.EN.md \
                  -c case-123.yaml -o report-123.EN.md < /dev/null

For inline marks, providing a macro definition config makes the same
translated template render either the real names or a redacted
version:

    # macros.yaml           # macros-redacted.yaml
    preamble: |             preamble: |
      {% macro person(name) %}{{ name }}{% endmacro %}
                              {% macro person(name) %}(関係者){% endmacro %}

Exclude embedz blocks from translation when a document contains them:

    --exclude '^```embedz\n(?s:.*?)^```\n'

# OPTIONS



( run in 1.034 second using v1.01-cache-2.11-cpan-9581c071862 )