# Is it possible to keep my translation together with original text?

I have an English article in LaTeX, which I'm going to translate to Russian. I want to keep my translation in sync with the original text. It means that I want every paragraph to stay as close to its original version as possible. Ideally like this:

\documentclass{article}
\UseLanguage{English} % or Russian
\begin{document}
The technology described in the article is very complex.
\inRussian{Технология, описанная в статье, очень сложна.}
\end{document}


The preamble will specify which language to use and the document will be automatically compiled for this selected language. Is there any packages that will enable me to translate the article in such a way?

-

Define two macros, and swap their definitions as needed

\newcommand{\inRussian}[1]{#1}

\newcommand{\inEnglish}[1]{}


or define one macro

\newcommand{\EngOrRus}[2]{#1}


and change #1 to #2 when you want to switch language.

-
I really like this solution except for one bit: You have to change the source file and then re-run latex to produce two files. Is it possible to use a environment variable or something? So one could run "LATEX_LANG=en pdflatex foo.tex" to output foo_en.pdf? –  c089 Feb 26 '11 at 6:55
A solution to this can be found here: latex-community.org/forum/… –  c089 Feb 26 '11 at 7:17

I'd usually convert the LaTeX file to a PO file (using po2a) and use a dedicated translation tool like Virtaal, Russian LaTeX file can then be generated from the translated PO file. Later when the English is changed the translation can easily synced using standard PO merging tools. Well, it sounds too complicated but it is fairly scalable, besides I do things like that nearly daily, so that is my natural choice.

-
I have just came accross this thread and this is wonderful and clean solution –  Zbynek Jan 19 at 8:53
I love this solution but the po4a gettextize extracts also many formatting details. For example if there is a table, it extracts the entire blueprint of the table. Is there any way to help po4a extract only translatable strings? For example by surrounding them by some special command e.g. \tr{This string is to be translated.} –  Martin Drozdik Jan 24 at 19:14

You can use the comment package for this and define environments for each language. This supports longer text parts and might be more efficient as a macro.

\documentclass{article}
% (still needs font and input encoding for Russian text)
\usepackage{comment}
% change that the other way around to activate Russian language:
\includecomment{English}
\excludecomment{Russian}

\begin{document}
\begin{English}
The technology described in the article is very complex.
\end{English}
\begin{Russian}
Технология, описанная в статье, очень сложна.
\end{Russian}
\end{document}


Note that this seems not to work inside the documentation text of a DTX file, most likely because of the changed catcode of %. But this isn't relevant for normal documents like yours.

-

My answer has the same basic idea as Boris' answer, but uses tex's \if syntax, which to my taste gives cleaner source:

\documentclass{article}
\newif\ifenglish
\englishtrue % Show English text only
%\englishfalse will show Russian text only
\begin{document}
\ifenglish
The technology described in the article is very complex.
\else
Технология, описанная в статье, очень сложна.
\fi
\end{document}


Khaled's approach, using localisation, is the proper way to do it. XLIFF is a pretty widely used XML format; see XML in localisation: A practical analysis.

-
+1, I'm using this at the moment in a DTX file of mine, because the comment package (see my answer) doesn't work for that. –  Martin Scharrer Jan 31 '11 at 18:12

Suggestion to the old version of the question:

Perhaps either parallel or parcolumns can be helpful.

Suggestion to the new version of the question:

You could use the language of the document as some kind of switch. Here is an example from my archives.

\documentclass[11pt,a4paper,russian]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{ifthen}

\let\langname\languagename      % It doesn't work without this line

\begin{document}
\ifthenelse{%
\equal{\langname}{russian}
}{%
Russian                     % Put all necessary stuff for the Russian version here
}{%
English                     % Put all necessary stuff for the English version here
}
\end{document}


The language option for babel (here put into the options for the document class) controls which version of the document is compiled. Other helpful suggestions may come from the TeX FAQ.

-
Maybe I didn't explain it properly, I want my document to be in only one language, which I will select in preamble –  yegor256 Nov 8 '10 at 9:44
So it is. See my edits. –  Thorsten Donig Nov 8 '10 at 18:09

I know this question has already been answered, but I wanted to share my two cents.

I was searching for the same exact thing as yegor256, and starting from the pointers in other answers I put together a small sty file that fits my needs. It supports an arbitrary number of different languages in the same document.

%
% Environment settings
%

\newcommand{\setdoclang}[2]
{
\main@language{#2}
\def\doclang{#2}
\def\doclangshort{#1}
}

\setdoclang{en}{english}

%
% Multilingual support commands
%
\newcommand{\langif}[3]
{
\ifthenelse{\equal{#1}{\doclang} \or \equal{#1}{\doclangshort}}
{#2}
{#3}%
}
\newcommand{\lang}[2]{\langif{#1}{#2}{}}
\newcommand{\sectionlang}[2]{\lang{#1}{\section{#2}}}
\newcommand{\subsectionlang}[2]{\lang{#1}{\subsection{#2}}}
\newcommand{\subsubsectionlang}[2]{\lang{#1}{\subsubsection{#2}}}


It's useful because it synchronizes also the correct language for the babel package, such that your document will always have the correct locale settings. You just have to write a code like this in your tex:

% MULTILINGUAL SUPPORT
\usepackage[italian,english]{babel} %enables babel to every lang supported by your document
\usepackage{multilanguage} % import the file with the above definitions
\setdoclang{it}{italian} % set short and long language codes
% the second one must be known by babel
%\setdoclang{en}{english}
% END MULTILINGUAL SUPPORT


After that you can mix in your regular document parts that shows up in every language (i.e. document structure, images, ...) and parts that shows up only for certain languages, like this:

% Sections, subsections, subsubsections:
\sectionlang{it}{Sezione 1} % in the first parameter you can freely use
% both short or long language codes
\sectionlang{english}{Section 1}

% Strings that are displayed only in a certain language
\lang{it}{Questa stringa appare solo in italiano.}
\lang{en}{This string shows up only in English.}

% When you have only two languages, you can simply rely on this if-else
% construct
\langif{it}{If vero: questo e' italiano.}{Else: this is for any language
different from Italian.}

-