Everything public is a global function prefixed shapetranslate_ or a hook named shapetranslate_*.
Ground rules #
- Use the API after
shapetranslate_loaded(or oninit). - All functions are safe when ShapeTranslate is inactive: they return an empty value or a
WP_Error. - A language reference can be a URL slug (
bn), code, locale (bn_BD), language ID or record. Empty means the current language. shapetranslate_translate_string()returns unescaped text. Escape it, or useshapetranslate_esc_html__().
Examples #
Current language and a translated post
add_action( 'shapetranslate_loaded', function () {
$slug = shapetranslate_current_language(); // 'bn', 'en', …
$bn_id = shapetranslate_get_post( 42, 'bn' ); // 0 when none
$home = shapetranslate_home_url( 'fr' );
} );Make a theme string translatable
add_action( 'init', function () {
shapetranslate_register_string( 'my-theme', 'footer_note', 'Made with care in Dhaka' );
} );
// In the template:
shapetranslate_esc_html_e( 'my-theme', 'footer_note', 'Made with care in Dhaka' );Print a switcher in a theme template
<?php
shapetranslate_language_switcher( array(
'display' => 'native_name', // name | language_code
'layout' => 'dropdown', // horizontal | vertical
'show_flags' => true,
'unavailable_behavior' => 'home', // hide | disabled | current
) );
?>