For developers
Conventions: public functions and hooks use the lingopress_ prefix, the namespace is BallesDev\LingoPress and the text domain is ballesdev-lingopress. No Composer and no external dependencies.
Public API (PHP)
Section titled “Public API (PHP)”Languages
Section titled “Languages”| Function | What it does |
|---|---|
lingopress_languages_list( $args ) |
List of the site’s languages. |
lingopress_default_language( $field ) |
Default language (slug or another field). |
lingopress_current_language( $field ) |
Language of the current request (frontend). |
lingopress_add_language( $args ) |
Creates a language (rewrite rules are flushed automatically). |
Content
Section titled “Content”| Function | What it does |
|---|---|
lingopress_set_post_language( $post_id, $lang ) |
Assigns a language to a post. |
lingopress_get_post_language( $post_id, $field ) |
Language of a post. |
lingopress_save_post_translations( $translations ) |
Links posts as translations ([ 'es' => 12, 'en' => 34 ]). |
lingopress_get_post_translations( $post_id ) |
Translation group of a post. |
lingopress_get_post( $post_id, $lang ) |
ID of a post’s translation in a given language. |
lingopress_set_term_language / lingopress_get_term_language |
Same, for terms. |
lingopress_save_term_translations / lingopress_get_term_translations / lingopress_get_term |
Same, for terms. |
Posts created before LingoPress was activated have no language until they’re saved again; lingopress_set_post_language() assigns it in bulk from a script.
Display and strings
Section titled “Display and strings”| Function | What it does |
|---|---|
lingopress_the_languages( $args ) |
Renders the language switcher. Same options as the shortcode (see Language switcher and menus). |
lingopress_register_string( $name, $text ) |
Registers a translatable string in String translations. |
lingopress__( $text ) / lingopress_e( $text ) |
Returns / prints the translation of a registered string in the current language. |
lingopress_translate_string( $text, $lang ) |
Translation of a string into a specific language. |
Register strings on every request, admin included: String translations lists the strings registered while it loads, and Remove unused strings deletes the saved translations of strings that weren’t registered on that request.
| Hook | Type | When |
|---|---|---|
lingopress_language_defined |
action | The request’s language has been resolved (frontend, in setup_theme). |
lingopress_translated_post_types |
filter | List of translatable post types (posts and pages by default; attachment when media translation is on). |
lingopress_translated_taxonomies |
filter | List of translatable taxonomies (category and post_tag by default). |
lingopress_ai_system_prompt |
filter | Lets you modify the system prompt sent to the AI. |
lingopress_ai_provider |
filter | Lets you replace the AI provider (inject your own). |
lingopress_switcher_items |
filter | Modifies the items in the language switcher. |
lingopress_sync_post_meta |
filter | Adds your own metadata to the sync between translations. |
lingopress_hreflang |
filter | Map of hreflang code => URL before it’s printed. |
lingopress_canonical_redirect |
filter | Canonical URL before redirecting; return false or '' to cancel the redirect. |
Other types of content
Section titled “Other types of content”Shop products, events and other custom post types or taxonomies aren’t translatable out of the box. Add them with the filters:
add_filter( 'lingopress_translated_post_types', function ( $post_types ) { $post_types[] = 'product'; return $post_types;} );
add_filter( 'lingopress_translated_taxonomies', function ( $taxonomies ) { $taxonomies[] = 'product_cat'; return $taxonomies;} );The AI translates the title, content and excerpt; custom fields (post meta) are neither translated nor copied, unless you add them to the sync with lingopress_sync_post_meta.
REST API
Section titled “REST API”langfields (read/write, with capability checks) andtranslationsfields in thewp/v2/*collections of the translatable post types and taxonomies.- Filter collections by language with
?lang=:GET /wp-json/wp/v2/posts?lang=en.lang=allturns the filter off. - Custom endpoints:
GET /wp-json/lingopress/v1/languages(public);POSTandDELETErequiremanage_options. - The block editor preloads its collections already filtered by the language of the post being edited.
WP-CLI
Section titled “WP-CLI”wp lingopress import-polylang(since 1.1.1): imports languages, content languages and translation groups from Polylang, whether it’s active or not. Safe to run more than once: anything already in LingoPress is skipped, and the default language set in LingoPress is kept. Exits with an error when the site has no Polylang data.
API keys in wp-config.php
Section titled “API keys in wp-config.php”Keys defined as constants take priority over the ones saved in LingoPress → AI translation, and the screen shows them as “Defined via” the constant:
define( 'LINGOPRESS_ANTHROPIC_API_KEY', '...' );define( 'LINGOPRESS_GEMINI_API_KEY', '...' );define( 'LINGOPRESS_OPENAI_API_KEY', '...' );define( 'LINGOPRESS_GROQ_API_KEY', '...' );With the WordPress (Connectors) provider (WordPress 7.0+), LingoPress uses wp_ai_client_prompt() and stores no key.
Data model
Section titled “Data model”Four custom taxonomies, no custom tables: lingopress_language and lingopress_term_language (language of posts and terms), lingopress_post_translations and lingopress_term_translations (translation groups). The same model proven by Polylang, with its own prefix: it survives WXR exports/imports and can coexist with Polylang’s data during a migration.
