mlang.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. *mlang.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Multi-language features *multilang* *multi-lang*
  4. This is about using messages and menus in various languages. For editing
  5. multi-byte text see |multibyte|.
  6. The basics are explained in the user manual: |usr_45.txt|.
  7. Type |gO| to see the table of contents.
  8. ==============================================================================
  9. 1. Messages *multilang-messages*
  10. Vim picks up the locale from the environment. In most cases this means Vim
  11. will use the language that you prefer, unless it's not available.
  12. To see a list of supported locale names on your system, look in one of these
  13. directories (for Unix):
  14. /usr/lib/locale ~
  15. /usr/share/locale ~
  16. Unfortunately, upper/lowercase differences matter. Also watch out for the
  17. use of "-" and "_".
  18. *:lan* *:lang* *:language* *E197*
  19. :lan[guage]
  20. :lan[guage] mes[sages]
  21. :lan[guage] cty[pe]
  22. :lan[guage] tim[e]
  23. Print the current language (aka locale).
  24. With the "messages" argument the language used for
  25. messages is printed. Technical: LC_MESSAGES.
  26. With the "ctype" argument the language used for
  27. character encoding is printed. Technical: LC_CTYPE.
  28. With the "time" argument the language used for
  29. strftime() is printed. Technical: LC_TIME.
  30. Without argument all parts of the locale are printed
  31. (this is system dependent).
  32. The current language can also be obtained with the
  33. |v:lang|, |v:ctype| and |v:lc_time| variables.
  34. :lan[guage] {name}
  35. :lan[guage] mes[sages] {name}
  36. :lan[guage] cty[pe] {name}
  37. :lan[guage] tim[e] {name}
  38. Set the current language (aka locale) to {name}.
  39. The locale {name} must be a valid locale on your
  40. system. Some systems accept aliases like "en" or
  41. "en_US", but some only accept the full specification
  42. like "en_US.ISO_8859-1". On Unix systems you can use
  43. this command to see what locales are supported: >
  44. :!locale -a
  45. < With the "messages" argument the language used for
  46. messages is set. This can be different when you want,
  47. for example, English messages while editing Japanese
  48. text. This sets $LC_MESSAGES.
  49. With the "ctype" argument the language used for
  50. character encoding is set. This affects the libraries
  51. that Vim was linked with. It's unusual to set this to
  52. a different value from 'encoding' or "C". This sets
  53. $LC_CTYPE.
  54. With the "time" argument the language used for time
  55. and date messages is set. This affects strftime().
  56. This sets $LC_TIME.
  57. Without an argument both are set, and additionally
  58. $LANG is set.
  59. The LC_NUMERIC value will always be set to "C" so
  60. that floating point numbers use '.' as the decimal
  61. point. This will make a difference for items that
  62. depend on the language (some messages, time and date
  63. format).
  64. Not fully supported on all systems.
  65. If this fails there will be an error message. If it
  66. succeeds there is no message. Example: >
  67. :language
  68. Current language: C
  69. :language de_DE.ISO_8859-1
  70. :language mes
  71. Current messages language: de_DE.ISO_8859-1
  72. :lang mes en
  73. <
  74. MS-WINDOWS MESSAGE TRANSLATIONS *win32-gettext*
  75. If you used the self-installing .exe file, message translations should work
  76. already. Otherwise get the libintl.dll file if you don't have it yet:
  77. http://sourceforge.net/projects/gettext
  78. Or:
  79. https://mlocati.github.io/gettext-iconv-windows/
  80. This also contains tools xgettext, msgformat and others.
  81. libintl.dll should be placed in same directory as (g)vim.exe, or one of the
  82. directories listed in the PATH environment value. Vim also looks for the
  83. alternate names "libintl-8.dll" and "intl.dll".
  84. Message files (vim.mo) have to be placed in "$VIMRUNTIME/lang/xx/LC_MESSAGES",
  85. where "xx" is the abbreviation of the language (mostly two letters).
  86. If you write your own translations you need to generate the .po file and
  87. convert it to a .mo file. You need to get the source distribution and read
  88. the file "src/po/README.txt".
  89. To overrule the automatic choice of the language, set the $LANG variable to
  90. the language of your choice. use "en" to disable translations. >
  91. :let $LANG = 'ja'
  92. (text for Windows by Muraoka Taro)
  93. ==============================================================================
  94. 2. Menus *multilang-menus*
  95. See |45.2| for the basics, esp. using 'langmenu'.
  96. Note that if changes have been made to the menus after the translation was
  97. done, some of the menus may be shown in English. Please try contacting the
  98. maintainer of the translation and ask him to update it. You can find the
  99. name and e-mail address of the translator in
  100. "$VIMRUNTIME/lang/menu_<lang>.vim".
  101. To set the font (or fontset) to use for the menus, use the |:highlight|
  102. command. Example: >
  103. :highlight Menu font=k12,r12
  104. ALIAS LOCALE NAMES
  105. Unfortunately, the locale names are different on various systems, even though
  106. they are for the same language and encoding. If you do not get the menu
  107. translations you expected, check the output of this command: >
  108. echo v:lang
  109. Now check the "$VIMRUNTIME/lang" directory for menu translation files that use
  110. a similar language. A difference in a "-" being a "_" already causes a file
  111. not to be found! Another common difference to watch out for is "iso8859-1"
  112. versus "iso_8859-1". Fortunately Vim makes all names lowercase, thus you
  113. don't have to worry about case differences. Spaces are changed to
  114. underscores, to avoid having to escape them.
  115. If you find a menu translation file for your language with a different name,
  116. create a file in your own runtime directory to load that one. The name of
  117. that file could be: >
  118. ~/.config/nvim/lang/menu_<v:lang>.vim
  119. Check the 'runtimepath' option for directories which are searched. In that
  120. file put a command to load the menu file with the other name: >
  121. runtime lang/menu_<other_lang>.vim
  122. TRANSLATING MENUS
  123. If you want to do your own translations, you can use the |:menutrans| command,
  124. explained below. It is recommended to put the translations for one language
  125. in a Vim script. For a language that has no translation yet, please consider
  126. becoming the maintainer and make your translations available to all Vim users.
  127. Send an e-mail to the Vim maintainer <maintainer@vim.org>.
  128. *:menut* *:menutrans* *:menutranslate*
  129. :menut[ranslate] clear
  130. Clear all menu translations.
  131. :menut[ranslate] {english} {mylang}
  132. Translate menu name {english} to {mylang}. All
  133. special characters like "&" and "<Tab>" need to be
  134. included. Spaces and dots need to be escaped with a
  135. backslash, just like in other |:menu| commands.
  136. Case in {english} is ignored.
  137. See the $VIMRUNTIME/lang directory for examples.
  138. To try out your translations you first have to remove all menus. This is how
  139. you can do it without restarting Vim: >
  140. :source $VIMRUNTIME/delmenu.vim
  141. :source <your-new-menu-file>
  142. :source $VIMRUNTIME/menu.vim
  143. Each part of a menu path is translated separately. The result is that when
  144. "Help" is translated to "Hilfe" and "Overview" to "Überblick" then
  145. "Help.Overview" will be translated to "Hilfe.Überblick".
  146. ==============================================================================
  147. 3. Scripts *multilang-scripts*
  148. In Vim scripts you can use the |v:lang| variable to get the current language
  149. (locale). The default value is "C" or comes from the $LANG environment
  150. variable.
  151. The following example shows how this variable is used in a simple way, to make
  152. a message adapt to language preferences of the user, >
  153. :if v:lang =~ "de_DE"
  154. : echo "Guten Morgen"
  155. :else
  156. : echo "Good morning"
  157. :endif
  158. <
  159. vim:tw=78:sw=4:ts=8:noet:ft=help:norl: