How to detect current locale in Mac OS X from the shell

大兔子大兔子 提交于 2019-12-18 13:21:14

问题


I need to detect the current locale in OS X from the command line. On Linux/Unix I can rely on LANG, but it is not always set:

http://henrik.nyh.se/2007/10/displaying-utf-8-correctly-in-leopard-terminal

I am looking for command line utilities or AppleScript code that allows me to find that information. Ideally they would work from 10.2 onwards

The closest I have found so far is

defaults read -g AppleLocale

which works on 10.3 onwards


回答1:


apropos yeilds the command locale

10.4 and later though

Edit:

defaults read .GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3

is mentioned here. I don't have access to a 10.2 system though, so I don't know if it works.




回答2:


locale 

or if that's not disponible

env | grep LC_



回答3:


export LANG=$(defaults read -g AppleLanguages | \
  sed '/"/!d;s/["[:space:]]//g;s/-/_/').UTF-8


来源:https://stackoverflow.com/questions/661935/how-to-detect-current-locale-in-mac-os-x-from-the-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!