annotate src/locale.c @ 35620:0dc032c77f1a v9.1.0553

patch 9.1.0553: filetype: *.mcmeta files are not recognized Commit: https://github.com/vim/vim/commit/d33a518025765c4a3530ad6cfb6cab83a30c8f55 Author: Tomodachi94 <tomodachi94@protonmail.com> Date: Tue Jul 9 19:55:16 2024 +0200 patch 9.1.0553: filetype: *.mcmeta files are not recognized Problem: filetype: *.mcmeta files are not recognized Solution: Detect '*.mcmeta' files as json filetype (Tomodachi94) "pack.mcmeta" was added to the JSON tests because that is the most common filename with that extension. There are currently 34,000 instances of this file extension on GitHub: https://github.com/search?q=path%3A*.mcmeta&type=code&p=2 .zip files with this extension have downloads in the millions on sites like CurseForge: https://www.curseforge.com/minecraft/search?page=1&pageSize=20&sortBy=relevancy&class=texture-packs Further reading about the file extension: https://minecraft.wiki/w/Tutorials/Creating_a_resource_pack#Creating_a_.MCMETA_file closes: #15189 Signed-off-by: Tomodachi94 <tomodachi94@protonmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 09 Jul 2024 20:00:08 +0200
parents 238ca27dbfd2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * locale.c: functions for language/locale configuration
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG))
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 # define HAVE_GET_LOCALE_VAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 static char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 get_locale_val(int what)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 char_u *loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 // Obtain the locale value from the libraries.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 loc = (char_u *)setlocale(what, NULL);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 if (loc != NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 // setocale() returns something like "LC_COLLATE=<name>;LC_..." when
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 // one of the values (e.g., LC_CTYPE) differs.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 p = vim_strchr(loc, '=');
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 if (p != NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 loc = ++p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 while (*p != NUL) // remove trailing newline
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 if (*p < ' ' || *p == ';')
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 *p = NUL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 break;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 ++p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 return loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 #endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 #ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 * On MS-Windows locale names are strings like "German_Germany.1252", but
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 * gettext expects "de". Try to translate one into another here for a few
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 * supported languages.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 static char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 gettext_lang(char_u *name)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 int i;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 static char *(mtable[]) = {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 "afrikaans", "af",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 "czech", "cs",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 "dutch", "nl",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 "german", "de",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 "english_united kingdom", "en_GB",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 "spanish", "es",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 "french", "fr",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 "italian", "it",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 "japanese", "ja",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 "korean", "ko",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 "norwegian", "no",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 "polish", "pl",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 "russian", "ru",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 "slovak", "sk",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 "swedish", "sv",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 "ukrainian", "uk",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 "chinese_china", "zh_CN",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 "chinese_taiwan", "zh_TW",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 NULL};
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 for (i = 0; mtable[i] != NULL; i += 2)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 return (char_u *)mtable[i + 1];
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 return name;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 #endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 * Return TRUE when "lang" starts with a valid language name.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 * Rejects NULL, empty string, "C", "C.UTF-8" and others.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 static int
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 is_valid_mess_lang(char_u *lang)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 return lang != NULL && ASCII_ISALPHA(lang[0]) && ASCII_ISALPHA(lang[1]);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 * Obtain the current messages language. Used to set the default for
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 * 'helplang'. May return NULL or an empty string.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 get_mess_lang(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 # ifdef HAVE_GET_LOCALE_VAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 # if defined(LC_MESSAGES)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 p = get_locale_val(LC_MESSAGES);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 // may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 // and LC_MONETARY may be set differently for a Japanese working in the
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 // US.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 p = get_locale_val(LC_COLLATE);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 p = mch_getenv((char_u *)"LC_ALL");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 if (!is_valid_mess_lang(p))
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 p = mch_getenv((char_u *)"LC_MESSAGES");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 if (!is_valid_mess_lang(p))
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 p = mch_getenv((char_u *)"LANG");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 p = gettext_lang(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 return is_valid_mess_lang(p) ? p : NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 #endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 // Complicated #if; matches with where get_mess_env() is used below.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 && defined(LC_MESSAGES))) \
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 && !defined(LC_MESSAGES))
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 * Get the language used for messages from the environment.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 static char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 get_mess_env(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 p = mch_getenv((char_u *)"LC_ALL");
31728
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
154 if (p != NULL && *p != NUL)
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
155 return p;
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
156
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
157 p = mch_getenv((char_u *)"LC_MESSAGES");
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
158 if (p != NULL && *p != NUL)
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
159 return p;
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
160
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
161 p = mch_getenv((char_u *)"LANG");
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
162 if (p != NULL && VIM_ISDIGIT(*p))
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
163 p = NULL; // ignore something like "1043"
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
164 # ifdef HAVE_GET_LOCALE_VAL
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 if (p == NULL || *p == NUL)
31728
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
166 p = get_locale_val(LC_CTYPE);
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 return p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 #endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 #if defined(FEAT_EVAL) || defined(PROTO)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 * Set the "v:lang" variable according to the current locale setting.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 * Also do "v:lc_time"and "v:ctype".
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 void
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 set_lang_var(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 char_u *loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 # ifdef HAVE_GET_LOCALE_VAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 loc = get_locale_val(LC_CTYPE);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 // setlocale() not supported: use the default value
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 loc = (char_u *)"C";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 set_vim_var_string(VV_CTYPE, loc, -1);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 // back to LC_CTYPE if it's empty.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 loc = get_locale_val(LC_MESSAGES);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 loc = get_mess_env();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 set_vim_var_string(VV_LANG, loc, -1);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 # ifdef HAVE_GET_LOCALE_VAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 loc = get_locale_val(LC_TIME);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 set_vim_var_string(VV_LC_TIME, loc, -1);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 # ifdef HAVE_GET_LOCALE_VAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 loc = get_locale_val(LC_COLLATE);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 // setlocale() not supported: use the default value
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 loc = (char_u *)"C";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 set_vim_var_string(VV_COLLATE, loc, -1);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 #endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 * Setup to use the current locale (for ctype() and many other things).
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 void
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 init_locale(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 setlocale(LC_ALL, "");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 # ifdef FEAT_GUI_GTK
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 // Tell Gtk not to change our locale settings.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 gtk_disable_setlocale();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 # endif
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 26861
diff changeset
228 # if defined(LC_NUMERIC)
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 // Make sure strtod() uses a decimal point, not a comma.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 setlocale(LC_NUMERIC, "C");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 // Apparently MS-Windows printf() may cause a crash when we give it 8-bit
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 // text while it's expecting text in the current locale. This call avoids
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 // that.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 setlocale(LC_CTYPE, "C");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 # ifdef FEAT_GETTEXT
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 int mustfree = FALSE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 # ifdef DYNAMIC_GETTEXT
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 // Initialize the gettext library
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 dyn_libintl_init();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 // expand_env() doesn't work yet, because g_chartab[] is not
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 // initialized yet, call vim_getenv() directly
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 if (p != NULL && *p != NUL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 vim_snprintf((char *)NameBuff, MAXPATHL, "%s/lang", p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 bindtextdomain(VIMPACKAGE, (char *)NameBuff);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 if (mustfree)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 vim_free(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 textdomain(VIMPACKAGE);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 * ":language": Set the language (locale).
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 void
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 ex_language(exarg_T *eap)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 char *loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 char_u *name;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 int what = LC_ALL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 char *whatstr = "";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 # ifdef LC_MESSAGES
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 # define VIM_LC_MESSAGES LC_MESSAGES
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 # define VIM_LC_MESSAGES 6789
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 name = eap->arg;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 // Check for "messages {name}", "ctype {name}" or "time {name}" argument.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 // Allow abbreviation, but require at least 3 characters to avoid
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 // confusion with a two letter language name "me" or "ct".
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 p = skiptowhite(eap->arg);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 if ((*p == NUL || VIM_ISWHITE(*p)) && p - eap->arg >= 3)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 what = VIM_LC_MESSAGES;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 name = skipwhite(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 whatstr = "messages ";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 what = LC_CTYPE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 name = skipwhite(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 whatstr = "ctype ";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 what = LC_TIME;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 name = skipwhite(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 whatstr = "time ";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 else if (STRNICMP(eap->arg, "collate", p - eap->arg) == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 what = LC_COLLATE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 name = skipwhite(p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 whatstr = "collate ";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 if (*name == NUL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 # ifndef LC_MESSAGES
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 if (what == VIM_LC_MESSAGES)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 p = get_mess_env();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 p = (char_u *)setlocale(what, NULL);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 if (p == NULL || *p == NUL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 p = (char_u *)"Unknown";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 smsg(_("Current %slanguage: \"%s\""), whatstr, p);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 # ifndef LC_MESSAGES
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (what == VIM_LC_MESSAGES)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 loc = "";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 loc = setlocale(what, (char *)name);
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 26861
diff changeset
336 # if defined(LC_NUMERIC)
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 // Make sure strtod() uses a decimal point, not a comma.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 setlocale(LC_NUMERIC, "C");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 if (loc == NULL)
26861
df2de1e63de0 patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26336
diff changeset
342 semsg(_(e_cannot_set_language_to_str), name);
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 # ifdef HAVE_NL_MSG_CAT_CNTR
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 // Need to do this for GNU gettext, otherwise cached translations
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 // will be used again.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 extern int _nl_msg_cat_cntr;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 ++_nl_msg_cat_cntr;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 // Reset $LC_ALL, otherwise it would overrule everything.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 vim_setenv((char_u *)"LC_ALL", (char_u *)"");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 if (what != LC_TIME && what != LC_COLLATE)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 // Tell gettext() what to translate to. It apparently doesn't
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 // use the currently effective locale. Also do this when
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 // FEAT_GETTEXT isn't defined, so that shell commands use this
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 // value.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if (what == LC_ALL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 vim_setenv((char_u *)"LANG", name);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 // Clear $LANGUAGE because GNU gettext uses it.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 vim_setenv((char_u *)"LANGUAGE", (char_u *)"");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 // Apparently MS-Windows printf() may cause a crash when
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 // we give it 8-bit text while it's expecting text in the
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 // current locale. This call avoids that.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 setlocale(LC_CTYPE, "C");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 if (what != LC_CTYPE)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 char_u *mname;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 mname = gettext_lang(name);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 mname = name;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 vim_setenv((char_u *)"LC_MESSAGES", mname);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 # ifdef FEAT_MULTI_LANG
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 set_helplang_default(mname);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 # ifdef FEAT_EVAL
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // Set v:lang, v:lc_time, v:collate and v:ctype to the final result.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 set_lang_var();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 maketitle();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 static char_u **locales = NULL; // Array of all available locales
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 static int did_init_locales = FALSE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 * Return an array of strings for all available locales + NULL for the
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 * last element. Return NULL in case of error.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 static char_u **
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 find_locales(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 garray_T locales_ga;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 char_u *loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 char_u *locale_list;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 size_t len = 0;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 // Find all available locales by running command "locale -a". If this
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 // doesn't work we won't have completion.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 # ifndef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 locale_list = get_cmd_output((char_u *)"locale -a",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 NULL, SHELL_SILENT, NULL);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 # else
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 // Find all available locales by examining the directories in
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 // $VIMRUNTIME/lang/
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 int options = WILD_SILENT|WILD_USE_NL|WILD_KEEP_ALL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 expand_T xpc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 char_u *p;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 ExpandInit(&xpc);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 xpc.xp_context = EXPAND_DIRECTORIES;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 locale_list = ExpandOne(&xpc, (char_u *)"$VIMRUNTIME/lang/*",
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 NULL, options, WILD_ALL);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 ExpandCleanup(&xpc);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 if (locale_list == NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 // Add a dummy input, that will be skipped lated but we need to
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 // have something in locale_list so that the C locale is added at
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 // the end.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 locale_list = vim_strsave((char_u *)".\n");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 p = locale_list;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 // find the last directory delimiter
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 while (p != NULL && *p != NUL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 if (*p == '\n')
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 break;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 if (*p == '\\')
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 len = p - locale_list;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 p++;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 if (locale_list == NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 return NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 ga_init2(&locales_ga, sizeof(char_u *), 20);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 // Transform locale_list string where each locale is separated by "\n"
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 // into an array of locale strings.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 loc = (char_u *)strtok((char *)locale_list, "\n");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 while (loc != NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 int ignore = FALSE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 if (len > 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 loc += len + 1;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 // skip locales with a dot (which indicates the charset)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 if (vim_strchr(loc, '.') != NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 ignore = TRUE;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (!ignore)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 if (ga_grow(&locales_ga, 1) == FAIL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 break;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 loc = vim_strsave(loc);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 if (loc == NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 break;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 loc = (char_u *)strtok(NULL, "\n");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 # ifdef MSWIN
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 // Add the C locale
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 if (ga_grow(&locales_ga, 1) == OK)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] =
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 vim_strsave((char_u *)"C");
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 vim_free(locale_list);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 if (ga_grow(&locales_ga, 1) == FAIL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 ga_clear(&locales_ga);
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 return NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 return (char_u **)locales_ga.ga_data;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 * Lazy initialization of all available locales.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 static void
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 init_locales(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
31728
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
507 if (did_init_locales)
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
508 return;
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
509
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
510 did_init_locales = TRUE;
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
511 locales = find_locales();
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 # if defined(EXITFREE) || defined(PROTO)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 void
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 free_locales(void)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 int i;
31728
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
519
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
520 if (locales == NULL)
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
521 return;
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
522
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
523 for (i = 0; locales[i] != NULL; i++)
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
524 vim_free(locales[i]);
238ca27dbfd2 patch 9.0.1196: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
525 VIM_CLEAR(locales);
21437
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 # endif
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 * Function given to ExpandGeneric() to obtain the possible arguments of the
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 * ":language" command.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 get_lang_arg(expand_T *xp UNUSED, int idx)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 if (idx == 0)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 return (char_u *)"messages";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (idx == 1)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 return (char_u *)"ctype";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 if (idx == 2)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 return (char_u *)"time";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 if (idx == 3)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 return (char_u *)"collate";
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 init_locales();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 if (locales == NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 return NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 return locales[idx - 4];
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 /*
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 * Function given to ExpandGeneric() to obtain the available locales.
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 */
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 char_u *
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 get_locales(expand_T *xp UNUSED, int idx)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 {
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 init_locales();
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 if (locales == NULL)
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 return NULL;
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 return locales[idx];
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 }
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562
b32b67a108f2 patch 8.2.1269: language and locale code spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 #endif