Skip to content

Conversation

@davidturnbull
Copy link
Contributor

Problem

Bucket types (json, yaml, markdown, etc.) have different capabilities, but there was no programmatic way to query these capabilities. Questions like "which buckets support the [locale] placeholder?" or "which buckets support locked keys?" required manually reviewing loader implementations.

This made it difficult to:

  • Generate accurate documentation
  • Validate user configurations before instantiating loaders
  • Build UI components that need to display bucket capabilities
  • Understand bucket features without deep-diving into code

Solution

Added a metadata registry that explicitly declares capabilities for all 29 bucket types.

New Bucket Type

Each bucket now includes:

  • displayName - Human-readable label (e.g., "JSON", "Xcode XCStrings")
  • supportsFormatter - Can use code formatters (Prettier, etc.)
  • supportsInjectLocale - Can inject locale code into content
  • supportsLockedKeys - Supports locking specific translation keys
  • supportsIgnoredKeys - Supports ignoring specific keys
  • supportsLockedPatterns - Supports pattern-based locking (MDX only)
  • supportsLocalePlaceholder - Supports [locale] placeholder in file paths
  • createLoader() - Factory function to create the loader

Architecture

Moved from a large switch statement to a standalone registry approach:

export const BUCKETS: Record<string, Bucket> = {
  json: {
    displayName: "JSON",
    supportsFormatter: true,
    supportsLocalePlaceholder: true,
    // ... other capabilities
    createLoader: (ctx) => composeLoaders(...)
  },
  // ... all 29 bucket types
}

This approach was chosen because:

  1. Lightweight consumption - Metadata can be imported without loader dependencies
  2. Build-time usage - Documentation generation doesn't need full loader infrastructure
  3. Clear separation - Metadata (declarative) is separate from loaders (runtime behavior)
  4. Queryability - Easy to lookup by bucket type without function calls

Public API

  • BUCKETS - Complete registry of all bucket types
  • getBucket(type) - Helper to lookup a bucket by type
  • Bucket type - For consumers who need the type definition

Impact

  • No breaking changes - createBucketLoader() signature unchanged
  • Enables future features like auto-generated documentation
  • Makes bucket capabilities explicit and maintainable
  • Simplifies validation and error messaging

🤖 Generated with Claude Code

@davidturnbull davidturnbull changed the title Add metadata registry for bucket types feat: add metadata registry for buckets Oct 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants