world-locale
world-locale provides comprehensive support for internationalisation concepts, and locale-aware operations.
Dependency Resolution
libraryDependencies += "africa.shuwari" %% "world-locale" % ""
Platform Support Matrix
| Module | JVM | Scala.js | Scala Native |
|---|---|---|---|
world-locale |
✓ | ✓ | ✓ |
Note: Use the
%%%operator instead of%%when targeting multiple platforms.
Module Contents
Countries
Complete ISO 3166-1 country code support with alpha-2, alpha-3, and numeric codes.
See Countries Guide for detailed documentation.
Locale Formatting
Locale-aware formatting capabilities for internationalised applications.
See Locale Formatting Guide for detailed documentation.
Key Types
- world.locale.country.Country - ISO 3166-1 country representation
- world.locale.LocaleError - Locale-related error types
Common Use Cases
Country Lookup
import world.locale.country.Country
// Access by code
val uk = Country.GB
val usa = Country.US
// Lookup by various identifiers
Country.withAlpha2("JP") // Some(Country.JP)
Country.withAlpha3("FRA") // Some(Country.FR)
Country.withNumericCode(276) // Some(Country.DE)
Country Properties
import world.locale.country.Country
val japan = Country.JP
japan.alpha2 // "JP"
japan.alpha3 // "JPN"
japan.numericCode // 392
japan.name // "Japan"
Design Goals
The Locale module is designed with these principles:
- Standards Compliance - Full ISO 3166-1 support
- Type Safety - Countries are distinct types, not strings
- Immutability - All types are immutable value types
- Cross-Platform - Identical behaviour on JVM, JS, and Native
- Performance - Efficient lookups via generated code
Platform Support
The Locale module supports:
- JVM - Scala
- Scala.js -
- Scala Native -
All features work identically across platforms.
Error Handling
Locale operations that may fail return Either[LocaleError, Result]:
import world.locale.LocaleError
// Example: Handling lookup failures
Country.withAlpha2("XX") match
case Some(country) => println(s"Found: ${country.name}")
case None => println("Country not found")
See world.locale.LocaleError for error types.
Next Steps
- Countries Guide - Learn about country support
- Locale Formatting Guide - Explore locale-aware formatting
- API Reference - Complete API documentation
Module Dependencies
The Locale module depends on:
world-common- Formatting abstractions and utilities
Future Enhancements
Future releases may include:
- Additional ISO standards support
- Locale-specific date/time formatting
- Number formatting with locale rules
- Collation and sorting support
In this article