This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The worldwide gem provides internationalization and localization APIs for Ruby, including address validation/formatting, currency handling, date/time formatting, region/country data, phone validation, and more. It also includes a TypeScript/JavaScript package at lang/typescript.
- Install dependencies:
bundle install - Run tests:
bundle exec rake test - Run single test file:
bundle exec ruby -Itest test/path/to/test_file.rb - Run single test method:
bundle exec ruby -Itest test/path/to/test_file.rb -n test_method_name - Lint:
bundle exec rubocop - Auto-fix lint issues:
bundle exec rubocop -a - Run tests and linting:
bundle exec rake(default task) - Console:
bin/consoleorbundle exec rake console
- Navigate to TypeScript directory:
cd lang/typescript - Install dependencies:
pnpm install - Build:
pnpm build - Run tests:
pnpm test - Watch tests:
pnpm test:watch - Lint:
pnpm lint - Type check:
pnpm typecheck - Format:
pnpm format
- Update CLDR data: See
rake/tasks/cldr.rakeand "Updating CLDR Data" section below
The gem uses Unicode CLDR (Common Locale Data Repository) for internationalization data. To update CLDR data, run these rake tasks in order:
-
Clean old data:
bundle exec rake cldr:data:clean- Removes pre-existing CLDR files to prepare for fresh import
-
Import from Unicode:
bundle exec rake cldr:data:import- Downloads CLDR data from unicode.org (version specified in
data/cldr.yml) - Converts XML to YAML format
- Stores raw data in
vendor/cldr/and processed data invendor/ruby-cldr/ - Takes several minutes; downloads ~50MB of data
- Optional:
VERSION=42to download a specific CLDR version - Optional:
COMPONENTS=Units,Calendarsto import specific components only
- Downloads CLDR data from unicode.org (version specified in
-
Apply patches:
bundle exec rake cldr:data:patch- Applies fixes to upstream CLDR data defined in
rake/cldr/patch.rb - Corrects inconsistencies in CLDR (e.g.,
²duplicate markers, inconsistent naming conventions) - Updates
data/cldr/files with patched data
- Applies fixes to upstream CLDR data defined in
-
Generate additional data:
bundle exec rake cldr:data:generate- Generates locale-specific data (date/time formats, missing plurals)
- Takes several minutes
-
Generate file indices:
bundle exec rake cldr:data:generate_paths- Creates lookup indices for fast file loading
To fix CLDR data inconsistencies:
- Edit
rake/cldr/patch.rband add your patch usingpatch_subdivisionsorpatch_file - Run the patch task:
bundle exec rake cldr:data:patch - Verify changes in the appropriate
data/cldr/locales/*/file - Commit both the patch code and the resulting data file changes
- Consider reporting the issue upstream at https://unicode-org.atlassian.net
Example patch:
# Remove ² markers from Spanish subdivisions in Portuguese
patch_subdivisions(:pt, [
[:esna, "Navarra²", "Navarra"],
[:esri, "La Rioja²", "La Rioja"],
])Important: The vendor/ directory is gitignored - it contains temporary build artifacts that should not be committed.
The gem is heavily data-driven, with locale/region data stored in YAML files under data/:
data/regions/- Contains country/territory-specific data (one file per ISO country code)data/cldr/- Unicode CLDR data for localizationdata/world.yml- Global region hierarchy and metadatadata/country_codes.yml- Country code mappingsdata/extant_outcodes.yml- Postal code prefix data for validation
The Worldwide module provides a facade with factory methods:
Worldwide.region(code:)- Access region/country dataWorldwide.address(...)- Create and manipulate addressesWorldwide.currency(code:)- Currency information and formattingWorldwide.locale(code:)- Locale informationWorldwide.numbers,Worldwide.names,Worldwide.lists- Formatting utilities
Regions & Addresses
Worldwide::Region- Represents countries, territories, provinces, states, etc.Worldwide::Address- Address objects with validation, normalization, and formattingWorldwide::AddressValidator- Validates address completeness and correctnessWorldwide::Zip- Postal code validation and normalization
Localization
Worldwide::Locale- Locale metadata and translationsWorldwide::Locales- Locale collections and lookupsWorldwide::RubyI18nConfig- Configures Ruby's I18n libraryWorldwide::Config- Global configuration
Formatting
Worldwide::Numbers- Number formatting per localeWorldwide::Currency- Currency symbols, names, and money formattingWorldwide::TimeFormatter- Time/date formatting helpersWorldwide::Names- Person name formatting respecting cultural conventionsWorldwide::Lists- List formatting with locale-appropriate conjunctionsWorldwide::Punctuation- Punctuation rules per locale
Validation
Worldwide::Phone- Phone number validation using phonelib- Region-specific postal code validation
- Address field completeness checking
Uses Minitest with:
minitest/autorunfor test runningminitest/reportersfor better outputminitest/focusfor focusing on specific tests (dev only)mocha/minitestfor mocking/stubbing
Test files are organized under test/worldwide/ mirroring the lib/worldwide/ structure.
activesupport(>= 7.0) - Rails utilitiesi18n- Ruby internationalization libraryphonelib(~> 0.8) - Phone number validationruby-cldr(git ref) - CLDR data parser (dev/build only)
Requires Ruby >= 3.1.0
- Frozen string literals: All Ruby files should start with
# frozen_string_literal: true - Style: Follow Shopify Ruby style guide via
rubocop-shopify - Module caching: Use instance variables for caching (e.g.,
@currencies_cache) - Data loading: Lazy-load YAML data to minimize memory footprint
- Locale awareness: Most classes accept
locale:parameter, defaulting toI18n.locale
- This is a public gem: Avoid adding internal-only references or artifacts
- When modifying region data, update the corresponding YAML file in
data/regions/ - CLDR data is periodically updated; don't manually edit
data/cldr/files directly - use patches - The gem supports both country-level and province/state-level validation
- Address formatting varies significantly by country; check
data/regions/XX.ymlfor country-specific rules - The TypeScript package provides equivalent address concatenation/splitting utilities