Message Keys and Structure
Nested keys are supported but not recommended
Paraglide JS supports nested keys through bracket notation syntax m["something.nested"]()
, which simulates nesting without actually creating nested JavaScript objects. This approach leverages TypeScript's template literal types to provide type safety while maintaining the flat structure that enables tree-shaking.
Why we recommend flat keys
1. Flat lists are the native format
- Databases operate on flat structures: Messages are stored in SQLite internally, which naturally uses flat key-value pairs
- Applications use flat lookups: At runtime, messages are accessed by key, not by traversing nested objects
- Compilers work with flat lists: The compilation process transforms each message into an individual function
2. Nested keys create unnecessary complexity
While nested keys might seem nice for developers initially, they create pain for everyone else in the ecosystem:
- Translators: Have to understand hierarchical structures instead of simple key-value pairs
- Build tools: Need to parse and transform nested structures into flat lists
- Runtime performance: Simulated nesting through bracket notation prevents some optimizations
- Type safety: While TypeScript template literals provide types, direct function names offer better IDE support
How to use nested keys (if you must)
If you have existing messages with dot notation, you can access them using bracket notation:
Recommended approach: Flat keys
Instead of nesting, use prefixes to organize related messages:
Benefits of this approach:
Working with dynamic keys
For dynamic menu systems, create explicit mappings:
Migration guide
If you're migrating from a library that uses nested keys: