Convert American spellings to British English. Originally created to fix the US spelling output from LLMs, but useful for anyone who needs British spellings in their documents and code.
- Multiple File Types: Text, markdown, LaTeX, HTML, JSON, and code files
- Smart Code Handling: Only converts comments and docstrings in code files, never string literals or identifiers
- Context-Aware: Preserves quoted text like
'colorScheme'in comments (API references) - Interactive Mode: Review and approve changes one by one
- Hook Integration: Automatically fix spellings when writing files
Requires uv and optionally just.
# Install dependencies
just sync
# or: uv sync
# Build standalone binary and install to ~/.local/bin
just build && just install# Process files
britfix --input file.txt
britfix --input "*.md" --recursive
# Process from stdin
echo "The color was analyzed" | britfix --quiet
# Output: The colour was analysed
# Interactive mode
britfix --input document.md --interactive
# Dry run
britfix --input "src/*.py" --dry-run--input: Input file(s) or pattern(s). If omitted, reads from stdin--interactive,-i: Interactive approval mode--dry-run: Preview changes without modifying files--no-backup: Skip backup creation--recursive: Process files recursively--quiet: Only output corrected text (for pipelines)
Different file types are handled by different strategies, configured in config.json:
| Strategy | Extensions | Behaviour |
|---|---|---|
| text | .txt |
Convert everything |
| markdown | .md, .markdown, .mdown, .mkd, .mdx |
Preserve code spans and code blocks |
| latex | .tex |
Skip LaTeX commands and math |
| html | .html, .htm, .xml |
Skip HTML tags |
| json | .json |
Only convert string values |
| code | .py, .js, .ts, etc. |
Only convert comments and docstrings |
For code files, the tool intelligently handles context:
Converted (prose in comments/docstrings):
# The behavior is favorable -> # The behaviour is favourable
"""This optimizes the color.""" -> """This optimises the colour."""NOT converted (code and API references):
config.get('organization') # String literal - unchanged
payload = {'colorScheme': x} # Dict key - unchanged
# Use 'colorField' for the API # Quoted in comment - unchangedEdit config.json to customise file type handling:
{
"strategies": {
"code": {
"extensions": [".py", ".js", ".ts", ...]
}
}
}The britfix_hook.py script integrates with tools that support hooks to automatically fix spellings when files are written.
-
Install dependencies:
just sync -
Configure your tool to call the hook. Example for settings:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "/absolute/path/to/britfix/run-hook.sh",
"timeout": 10
}
]
}
]
}
}Enable logging by uncommenting in run-hook.sh:
export BRITFIX_LOG=/tmp/britfix.logThen watch: tail -f /tmp/britfix.log
just sync # Install dependencies
just test # Run tests
just test-hook # Test hook
just build # Build standalone binary
just clean # Remove build artefactsMIT