作者:Yihui Xie
译者:郑宝童
日期:2021.06.02


4.5 Internationalization

If the language of your book is not English, you will need to translate certain English words and phrases into your language, such as the words “Figure” and “Table” when figures/tables are automatically numbered in the HTML output. Internationalization may not be an issue for LaTeX output, since some LaTeX packages can automatically translate these terms into the local language, such as the ctexcap package for Chinese.

如果您的书的语言不是英语,您将需要将某些英语单词和短语翻译成您的语言,例如,单词“Figure”和“Table”,当HTML输出中的figures/tables 被自动编号时。对于LaTeX输出,Internationalization 并不是个问题,因为一些LaTeX包可以自动将这些术语翻译成本地语言,比如中文的ctexcap包。

For non-LaTeX output, you can set the language field in the configuration file _bookdown.yml. Currently the default settings are:
对于非latex输出,可以在配置文件_bookdown.yml中设置language 字段。目前默认设置是:

  1. language:
  2. label:
  3. fig: 'Figure '
  4. tab: 'Table '
  5. eq: 'Equation '
  6. thm: 'Theorem '
  7. lem: 'Lemma '
  8. cor: 'Corollary '
  9. prp: 'Proposition '
  10. cnj: 'Conjecture '
  11. def: 'Definition '
  12. exm: 'Example '
  13. exr: 'Exercise '
  14. hyp: 'Hypothesis '
  15. proof: 'Proof. '
  16. remark: 'Remark. '
  17. solution: 'Solution. '
  18. ui:
  19. edit: Edit
  20. chapter_name: ''
  21. appendix_name: ''

For example, if you want FIGURE x.x instead of Figure x.x, you can change fig to "FIGURE ":

例如,如果你想让FIGURE x.x代替Figure x.x,你可以将fig改为"FIGURE ":

  1. language:
  2. label:
  3. fig: "FIGURE "

The fields under ui are used to specify some terms in the user interface. The edit field specifies the text associated with the edit link in _bookdown.yml (Section 4.4). The fields chapter_name, appendix_name, fig, tab and eq can be either a character string to be prepended to chapter (e.g., 'CHAPTER ') or reference number (e.g., 'FIGURE '), or an R function that takes a number (chapter or reference number) as the input and returns a string. (e.g., !expr function(i) paste('Chapter', i)). Here is an example for Hungarian:

  1. language:
  2. label:
  3. fig: !expr function(i) paste(i, 'ábra')
  4. ui:
  5. chapter_name: !expr function(i) paste0(i, '. fejezet')

For chapter_name and appendix_name only, if it is a character vector of length 2, the chapter title prefix will be paste0(chapter_name[1], i, chapter_name[2]), where i is the chapter number. There is one caveat when you write in a language that uses multibyte characters, such as Chinese, Japanese, and Korean (CJK): Pandoc cannot generate identifiers from section headings that are pure CJK characters, so you will not be able to cross-reference sections (they do not have labels), unless you manually assign identifiers to them by appending {#identifier} to the section heading, where identifier is an identifier of your choice.

对于chapter_nameappendix_name,如果它是一个长度为2的字符向量,章节标题前缀将是paste0(chapter_name[1], i, chapter_name[2]),其中i是章节编号。
当您使用多字节字符(如中文、日文和韩文)编写时,有一个注意事项:Pandoc不能从纯CJK字符的章节标题中生成标识符,因此您不能交叉引用章节(它们没有标签),非您通过将{#identifier}附加到节标题来手动为它们分配标识符,其中identifier是您选择的标识符。