14

Is there an option which changes default title of table of contents in Org mode?
My document is not in English so I want to translate table of content's title.


Answer

As JeanPierre said, It's about export settings. You can set LANGUAGE at the top of your org document this way:

#+LANGUAGE: fr

And French will be used as default language of all strings that org produces during export.
The constant responsible for translation mappings is org-export-dictionary in ox.el and if your language is not supported you can drop it there and then eval-defun to let change take place. In my case:

(defconst org-export-dictionary 
    ...   
    ("Table of Contents"
         ...
         ("sr" :html "Sadržaj" :utf-8 "Sadržaj")
         ...)
    ...)

I've wrote a naive function which can be useful in init.el:

(defun org-export-translate-to-lang (term-translations &optional lang)
  "Adds desired translations to `org-export-dictionary'.
   TERM-TRANSLATIONS is alist consisted of term you want to translate
   and its corresponding translation, first as :default then as :html and
   :utf-8. LANG is language you want to translate to."
  (dolist (term-translation term-translations)
    (let* ((term (car term-translation))
           (translation-default (nth 1 term-translation))
           (translation-html (nth 2 term-translation))
           (translation-utf-8 (nth 3 term-translation))
           (term-list (assoc term org-export-dictionary))
           (term-langs (cdr term-list)))
      (setcdr term-list (append term-langs
                                (list
                                 (list lang
                                       :default translation-default
                                       :html translation-html
                                       :utf-8 translation-utf-8)))))))

(org-export-translate-to-lang '(("Table of Contents"
                                 "Sadržaj"
                                 "Sadržaj"
                                 "Sadržaj")
                                ("Another term"
                                 "coilogji"))
                              "sr")

Disclaimer

It doesn't work if you want to export via Latex (Latex is used when Org exports to PDF). Look at Tyler's answer and comments.

  • What format are you exporting to? PDF, html, or? – Tyler Mar 26 '16 at 22:26
  • @TylerI I exporting mostly to ODT and HTML. – foki Mar 27 '16 at 7:44
3

Org manual says this about export settings (you should be able to browse it in emacs info C-h i m Org m exporting):

‘LANGUAGE’

The language used for translating some strings (‘org-export-default-language’). E.g., ‘#+LANGUAGE: fr’ will tell Org to translate File (english) into Fichier (french) in the clocktable.

I haven't tried it but I expect it should do what you want.

  • 1
    Not sufficient for all exporters, for Latex exports, you may want to look at @rené answer. – Jocelyn delalande Dec 31 '16 at 12:50
9

As JeanPierre answer pointed, you need to specify the language export setting. For French the next line does the work:

#+LANGUAGE: fr

No all languages are supported and, as you said, is possible to see which ones are viewing the org-latex-export-dictionary variable (you can use the emacs command C-h v then write the variable name). Some languages might be only partially supported or not supported at all like Serbian. If you want it to work with an unsupported language add the translated strings to the variable and preferably send them to the devs so it ends up org-mode.

LaTex and PDF

If you are exporting to LaTex and want to let Babel change the text use:

#+LANGUAGE: fr
#+LATEX_HEADER: \usepackage[AUTO]{babel}

This will work in both HTML and latex as the AUTO keyword will be substituted by the corresponding Babel language name. To view which languages are supported view the org-latex-babel-language-alist variable. Not all languages available in Babel are there but Serbian is and works (tested it and "Contents" appears as "Sadržaj").

If your language is not in org-latex-babel-language-alist but is available in babel, like Breton, use:

#+LANGUAGE: br
#+LATEX_HEADER: \usepackage[breton]{babel}

As Breton is not in org-latex-export-dictionary theLANGUAGE variable won't do anything for HTML export, it will be in English, but is necessary. That's because what will end up in the LaTex file will be \usepackage[breton, <default-lang>]{babel} where default-lang will be English if LANGUAGE is not present and the last language is considered the default by Babel. As br is not in org-latex-babel-language-alist we end up with \usepackage[breton, ]{babel}, there Breton is the default.

If Breton is added to org-latex-babel-language-alist it will work anyway (\usepackage[breton, breton]{babel}). If Breton is included in org-latex-export-dictionary it will now work in HTML too. If Breton wasn't supported by babel it will work anyway but be in English, so this configuration is the one who gives you as much in the specified language as possible with English as a fall back. I rather use AUTO if available as there is only one place to put the language.

If you don't like what Babel puts as "Contents" but still want to use it you can do something like:

#+LANGUAGE: en
#+LATEX_HEADER: \usepackage[AUTO]{babel}
#+LATEX_HEADER: \addto\captionsenglish{\renewcommand\contentsname{Outline}}

This is like the Tyler's answer but for Babel.

  • Thanks! It works for standard pdf export but doesn't work with Beamer slides export. – foki Apr 11 '16 at 20:22
4

If you are exporting to PDF, org-mode will be calling LaTeX to do the conversion. In that case, you should be able to insert the LaTeX command to change the TOC heading with the following line:

#+LATEX_HEADER: \renewcommand*{\contentsname}{My Table of Contents Header}

Put that at the top of your file and try the export.

  • I currently don't have LATEX environment set so I can't try it with PDF. Now I want to export to ODT and HTML so LATEX command doesn't help here (tell me if I'm wrong). – foki Mar 27 '16 at 8:27
  • 1
    When exporting to LaTeX, you'd better use LaTeX's own handling of languages \usepackage[mylanguage]{babel}. – JeanPierre Mar 27 '16 at 13:45
  • @JeanPierre I've just noticed a weird behavior. Tyler's approach don't work for me, but behavior manifested using JeanPierre's is even more interesting - I have declared both, #+LANGUAGE: fr and #+LATEX_HEADER: \usepackage[english]{babel} and in this case Latex export respects the first setting and translates strings in French counterparts. If I declare de in the first and french or frenchb in the second - de is used. I've also noticed that in described cases exporter does not use org-export-dictionary, more likely it use Latex languages. Have any idea? – foki Mar 30 '16 at 12:13
  • @foki sorry, I was missing a colon :. I've corrected my answer. – Tyler Mar 30 '16 at 15:19
  • 2
    Strange, if I use #+LANGUAGE: fr on it's own, it is ignored - the output LaTeX is in English. If I use it and #+LATEX_HEADER: \usepackage[english]{babel}, the resulting LaTeX includes the line \usepackage[english, frenchb]{babel}. And if I only use #+LATEX_HEADER: \usepackage[french]{babel}, without setting LANGUAGE:, what actually gets inserted is \usepackage[frenchb, english]{babel}. None of them change the PDF, it's always English. – Tyler Mar 30 '16 at 15:32
0

Short answer : for pdf exports, the package texlive-lang-french is required

org 9.1.9 : Setting #+LANGUAGE: fr alone has no effect.

make it happen with

#+LATEX_HEADER: \usepackage[frenchb]{babel}

or

#+LANGUAGE: fr
#+LATEX_HEADER: \usepackage[AUTO]{babel}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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