=== AI Translate BYOK ===
Contributors: deusacc
Tags: translation, multilingual, ai, localization, content
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.5.14
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Translate posts and pages into any language with an AI model — bring your own API key (BYOK), draft review before publishing, no plugin subscription.

== Description ==

Reaching readers and buyers in their own language is one of the highest-leverage things a site can do, but per-word translation agencies are slow and expensive, and most "AI translate" plugins lock the good part behind a monthly subscription. AI Translate BYOK adds one button to the post editor: pick a language, click Translate, and a full draft translation — title and content, HTML and shortcodes preserved — appears ready for a human to review and publish.

Features:

* One-click translation from the post/page editor sidebar, for any public post type.
* Human review by default: translations are created as drafts, never overwrite the original, and only go live when you (or an editor) publish them. An "auto-publish" mode is available for teams that trust the pipeline.
* Preserves HTML structure, shortcodes and Gutenberg block markup — only the human-readable text is translated.
* No cost for the plugin itself: you use your own API key and only pay (if at all) the provider you choose.
* Built-in shortlist of the languages with the highest demand (Arabic, Hindi, Chinese, Khmer, Swahili) plus the usual European/Asian languages — or type any language name.
* Know the cost before you click: the editor box estimates the tokens and the price of the translation with your model (list prices of common OpenAI, Anthropic, Gemini and DeepSeek models built in, or your own price per 1M tokens).
* A dedicated Posts > AI Translations page listing every translation created, its status and its source.
* Multilingual SEO without a multilingual plugin: published translations and their original are linked with `hreflang` alternate tags (the original is the `x-default`), so search engines serve each reader the right language instead of treating the copies as duplicates. If Polylang or WPML is active, they handle this and the plugin stays out of the way.
* A language switcher for readers: the `[aitr_languages]` shortcode or the "AI Translate: languages" block lists the other languages of the current post. No branding or credit links on your site.

BYOK (Bring Your Own Key): the plugin ships no API key of its own and does not act as a paid intermediary — a specific requirement of the WordPress.org policy on plugins that use external services, and at the same time the reason it costs less than subscription-based competitors.

= Free vs Full version =

This version is free with no limits: translate as many posts as you like, into any language. [The full version](https://shop.lumnika.com/ai-translate-byok.html) (one-time payment, no subscription) is for sites translating a whole catalogue: bulk translation of many posts at once from the Posts list, translation of Yoast SEO / Rank Math titles and meta descriptions and of categories and tags, automatic linking of translations in Polylang or WPML, WooCommerce products (variations, custom and global attributes such as Color or Size, prices, SKU and stock kept in sync across languages), translated navigation menus (classic and block themes), Elementor pages (headings, text, buttons and tabs translated, layout and styles kept), per-language URLs without Polylang or WPML (translations served at /de/your-post/ with a 301 from the old address, the right html lang and one sitemap per language), automatic translation on publish with a glossary of terms to keep, and outdated-translation tracking: when you edit an original, its translations are flagged as outdated and can be re-translated in place, one by one or in bulk. It replaces this plugin in place with the same settings; its license key comes pre-filled in the download (nothing to type) and also brings automatic updates from the shop.

== External services ==

This plugin sends the title and content of the post you choose to translate to the AI endpoint that you configure yourself in the settings (API base URL, API key and model). No request is sent anywhere until you enter your own credentials, and no data passes through any server belonging to the plugin author. Which provider receives the data, and under which terms and privacy policy, is entirely your choice — by default the plugin points at the OpenAI chat completions API (https://openai.com/policies/terms-of-use, https://openai.com/policies/privacy-policy). On WordPress 7.0+ you can instead pick "WordPress AI": the request then goes through the AI client built into WordPress to the provider you connected in Settings > Connectors, under that provider's terms.

Optional setup tips: only if you tick "Send me setup tips" in the settings, the email address you enter is sent once to shop.lumnika.com (the plugin author's shop, https://shop.lumnika.com/) together with the plugin name, to send you a few setup tips by email. The box is unticked by default and nothing is sent otherwise.

== Installation ==

1. Upload the `ai-translate-byok` folder to `/wp-content/plugins/`.
2. Activate the plugin from the WordPress Plugins menu.
3. Go to Settings > AI Translate BYOK and enter your API key (and, if you are not using OpenAI, your provider's URL and model name).
4. Open any post or page, pick a language in the "AI Translate BYOK" box in the sidebar, and click Translate.

== Frequently Asked Questions ==

= Can I use the AI already configured in WordPress, without a key? =
Yes, on WordPress 7.0 or newer. Connect a provider once in Settings > Connectors, then pick "WordPress AI" in this plugin's Provider list and save: no key is pasted here. Leave the model on "auto" to let WordPress choose, or type a model name you prefer. On older WordPress versions this option is simply not shown.

= Do I need an OpenAI key specifically? =
No. Pick your provider in the "Provider" list of the settings (OpenAI, OpenRouter, Anthropic Claude, Google Gemini, DeepSeek, Groq, Mistral, DeepL or a local Ollama) and the base URL and a recommended model are filled in for you; paste your key and save. Any other endpoint compatible with the OpenAI "chat completions" API works too: choose "Custom" and enter its URL and model.

= Is there a free provider? =
Yes. Google Gemini and Groq both offer a free tier with an API key and no credit card; a local Ollama costs nothing at all. Pick one in the "Provider" list.

= Does the translation overwrite my original post? =
No. It always creates a new, separate post in the target language, linked back to the original.

= Does it publish automatically? =
Not by default. New translations are created as drafts so a human can review them before they go live. You can switch to "publish immediately" in the settings if you prefer.

= Does the plugin send my content to a server of its own? =
No. Requests go directly from your site to the API provider you configured yourself.

= Is there a limit on translations? =
No. The only cost is what your AI provider charges for the requests you make with your own key.

== Screenshots ==

1. The AI Translate BYOK box in the post editor sidebar: pick a language, click Translate.
2. The translation is created as a separate draft, headings, links and block markup preserved, ready for a human to review and publish.
3. Posts > AI Translations lists every translation with its language, status and source post.
4. Settings: any OpenAI-compatible endpoint (here Groq, a free tier), your own API key and model, and the status of new translations.

== Changelog ==

= 1.5.14 =
* Rate limits (429/503) are retried after the provider's Retry-After instead of failing at once; a rejected API key now says so clearly. Your API key is no longer printed back into the settings page.
* Full version: the bulk queue no longer drops posts on a timeout or rate limit (retried up to 3 times); a rejected key or exhausted credit pauses it with a Resume button, and every failed post is listed instead of only the last one.
* Full version: the site limit is rechecked every hour (with a "Check again" link), and uninstalling removes all plugin data.

= 1.5.13 =
* When your AI provider account runs out of credit (or hits its daily quota) the plugin now says so clearly and pauses the bulk and re-sync queues instead of failing every remaining post: top up, then run again.

= 1.5.12 =
* Long posts into Hindi, Thai, Russian, Arabic, Chinese, Japanese and other non-Latin languages are sent in smaller parts sized for the target script, so they no longer hit the AI output limit; a part that is still cut off is split again and retried instead of failing.
* WordPress AI Client (Settings > Connectors): a response cut off by the token limit is now rejected instead of being saved half-translated.

= 1.5.11 =
* Full version: menus, WooCommerce attributes, Elementor pages and SEO/excerpt fields with many texts are translated in batches, so long lists into languages like Hindi or Japanese no longer hit the AI output limit; texts the AI skips are asked again, and line breaks in excerpts are kept.

= 1.5.10 =
* Image alt and title attributes inside the content are now translated too.
* Full version: ACF text, textarea and WYSIWYG fields are translated (formatting kept); other ACF field types, repeaters and flexible content are copied unchanged.

= 1.5.9 =
* License: "Deactivate on this site" button frees a seat for another domain without emailing support.
* Multisite: network-activated installs take one license key in Network Admin > Settings, and the network counts as one site.

= 1.5.8 =
* A license key now counts the site it unlocks the full version on (3 sites per license); past the limit the full-version features turn off on that site with a clear notice and upgrade links.

= 1.5.7 =
* New: on WordPress 7.0+ you can pick "WordPress AI" as the provider: translations go through the AI client built into WordPress, using the connectors already set up in Settings > Connectors, so no API key is pasted into this plugin.
* Fix: uninstall cleanup on multisite no longer uses a global variable name without the plugin prefix.

= 1.5.6 =
* New: DeepL as a provider (Free and Pro keys, detected automatically). Block markup and shortcodes are kept out of the translation and restored unchanged.

= 1.5.5 =
* After 5 and 25 posts translated one by one, a dismissible notice points to the full version (whole site in one click).
* Settings: optional, unticked "Send me setup tips" email opt-in; the email is sent to shop.lumnika.com only if you tick it.

= 1.5.4 =
* Settings page: links to the other BYOK plugins from Lumnika (static links, no remote calls).

= 1.5.3 =
* First run: activating the plugin opens the settings with a 2-step getting-started box and a "Translate your first post" button.
* After 10 translations, a one-time dismissible notice asks for a WordPress.org review (dashboard, plugins and plugin settings only).
* Full version: Elementor pages are translated too: widget texts (headings, text editor, buttons, tabs and other repeaters) in two requests, layout, ids and page template kept.

= 1.5.2 =
* Fix: the Google Gemini preset now uses `gemini-3.5-flash-lite` (Google no longer serves `gemini-2.5-flash-lite` to new API keys).
* Full version: automatic updates from Plugins > Updates, with the license key included in your download.

= 1.5.1 =
* Fix: the DeepSeek preset now uses `deepseek-flash` (DeepSeek retired `deepseek-chat`); the Google Gemini preset uses the stable `gemini-2.5-flash-lite`.
* The cost estimate knows gpt-5-mini, gpt-5-nano, gemini-2.5-flash-lite, deepseek-flash and deepseek-v4-pro (DeepSeek at peak-hour rates).

= 1.5.0 =
* New: "Provider" list in the settings with OpenAI, OpenRouter, Anthropic (Claude), Google Gemini, DeepSeek, Groq, Mistral and Ollama (local): picking one fills in the base URL and a recommended model, with a link to get the API key. "Custom" keeps any OpenAI-compatible endpoint.
* The cost estimate knows the default models of the new providers.
* Developers: new `aitr_provider_presets` filter to add or change providers.

= 1.4.0 =
* Full version: WooCommerce global attributes (Color, Size...) are translated too: each term is translated once and reused across products, and variations and default selections point to the translated terms, so filters and variation pickers show the translated language.
* Full version: navigation menus of block themes (Twenty Twenty-Four, Twenty Twenty-Five...) are translated, with links pointing to the translated pages.

= 1.3.0 =
* New: cost estimate in the editor box before translating (tokens and USD for the selected language), based on the list price of common models or on your own price per 1M tokens in the settings.
* Developers: new `aitr_model_prices` filter to add or update model prices.

= 1.2.0 =
* New: `hreflang` alternate links between an original and its published translations (x-default = original), when Polylang/WPML are not active.
* New: `[aitr_languages]` shortcode and "AI Translate: languages" block, a simple language switcher for readers.
* Developers: new `aitr_lang_code` filter to map a custom language name to its hreflang code.
* Full version: outdated-translation tracking and "Re-translate with AI" (single, bulk, or all outdated at once).

= 1.1.1 =
* Translations created in the background (WP-Cron) keep the author of the original post.

= 1.1.0 =
* No monthly limit any more: the free version translates without quotas.
* Developers: new `aitr_translation_created` action after each translation.

= 1.0.1 =
* Fix: translations of Gutenberg posts could lose the block markup (`<!-- wp:... -->` comments), because the sanitization step treated them as unrecognized HTML comments and stripped them. Block structure is now preserved.

= 1.0.0 =
* First release: BYOK translation from the post editor, draft-by-default workflow, translations list page, free/full-version tier.
