what is the terminal command to know the user's language setting (language name is enough) in mac? Can you provide the shell script?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can get a list of the user's language preferences with defaults read NSGlobalDomain AppleLanguages
. OS X will use the languages in decreasing order of preference (if the first one is not available in a particular app). On my machine:
$ defaults read NSGlobalDomain AppleLanguages
(
en,
ja,
fr,
de,
es,
it,
pt,
"pt-PT",
nl,
sv,
nb,
da,
fi,
ru,
pl,
"zh-Hans",
"zh-Hant",
ko,
ar,
cs,
hu,
tr
)
In bash
, to get the first one (the primary UI language), you can slice off the first one with this (admittedly messy) script:
langs=(`defaults read NSGlobalDomain AppleLanguages`)
echo ${langs[1]/,/} # langs[0] is the open bracket