Using Dictionaries
What are dictionaries?
Section titled “What are dictionaries?”Dictionaries are traditional key-value translation files. They’re useful for:
- Shared strings across many components (button labels, error messages)
- Content managed outside your codebase
- Migration from existing i18n setups
Configuration
Section titled “Configuration”{ "dictionaries": { "include": ["src/dictionaries/*.json"], "format": "key-value" }}Create a dictionary
Section titled “Create a dictionary”{ "save": "Save", "cancel": "Cancel", "delete": "Delete", "loading": "Loading..."}useDictionary(filenameKey) looks up one dictionary file and returns a Record<string, string>. The filename key is the dictionary path without the .json extension:
src/dictionaries/common.json→commonsrc/dictionaries/pages/home.json→pages/home
Use in components
Section titled “Use in components”import { useDictionary } from 'tyndale-react';
export function ActionButtons() { const labels = useDictionary('common');
return ( <div> <button>{labels.save ?? 'Save'}</button> <button>{labels.cancel ?? 'Cancel'}</button> </div> );}If no entries match the filename key, useDictionary(filenameKey) returns an empty object.