Search code examples
javalocalizationlocale

en_US or en-US, which one should you use?


Assume you want to store the locale of user preference in database, which value you will use?

en_US or en-US

They are two standards, but which one you prefer to use as part of your own application?

Updated: Is seems many web sites use dash instead of underscore, e.g.

http://zh.wikipedia.org/zh-tw http://www.google.com.hk/search?hl=zh-TW


Solution

  • I'm pretty sure "-" is the standard. If you see "_" somewhere it's probably something some people came up with to make it a valid identifier.

    Personally I'd go with "-", just to be correct.

    http://en.wikipedia.org/wiki/IETF_language_tag

    https://datatracker.ietf.org/doc/html/rfc5646