Skip to content

Content Automation Scripts ​

The project includes three AI-powered scripts that help maintain high-quality content. These scripts can fix grammar, improve readability, and translate content automatically.

Overview ​

ScriptCommandWhat it does
Grammar Fixpnpm fix:grammarFixes spelling, typos, and grammar errors
Readabilitypnpm improve:readabilityImproves sentence clarity and flow
Translationpnpm translate:enTranslates Dutch content to English

All scripts support dry-run mode (preview changes without writing) and language filters (process only Dutch or only English).

Setup ​

These scripts require API keys. Add them to your .env file in the project root:

env
NUXT_OPENAI_API_KEY=sk-...           # For grammar & readability scripts
NUXT_GOOGLE_TRANSLATE_SECRET=...     # For translation script

WARNING

Never commit .env to Git. The file is already in .gitignore. Ask a team member for the API keys if you don't have them.

Grammar Fix Script ​

Fixes spelling and grammar mistakes with a conservative approach — it only changes things that are clearly wrong.

Commands ​

bash
# Preview changes (recommended first step)
pnpm fix:grammar:dry

# Fix all content (both languages)
pnpm fix:grammar

# Fix only Dutch content
pnpm fix:grammar:nl

# Fix only English content
pnpm fix:grammar:en

What it fixes ​

  • Spelling errors (e.g., "ondersuek" → "onderzoek")
  • Grammar mistakes
  • Expands abbreviations (o.a. → onder andere)
  • Basic punctuation issues

What it preserves ​

  • Markdown formatting (links, headings, lists)
  • Code blocks and components
  • Frontmatter structure
  • Annotation syntax (:annotation{:ids="[1]"}[text])

Readability Improvement Script ​

Goes further than grammar fixes — it restructures sentences and paragraphs for clarity.

Commands ​

bash
# Preview changes
pnpm improve:readability:dry

# Improve all content
pnpm improve:readability

# Improve only Dutch
pnpm improve:readability:nl

# Improve only English
pnpm improve:readability:en

# Force re-process already-processed files
pnpm improve:readability:force

What it improves ​

  • Complex sentences → shorter, clearer ones
  • Passive voice → active voice where appropriate
  • Jargon → plain language
  • Ambiguous pronouns → explicit references
  • Dense paragraphs → broken into digestible chunks
  • Weak transitions → smoother flow

Example ​

Before:

markdown
Er wordt door ons onderzoek gedaan naar de omstandigheden
waarin de varkens worden gehouden en dit is niet goed en
het moet beter en er zijn diverse problemen met de
huisvesting die we hebben gezien tijdens het onderzoek.

After:

markdown
Wij onderzoeken de omstandigheden waarin varkens worden
gehouden. Deze omstandigheden zijn slecht en moeten
verbeteren.

Tijdens het onderzoek zagen we meerdere problemen met
de huisvesting.

TIP

The readability script makes more substantial changes than the grammar script. Always review changes carefully before committing.

Translation Script ​

Translates Dutch content to English automatically using Google Translate.

Commands ​

bash
# Preview what would be translated
pnpm translate:en:dry

# Translate all untranslated content
pnpm translate:en

How it works ​

  1. Scans content/nl/ for files
  2. Checks if a corresponding English file exists in content/en/
  3. Translates missing or outdated files
  4. Preserves all Markdown structure, links, and components

What gets translated ​

  • Markdown body text
  • Frontmatter text fields (title, description, image.alt)
  • JSON text fields (name, plural, label, subLabel)

What stays the same ​

  • Folder and file names
  • URLs and paths
  • Animal keys, welfare brand keys
  • Dates, coordinates, and other technical values
  • Annotation syntax structure

For new Dutch content ​

Run the scripts in this exact order:

bash
# Step 1: Fix grammar in your new Dutch content
pnpm fix:grammar:nl

# Step 2: Improve readability in Dutch
pnpm improve:readability:nl

# Step 3: Translate to English
pnpm translate:en

# Step 4: Fix any grammar artifacts in the English translation
pnpm fix:grammar:en

# Step 5: Improve readability of the English version
pnpm improve:readability:en

For reviewing all existing content ​

bash
# Preview everything first
pnpm fix:grammar:dry
pnpm improve:readability:dry

# If happy with the previews, run for real
pnpm fix:grammar
pnpm improve:readability

# Always review changes before committing
git diff content/

After any script run ​

Always review the changes before committing:

bash
# See what changed
git diff content/

# If everything looks good, commit
git add content/
git commit -m "content: fix grammar in investigation articles"

# If something went wrong, revert
git checkout content/

Progress Tracking ​

Each script tracks which files it has already processed:

ScriptLog file
Grammar.grammar-fix-log.json
Readability.readability-log.json
Translation.translation-log.json

These log files prevent re-processing unchanged files, saving API costs. To force re-processing, use the --force flag or delete the relevant log file.

Cost Estimates ​

OperationFirst run (all content)Incremental (new content)
Grammar fix~$5-15~$1-5
Readability~$5-15~$1-5
Translation~$15-30~$1-5
Total~$25-60~$3-15

Troubleshooting ​

"No changes needed" ​

The file was already processed. Check the log file, or use --force to re-process.

"API key not found" ​

Check your .env file. Make sure the variable names are correct:

  • NUXT_OPENAI_API_KEY for grammar and readability
  • NUXT_GOOGLE_TRANSLATE_SECRET for translation

"Rate limit exceeded" ​

Wait a few minutes and try again. The scripts will resume from where they left off.

Changes are too aggressive ​

The readability script can sometimes restructure more than you'd like. Options:

  • Review changes with git diff and selectively revert
  • Use only the grammar script for a lighter touch
  • Manually edit after the script runs