No results
7
Developers
Robin edited this page 2026-11-23 00:48:15 +01:00
For developers
Test defined( 'LROB_AI_TRANSLATOR_VERSION' ) before using any of these.
Functions
// Languages of the site, the main one first: locale => [prefix, hreflang, name, default].
lrob_ai_translator_languages();
lrob_ai_translator_default_language(); // 'fr_FR'
lrob_ai_translator_current_language(); // 'en_US' on https://example.com/en/…
// The language a post is written in.
lrob_ai_translator_post_language( $post_id ); // 'fr_FR'
// A post's public address in each language it can be read in: locale => URL.
lrob_ai_translator_post_translations( $post_id );
// [ 'fr_FR' => 'https://example.com/a-propos/', 'en_US' => 'https://example.com/en/about/' ]
Filters
| Filter | Arguments | Use |
|---|---|---|
lrob_ai_translator_skip_request |
bool $skip |
Return true to leave the current request alone (a plugin that serves its own pages in each language). |
lrob_ai_translator_alternates |
array $urls (locale => URL) |
The addresses of the current page in each language, used by the switcher and the hreflang links. |
lrob_ai_translator_skip_object |
bool $skip, string $type, int $id |
Keep an object out of translation ($type: post, term, site). |
lrob_ai_translator_meta_keys |
array $keys, WP_Post $post |
Post meta fields translated with the post (an SEO plugin's title and description). |
lrob_ai_translator_term_meta_keys |
array $keys |
Term meta fields translated with the term (an SEO plugin's title and description of a category). |
lrob_ai_translator_site_options |
array $options |
Texts of a plugin's settings shown to visitors, translated with the site's title: option name => list of keys of that option's array (breadcrumb labels). Served through option_{name}. |
lrob_ai_translator_template_site |
array $site |
The facts used to tell which templates the site serves (posts per type, terms, authors, dates, archives). An SEO plugin that turns off author or date archives sets their count to 0. |
lrob_ai_translator_other_translator |
string $name |
The name of another active translation plugin ("" for none). While one is active, nothing of this plugin reaches visitors' pages. |
lrob_ai_translator_block_attributes |
array $map (block name => attribute names) |
Text attributes of dynamic blocks, translated from the block's comment. |
lrob_ai_translator_taxonomies |
array $taxonomies |
Taxonomies translated (public ones by default; with WooCommerce products, the product attributes too). |
lrob_ai_translator_shortcode_attributes |
array $map (shortcode name => attribute names) |
Text attributes of shortcodes, written in plain text, translated with the page (WPBakery, Divi and Avada's are declared). |
lrob_ai_translator_post_fields |
array $fields, WP_Post $post |
Other texts translated with a post, in its context (field => text). WooCommerce variations use it. |
lrob_ai_translator_builder_types |
array $types |
A page builder's own kinds of content (headers, footers, sections), translated and applied to every page in the compatible mode. |
Examples:
// Translate a custom field with the post.
add_filter( 'lrob_ai_translator_meta_keys', function ( array $keys, WP_Post $post ): array {
$keys[] = 'subtitle';
return $keys;
}, 10, 2 );
// The "label" attribute of a dynamic block is text to translate.
add_filter( 'lrob_ai_translator_block_attributes', function ( array $map ): array {
$map['example/notice'] = array( 'label' );
return $map;
} );
// Never translate the "legal" page.
add_filter( 'lrob_ai_translator_skip_object', function ( bool $skip, string $type, int $id ): bool {
return $skip || ( 'post' === $type && 'legal' === get_post_field( 'post_name', $id ) );
}, 10, 3 );
Actions
| Action | Arguments | When |
|---|---|---|
lrob_ai_translator_purge |
array $urls, bool $all |
A translation changed: purge these addresses (every language) from a cache the plugin does not know, or the whole site when $all is true. See Page caches. |
Constants (wp-config.php)
| Constant | |
|---|---|
LROB_AI_TRANSLATOR_API_KEY |
The Anthropic API key. The settings then name it and do not let it be changed. |
LROB_AI_TRANSLATOR_UPDATE_TOKEN |
A read token for updates from a private repository. |
Background work and WP-CLI
The queue runs on the WP-Cron event lrob_ai_translator_work (every minute while something waits); a daily event, lrob_ai_translator_daily, purges the old log and catches content changed outside the editor. With WP-CLI:
wp cron event run lrob_ai_translator_work
The plugin's own commands:
wp lrob-ai-translator translate --all [--dry-run] [--yes] # everything not translated: estimate, then queue (as the screen's button)
wp lrob-ai-translator translate --all --again # everything translated, again (corrections by hand kept)
wp lrob-ai-translator translate --pending --batch # what already waits, in deferred batches (--direct: one at a time)
wp lrob-ai-translator inspect post 42 [--lang=en_US] # state of each language, and each translation refused at the last attempt beside its source
wp lrob-ai-translator switch [--apply] # the switch from TranslatePress: simulated, or applied
wp lrob-ai-translator addresses <file> [--columns=1,2,3] [--impose] # a table of addresses: compared, or imposed
Each one fails (exit code 1) while something is wrong: an address that would change, a table with errors.
What is stored
Tables {prefix}lrobait_*: the index of contents and their state per language, the translated texts and segments, the translated slugs, the batches, the log and the daily totals. The settings are in the option lrob_ai_translator. Translations are served through WordPress's own filters; posts are never modified.