Course contentsShow
← Web Development
Lesson 2496 of 2,98245. InternationalizationFree lesson

Understanding Locales and Language Tags

Learn the structure of BCP 47 language tags and how locales represent language, region, and cultural preferences.

Understanding Locales and Language Tags

You'll learn how BCP 47 language tags systematically encode language, region, and cultural formatting preferences for internationalization.

What is a Locale?

A locale is a set of parameters that defines a user's language, region, and cultural conventions. Think of it like a "cultural profile" that tells your application how to format dates, numbers, currencies, and which language to display.

Language tags are the standardized codes that identify these locales, following the BCP 47 specification (Best Current Practice 47).

BCP 47 Language Tag Structure

Language tags follow a hierarchical pattern of subtags separated by hyphens:

language[-script][-region][-variant][-extension]

Components:

  • language (required): Two or three-letter code (ISO 639), e.g., en (English), zh (Chinese), fr (French)
  • script (optional): Four-letter code for writing system, e.g., Hans (Simplified), Latn (Latin)
  • region (optional): Two-letter country code (ISO 3166-1), e.g., US, GB, CN
  • variant (optional): Special dialects or conventions
  • extension (optional): Additional locale preferences like calendar or numbering systems

Common Examples

  • en – Generic English
  • en-US – English as used in the United States
  • en-GB – English as used in Great Britain
  • zh-Hans-CN – Simplified Chinese in China
  • pt-BR – Portuguese in Brazil
  • fr-CA – French in Canada

Why This Matters

The same language can have dramatically different formatting rules by region. English speakers in the US write dates as 12/31/2024, while those in the UK write 31/12/2024. Currency symbols, number separators, and even vocabulary differ significantly.

Key Takeaway: BCP 47 language tags provide a standardized, hierarchical system for encoding language and regional preferences, enabling web applications to deliver culturally appropriate content and formatting worldwide.