Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

6 Answers 6

up vote 26 down vote accepted

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.

share|improve this answer
1  
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
4  
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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
+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.

share|improve this answer
    
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.}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.