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