Should i use ISO 3166 country codes (US) or culture codes (en-US)?
ISO 3166 has a list of 2 character country codes such as US, UK, FR.
A shopping cart I've 开发者_Python百科used has both these codes and also the culture codes such as en-US or en-UK.
For a separate project I thought that the longer code is more useful because it at the very least tells me the language used by that country. But i cant seem to find an accurate list of them.
Should I use these 'culture codes' for tracking countries or just stick to the 2 character ISO 3166 names? What might be the catches of using either ?
I'm not sure why a shoppin cart that is locked to the english language would even care about en-US vs just US. Any insight?
Edit: Also where can I get a culture code list? Is this an ISO standard? Is it correct to assume that the country portion of a culture code is an ISO 3166 country code?
Country codes are used to identify countries. Simply countries.
Culture codes serve to identify cultures to refer to their specifics, like decimal signs, date separator, currencies etc. Here you are not directly interested in a country but in a particular culture.
If you need to simply track countries then stick with ISO 3166 codes. It is a good and simple standard. If you do something like IP-to-country determination, then most services will only give you countries but not specific user cultures.
You really need to tell us what usage scenario you have in mind, then it will be possible to advice better.
As others have pointed out, the answer to this questions really depends on the application.
Countries
Countries are political entities which make laws and administer legal jurisdictions. Countries define things like currencies and their symbols, trade tariffs, phone number prefixes, systems of weights and measures (metric, imperial, etc) and so on. Countries are defined by ISO standard 3166, which defines a set of two-letter (alpha-2), three-letter (alpha-3) and numeric country codes.
The ISO 3166-1 Alpha-2 codes are unrelated to Internet ccTLDs, though they are often the same.
Cultures
Cultures are groupings of language and social norms defining things like the way numbers are written and dates are written. Cultures are usually denoted using their ISO 639 language codes. There are actually four different codes for each language, alpha-2, alpha-3, alpha-3 based on the English language name, and alpha-3 with dialect extensions.
Both countries and cultures are imperfectly correlated with geographic regions.
In computing applications
For many computing applications, it's useful to know both. For example, you want to know what language to present your website in, and you want to know what currency the user expects to make their purchases in, what sales tax to apply, customs and postal rates and so.
This is where the familiar culture-country codes, like en-US, come in. This tells you that the language is English (United States), and the country is USA.
American English has different spellings, and even different words, to standard English, which may be relevant to your application, and the British numerical notation should be used. It also tells you that the currency to display products in is USD, that the symbol is "$" and the currency has 100 subdivisions, that you should use imperial weights and measures (feet and pounds), car components must be for left-hand drive, and so on.
A note about language
You cannot automatically assume language by country. Many countries have more than one official language. For example, in Canada it's English and Quebecois (Canadian French). India has 18 official languages, and no one language is spoken by more than around 20% of the population.
If you're just tracking countries of your users, I would stick to the country codes. Culture is more for tracking things such as decimal separators (.
vs ,
).
I'm not answering your main question, but the ISO 3166 country code for the United Kingdom is GB, not UK (which is “exceptionally reserved”, though), although the latter is the DNS TLD code for the United Kingdom (because of a personal error of Jon Postel, an urban legend has it). For that reason, the language tag for “British English” is en-GB, not en-UK.
That being said, it's not quite clear what you need those codes for.
As a few have pointed out, one indicates only the country (US), while the other indicates both language and country (en-US). I just wanted to add that the whole point of having language/country is because this relationship is not one-to-one. You can have the same language spoken in different countries (pt-BR vs pt-PT), and you can have several languages spoken in the same country (fr-CA and en-CA).
If all you need to track is the user's country, by all means, use the ISO codes. If you need to track cultural and regional settings, then I'd use the full culture code.
As others have said, if you want to record users' geographic location, then use the ISO country codes.
If you also want to track users' culture for presentation purposes (e.g. translations, date and number formatting), then you should store both. Nothing should prevent a user living abroad from using their native language and culture settings. For example a French-speaking Canadian living in the US might have the US country code but want the fr-CA culture code.
精彩评论