将文本翻译成另一种语言

将文本翻译成另一种语言

在此处输入图片描述我不确定这是否超出了 Latex 的功能,但是有没有办法将文档的纯文本翻译成另一种语言,而不必逐段进行?

我曾经研究过 Tortoise Tagger 和 omegaT,但却无法理解。

\documentclass{article}

\usepackage{blindtext}

\begin{document}

\blindtext

\vspace{1cm}
Can this be translated into another language? (Supposing of course it was in    English for example into Spanish), As well as keeping some maths work.

$5+4=9$

\end{document}

任何帮助都会很感激,即使这不是 Latex 想要做的。谢谢

进行编辑以尝试解释我所追求的内容。

\documentclass{article}

\begin{document}
%What I want to write:
This is how to Add $5+4$%%%%.  input


%%% Some code then...
to jak dodać $5+4$
%What it prints in Polish


$5+4=9$

\end{document}

答案1

以下是一个概念证明。其思路如下:

  1. 用文字框住要翻译的部分\begin{translate},然后\end{translate}
  2. 将此环境的内容收集到一个文件中
  3. 将所有单数转义\为双数,\\以避免 shell 控制序列在下一步中混淆翻译工具
  4. 使用此文件调用翻译工具并将翻译写入另一个文件
  5. 在 LaTeX 文档中输入其他文件

步骤 2 的实现由 Ulrike Fisher 在https://tex.stackexchange.com/a/2574/

对于步骤 4,我使用了translate-shellLinux,它支持 Google Translate、Bing、Apertium、Yandex 和许多非翻译引擎的拼写检查器(spell、aspell、hunspell)。对于步骤 3,我使用了sed

目标语言和源语言作为translate源环境的可选参数(默认英语)和目标环境的强制参数。

梅威瑟:

\documentclass{article}
\usepackage{xcolor}
\usepackage{shellesc}
\usepackage{environ}
\newwrite\myexport

\makeatletter
\NewEnviron{translate}[2][en]{%
% step 2
\toks@=\expandafter{\BODY}%
\immediate\openout\myexport=totrans.tex
\immediate\write\myexport{\the\toks@}
\immediate\closeout\myexport
% step 3
\ShellEscape{sed -i -e 's/\\/\\\\/g' totrans.tex}
% step 4
\ShellEscape{trans -b -i totrans.tex -o translated.tex #1:#2}
% step 5
\input{translated.tex}
}
\makeatother

\begin{document}
\begin{translate}[en]{es}
Can this be translated into another language? (Supposing of course it was in English for example into Spanish), As well as keeping some maths work.

The snippets can span multiple paragraphs.
\end{translate}

\section{Addition in Polish}

\begin{translate}{pl}
Addition in blue: \color{blue} This is how to Add $5+4$%%%%.  input
\end{translate}

$5+4=9$

\end{document}

结果:

在此处输入图片描述

免责声明:如果环境有一些复杂的处理(例如,如果存在逐字内容),以这种方式将环境内容保存到文件可能会中断。此外,翻译可能会影响宏名称或参数,尽管 Google 翻译似乎不会影响它们(请参阅\color{blue}MWE 中未翻译的部分)。当然,上面的步骤 3 也可能是问题的根源,尽管在翻译过程中重复的内容\\会被转换回来(即,blue: \\color{blue}被翻译为niebiesko: \color{blue})。

这里有一个错误,就是$5+4$被神秘地翻译成了 ,5 $ + 4 $这弄乱了空格。你可能需要试验一下如何输入,才能让代码在翻译后正确保留下来。

相关内容