Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromneovim/neovim

Commit2a61983

Browse files
mhinzgithub-actions[bot]
authored andcommitted
fix(mac): use same $LANG fallback mechanism as Vim
In a locale "en_US", "en" is the language and "US" is the region.Before this change, we were too clever for our own good and tried to handle theregion as well. But if the macOS primary language is set to "English" and theregion to "Norway", we would end up with "en_NO", which is a locale that doesnot exist.Now we only take the language into account. Taking the example from above wouldyield "en_US", which is a sensible fallback.If the region is important to you, set $LANG and the more specific LC_*variables in your shell config or alternatively use `:help :language`.Referencesneovim#18292(cherry picked from commite038625)
1 parent8d4fbcb commit2a61983

File tree

2 files changed

+17
-47
lines changed

2 files changed

+17
-47
lines changed

‎src/nvim/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ if(WIN32)
1616
# tell MinGW compiler to enable wmain
1717
set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS} -municode")
1818
elseif(CMAKE_SYSTEM_NAMESTREQUAL"Darwin")
19-
set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS} -frameworkCoreFoundation")
20-
set(CMAKE_MODULE_LINKER_FLAGS"${CMAKE_MODULE_LINKER_FLAGS} -frameworkCoreFoundation")
19+
set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS} -frameworkCoreServices")
20+
set(CMAKE_MODULE_LINKER_FLAGS"${CMAKE_MODULE_LINKER_FLAGS} -frameworkCoreServices")
2121
endif()
2222

2323
set(TOUCHES_DIR${PROJECT_BINARY_DIR}/touches)

‎src/nvim/os/lang.c‎

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#ifdef__APPLE__
55
# defineBoolean CFBoolean // Avoid conflict with API's Boolean
6-
#include<CoreFoundation/CFLocale.h>
7-
# include<CoreFoundation/CFString.h>
6+
#defineFileInfo CSFileInfo // Avoid conflict with API's Fileinfo
7+
# include<CoreServices/CoreServices.h>
88
# undef Boolean
9+
# undef FileInfo
910
#endif
1011

1112
#include"auto/config.h"
@@ -21,55 +22,24 @@ void lang_init(void)
2122
{
2223
#ifdef__APPLE__
2324
if (os_getenv("LANG")==NULL) {
24-
constchar*lang_region=NULL;
25-
CFTypeRefcf_lang_region=NULL;
26-
27-
CFLocaleRefcf_locale=CFLocaleCopyCurrent();
28-
if (cf_locale) {
29-
cf_lang_region=CFLocaleGetValue(cf_locale,kCFLocaleIdentifier);
30-
CFRetain(cf_lang_region);
31-
lang_region=CFStringGetCStringPtr(cf_lang_region,
32-
kCFStringEncodingUTF8);
33-
CFRelease(cf_locale);
34-
}else {
35-
// Use the primary language defined in Preferences -> Language & Region
36-
CFArrayRefcf_langs=CFLocaleCopyPreferredLanguages();
37-
if (cf_langs&&CFArrayGetCount(cf_langs)>0) {
38-
cf_lang_region=CFArrayGetValueAtIndex(cf_langs,0);
39-
CFRetain(cf_lang_region);
40-
CFRelease(cf_langs);
41-
lang_region=CFStringGetCStringPtr(cf_lang_region,
42-
kCFStringEncodingUTF8);
43-
}else {
44-
ELOG("$LANG is empty and your primary language cannot be inferred.");
45-
return;
46-
}
47-
}
48-
4925
charbuf[50]= {0 };
50-
boolset_lang;
51-
if (lang_region) {
52-
set_lang= true;
53-
xstrlcpy(buf,lang_region,sizeof(buf));
54-
}else {
55-
set_lang=CFStringGetCString(cf_lang_region,buf,40,
56-
kCFStringEncodingUTF8);
57-
}
58-
if (set_lang) {
26+
27+
// $LANG is not set, either because it was unset or Nvim was started
28+
// from the Dock. Query the system locale.
29+
if (LocaleRefGetPartString(NULL,
30+
kLocaleLanguageMask |kLocaleLanguageVariantMask |
31+
kLocaleRegionMask |kLocaleRegionVariantMask,
32+
sizeof(buf)-10,buf)==noErr&&*buf) {
5933
if (strcasestr(buf,"utf-8")==NULL) {
6034
xstrlcat(buf,".UTF-8",sizeof(buf));
6135
}
6236
os_setenv("LANG",buf, true);
37+
setlocale(LC_ALL,"");
38+
// Make sure strtod() uses a decimal point, not a comma.
39+
setlocale(LC_NUMERIC,"C");
40+
}else {
41+
ELOG("$LANG is empty and the macOS primary language cannot be inferred.");
6342
}
64-
CFRelease(cf_lang_region);
65-
# ifdefHAVE_LOCALE_H
66-
setlocale(LC_ALL,"");
67-
68-
# ifdefLC_NUMERIC
69-
// Make sure strtod() uses a decimal point, not a comma.
70-
setlocale(LC_NUMERIC,"C");
71-
# endif
72-
# endif
7343
}
7444
#endif
7545
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp