Skip to content

werlen-nevio/LanguageTool-Open-Source-API

Repository files navigation

LanguageTool Browser Extension (Open Source API)

A lightweight browser extension that provides real-time grammar and spell checking using the LanguageTool API. Connect to any LanguageTool API endpoint - whether self-hosted or official - for instant writing feedback across all text fields on the web.

Features

  • Real-time Grammar & Spell Checking: Instant feedback as you type in any text field
  • Visual Underlines: Errors are highlighted with color-coded underlines
  • Smart Suggestions: Click on any underlined error to see replacement suggestions
  • Auto-Check Mode: Automatically checks text as you type (configurable)
  • Flexible Endpoints: Connect to self-hosted or official LanguageTool servers
  • Multi-Language Support: Works with any language supported by LanguageTool
  • Context Menu Integration: Right-click in any text field to manually trigger a check
  • Status Badge: Visual indicator showing check status and error count
  • Performance Optimized: Intelligent debouncing and caching to minimize API calls

Installation

From Source

  1. Clone or download this repository
  2. Open your browser's extension management page:
    • Chrome/Edge: Navigate to chrome://extensions/
  3. Enable "Developer mode"
  4. Click "Load unpacked" and select the extension directory

Configuration

After installation, click the extension icon or right-click in any text field and select "Options" to configure:

  1. Endpoint: The URL of your LanguageTool API server (default: http://localhost:8081)
  2. Language: The language code for checking (e.g., en-US, de, fr)
  3. Auto-Check: Enable/disable automatic checking as you type
  4. Debounce: Delay in milliseconds before sending a check request (recommended: 600-1200ms)

Self-Hosting LanguageTool

Running your own LanguageTool server gives you complete control over your data and removes dependency on external services.

Option 1: Docker (Recommended)

The easiest way to self-host LanguageTool is using Docker:

docker run -d \
  --name languagetool \
  -p 8081:8010 \
  -e langtool_languageModel=/ngrams \
  -e Java_Xms=512m \
  -e Java_Xmx=1g \
  erikvl87/languagetool

This will start LanguageTool on http://localhost:8081.

With n-gram datasets for better quality:

docker run -d \
  --name languagetool \
  -p 8081:8010 \
  -e langtool_languageModel=/ngrams \
  -e Java_Xms=2g \
  -e Java_Xmx=4g \
  -v /path/to/ngrams:/ngrams \
  erikvl87/languagetool

Download n-gram datasets from LanguageTool's website.

Option 2: Docker Compose

Create a docker-compose.yml file:

version: '3'
services:
  languagetool:
    image: erikvl87/languagetool
    container_name: languagetool
    ports:
      - "8081:8010"
    environment:
      - langtool_languageModel=/ngrams
      - Java_Xms=512m
      - Java_Xmx=1g
    restart: unless-stopped

Start with:

docker-compose up -d

Option 3: Manual Installation

  1. Install Java: LanguageTool requires Java 8 or later

    # Ubuntu/Debian
    sudo apt install openjdk-11-jre-headless
    
    # macOS
    brew install openjdk@11
  2. Download LanguageTool: Get the standalone version from languagetool.org

    wget https://languagetool.org/download/LanguageTool-stable.zip
    unzip LanguageTool-stable.zip
    cd LanguageTool-*
  3. Start the Server:

    java -cp languagetool-server.jar org.languagetool.server.HTTPServer \
      --port 8081 \
      --allow-origin "*"
  4. Test the Server:

    curl -d "text=This is a test" -d "language=en-US" http://localhost:8081/v2/check

Option 4: Using LanguageTool Plus/Premium

If you prefer not to self-host, you can use the official LanguageTool service:

  1. Sign up at languagetool.org
  2. Set the endpoint to: https://api.languagetoolplus.com
  3. Note: The free tier has rate limits; consider LanguageTool Premium for unlimited checks

Server Configuration Tips

  • Memory: Allocate at least 512MB RAM (1-2GB recommended for better performance)
  • Port: The default port is 8010 in Docker, but you can map it to any port
  • CORS: Use --allow-origin "*" to allow browser requests (already configured in Docker image)
  • Performance: Enable n-gram datasets for improved detection quality
  • Multiple Languages: LanguageTool supports 30+ languages out of the box

Network Configuration

If running LanguageTool on a different machine:

  1. Make sure the port is accessible from your browser's machine
  2. Update the extension's endpoint setting to point to your server's IP/hostname
  3. Example: http://192.168.1.100:8081 or https://languagetool.yourdomain.com

Security Considerations

  • Local Network Only: If possible, keep LanguageTool on your local network
  • HTTPS: For production deployments, use HTTPS with a reverse proxy (nginx, Caddy)
  • Authentication: Consider adding authentication if exposing to the internet
  • Firewall: Restrict access to trusted IPs if deploying on a server

Usage

Once configured, the extension works automatically:

  1. Auto-Check Mode: Type in any text field, and errors will appear with underlines after a short delay
  2. Manual Check: Right-click in a text field and select "Mit LanguageTool prüfen" (Check with LanguageTool)
  3. View Suggestions: Click on any underlined error to see replacement suggestions
  4. Apply Fix: Click a suggestion to apply it instantly
  5. Status Badge: Look at the bottom-right corner of each text field to see:
    • Spinner: Check in progress
    • Green checkmark: No errors found
    • Number: Count of detected errors

Supported Text Fields

The extension works with:

  • Standard HTML <textarea> elements
  • Text <input> fields (text, search, email, url, tel)
  • ContentEditable elements (rich text editors)

Browser Compatibility

  • Chrome/Edge: Full support (Manifest V3)
  • Brave, Opera, Vivaldi: Should work as Chromium-based browsers

Privacy

This extension:

  • Only sends text content to the configured LanguageTool endpoint
  • Does not collect or transmit any personal data
  • Does not use external analytics or tracking
  • Stores settings locally using browser storage sync

When self-hosting, your text never leaves your network.

Development

Project Structure

languagetool-extension/
├── manifest.json       # Extension configuration
├── background.js       # Service worker (context menu)
├── content.js          # Main content script (checking logic)
├── options.html        # Settings page
├── options.js          # Settings page logic
├── options.css         # Settings page styles
├── overlay.css         # Underline and popover styles
└── icons/              # Extension icons

Key Components

  • content.js: Handles text monitoring, API calls, and UI rendering
  • background.js: Manages context menu integration
  • options.js: Settings management with chrome.storage.sync

API Integration

The extension uses the LanguageTool HTTP API v2:

POST /v2/check
Content-Type: application/x-www-form-urlencoded

text=Your text here&language=en-US

Response contains matches with offset, length, message, and replacement suggestions.

Troubleshooting

Extension not checking text

  1. Verify the LanguageTool server is running and accessible
  2. Check the endpoint URL in extension options (must include http:// or https://)
  3. Test the API manually: curl -d "text=test" -d "language=en-US" http://localhost:8081/v2/check
  4. Check browser console for error messages

CORS errors

If using a self-hosted server, ensure it's started with --allow-origin "*" or configure proper CORS headers.

Underlines not appearing

  1. Verify auto-check is enabled in options
  2. Type more than 8 characters (minimum threshold)
  3. Check if the text field type is supported
  4. Look for the status badge - spinner means checking, number means errors found

Performance issues

  1. Increase the debounce time in settings (try 1000-1500ms)
  2. Ensure your LanguageTool server has adequate resources
  3. Consider enabling caching on the server side

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This extension is open source. LanguageTool itself is licensed under LGPL 2.1 or later.

Acknowledgments

Links

About

Grammar and spell checker with real-time underlines. Connect to any LanguageTool API endpoint (self-hosted or official) for instant writing feedback in text fields across the web.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors