Skip to content

Add Locale (primitives) #75

@vhrcgcom

Description

@vhrcgcom

Description

Implement Locale as a ValueObject in the primitives module.

Spec: BCP 47 language tag (e.g. en-US, cs-CZ)

Implementation checklist

  • Create src/primitives/locale.rs
  • Implement ValueObject trait
  • Add #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  • Export from src/primitives/mod.rs and prelude
  • Unit tests: valid input · empty input · invalid format · normalisation
  • Doc comment with # Example block
  • Update status in ROADMAP.md from ⬜ to ✅

Implementation detail

Input / Output

Type Alias
Input String LocaleInput
Output String LocaleOutput

Normalization

Trim; normalise the separator: accept both _ and - as separators between the language and region subtags, store with - (BCP 47 canonical form). Lowercase the language subtag, uppercase the region subtag if present (e.g. "en_us""en-US").

Validation

Must match BCP 47 at a structural level — for MVP, a two-part rule is sufficient:

  • Language subtag: 2–3 ASCII letters (lowercase after normalisation).
  • Optional region subtag (after -): exactly 2 ASCII letters (uppercase after normalisation) OR exactly 3 digits.
  • Other subtag types (script, variant, extension) are out of scope for MVP.

Extra methods

None beyond the trait.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions