9

I could not really find anything matching, maysome someone got an idea or a starting point:

I want to maintain a collection of documents written in Kile, Using LaTeX converted by xetex into pdf format. These documents have to be updated from time to time. I required each document to be available in two or three languages.

I do not want to maintain separate source files/collections for the different languages, since this will certainly lead to documents running out of sync. Instead I imagine something like this:

- each token of natural language ("phrase") will be enclosed in a macro
- the macro fetches the translation of the phrase from a local service
- this service could be a script reading translations from a file

Since there are applications suitable to maintain such phrase collections this appears to be a natural approach to me. However, I fail to find a good starting point..

arkascha
  • 261

3 Answers3

7

Using the iflang package it is possible to write a slightly cleaner command equivalent to the one in the previous answer:

\usepackage[ngerman,english]{babel}
%\usepackage[english,ngerman]{babel}

\usepackage{iflang}

\newcommand{\babel}[2]{\IfLanguageName{english}{#1}{#2}}
  • Interesting, thanks. I will take a look into it, though I currently do not have any documents maintained in LaTeX. Guess that will get interesting again for my next application ;-) – arkascha Nov 19 '18 at 06:44
  • @BrunoHass I am trying to understand how your code works and I am getting exactly the opposite choice of text for the macro \babel . For example, if I run your code above with the command \babel{Deutscher Text}{english text} I get the Deutscher Text while I believe the correct should be the english text. Would you be able to extend your code just a few lines that make it complete? – TeX Apprentice Dec 04 '21 at 20:15
7

Ok, I managed to put together my own solution by trying around and considering examples I found elsewhere. This is what I currently use, near the start of my project. It works fine so far:

%%%%%%%%%%%%%%%
% this is a document holding multiple languages
% switch between ENGLISH and GERMAN by commenting one of the following lines:
\usepackage[ngerman,english]{babel} % makes ENGLISH content
%\usepackage[english,ngerman]{babel} % makes GERMAN content
% this is the macro to define phrases in two languages:
\newcommand{\babel}[2]{\ifnum\pdfstrcmp{\languagename}{english}=0 {#2}\else{#1}\fi}
\newcommand{\babelDE}[1]{\ifnum\pdfstrcmp{\languagename}{ngerman}=0 {#1}\fi}
\newcommand{\babelEN}[1]{\ifnum\pdfstrcmp{\languagename}{english}=0 {#1}\fi}
% example:   \babel{Deutscher Text}{english text}
% example:   \babelDE{deutscher Text}
% example:   \babelEN{english text}
%%%%%%%%%%%%%%%
egreg
  • 1,121,712
arkascha
  • 261
0

I had a similar problem and @KJO suggested the catchfilebetweentags package as described in https://tex.stackexchange.com/a/4952/170109. It worked for me.

  • Could you please add more context to your answer? Otherwise this is only a link-only answer and will be deleted. –  Apr 14 '19 at 14:47
  • I think there is no need of a context. I answered to @arkasha's question. I think anyone can go to the link. If not please delete my answer. – nino_user183677 Apr 14 '19 at 16:07
  • Then you can post that answer here. –  Apr 14 '19 at 16:08