Skip to content

hacklaen/th-simple-translate

Repository files navigation

TH Simple Translate

Version: 1.2.2

A lightweight WordPress multilingual plugin with Google Translate API integration, visual translation editor, and frontend language switcher shortcode. Inspired by TranslatePress — built as a simplified, self-hosted alternative.


Key Features

  • Unlimited Languages — Select a source language and add as many target languages as needed
  • Google Translate API v2 — Automatic machine translation with result caching in the database
  • Output Buffering Translation — Intercepts rendered HTML and replaces text content, title, alt, placeholder attributes, meta tags, and page title
  • Language Switcher Shortcode[thst_language_switcher] renders a dropdown (or list) for language selection
  • Table Editor — Spreadsheet-like admin UI to browse, search, edit, and delete translations per language
  • Visual Editor — TranslatePress-inspired side-by-side editor with page preview iframe, sidebar string list, inline editing, and per-string auto-translate
  • Admin Bar Integration — "🌐 Übersetzen" link on every frontend page opens the visual editor for that URL
  • Cookie-Based Language — No URL rewriting or subdirectories; clean and compatible with all themes
  • notranslate Opt-out — Add class="notranslate" to any HTML element to prevent its translation (industry standard, works on frontend and in REST API filter)

Requirements

Requirement Minimum
PHP 7.4+
WordPress 5.8+
SSL Recommended
Google Cloud Account Required for automatic translation

Installation

cd wp-content/plugins/
git clone git@github.com:hacklaen/th-simple-translate.git

Activate via Plugins → Activate in WordPress admin. The plugin automatically creates its database table on activation.

See the Setup Runbook for detailed configuration instructions.

Quick Start

  1. Go to Simple Translate → Einstellungen
  2. Select your source language (e.g., German)
  3. Add target languages (e.g., English, French)
  4. Enter your Google Translate API Key (how to get one)
  5. Enable Automatische Übersetzung
  6. Save settings
  7. Add [thst_language_switcher] to a widget area or page
  8. Visit your site and switch languages — done!

Architecture

th-simple-translate/
├── th-simple-translate.php          # Entry point, singleton bootstrap
├── includes/
│   ├── class-database.php           # DB schema, CRUD, language list
│   ├── class-settings.php           # Admin settings page
│   ├── class-google-translate.php   # Google Translate API v2 client
│   ├── class-translation-render.php # Output buffering & page translation
│   ├── class-shortcode.php          # [thst_language_switcher] shortcode
│   └── class-editor.php             # Visual editor & table editor AJAX
├── assets/
│   ├── css/ (admin.css, editor.css, frontend.css)
│   └── js/  (admin.js, editor.js)
└── docs/                            # Documentation

Database

All translations are stored in a single table (wp_thst_translations) with a SHA-256 hash index for fast lookups. Translation statuses: 0 = untranslated, 1 = machine, 2 = manually edited.

Translation Pipeline

Page Request → output buffer → extract text nodes (regex)
  → skip notranslate regions → bulk DB lookup
  → auto-translate missing via Google API
  → cache in DB → replace text in HTML (preserve notranslate)
  → serve translated page

Shortcodes

Shortcode Description
[thst_language_switcher] Language selection dropdown
[thst_language_switcher style="list"] Language selection as horizontal link list

Admin Pages

Page Menu Location Purpose
Einstellungen Simple Translate → Einstellungen Source/target languages, API key, auto-translate toggle
Übersetzungen Simple Translate → Übersetzungen Table editor: browse, search, edit, delete per language
Visueller Editor Simple Translate → Visueller Editor Side-by-side iframe editor with live page preview

Documentation

Document Description
Architecture Plugin structure, DB schema, translation pipeline
API Reference AJAX endpoints, shortcodes, hooks, notranslate opt-out
Google Translate API setup, pricing, troubleshooting
Setup Runbook Step-by-step installation and configuration

License

GPL2

About

A simple WordPress translation plugin with Google Translate API integration and visual translation editor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors