Wpct i18n
Adapter for multilingual wp plugins.
The plugin offers a coherent and consistent filters API to interact with multiple translation plugins. Integrates with WPML and Polylang.
Installation
Download the latest release
as a zipfile. Once downloaded, decompress and place its content on your WP instance.
wp-content/plugins
's directory.
Go to the releases page to find previous versions.
You can install it with wp-cli
with the next command:
wp plugin install https://git.coopdevs.org/codeccoop/wp/plugins/wpct-i18n/-/releases/permalink/latest/downloads/plugins/wpct-i18n.zip
API
Getters
wpct_i18n_default_language
Get site default language.
Arguments:
-
any $default
: Default value. -
string $format
: Locale or slug.
Returns:
-
string $language
: Site current language.
Example:
$language = apply_filter('wpct_i18n_default_language', null, 'slug');
echo $language;
wpct_i18n_current_language
Get site current language.
Arguments:
-
any $default
: Default value. -
string $format
: Locale or slug.
Returns:
-
string $language
: Site current language.
Example:
$language = apply_filter('wpct_i18n_current_language', null, 'slug');
echo $language;
wpct_i18n_active_languages
Returns the site active languages.
Arguments:
-
any $default
: Default value. -
string $format
: Locale or slug.
Returns:
-
array $lang
: Active languages
Example:
$languages = apply_filters('wpct_i18n_active_languages', [], 'slug');
foreach ($languages as $language) {
// do something
}
wpct_i18n_post_language
Get WP_Post language.
Arguments:
-
any $default
: Default value. -
integer $post_id
: Post ID. -
string $format
: Locale or slug.
Returns:
-
string $language
: Post's language.
Example:
$lang = apply_filters('wpct_i18n_post_language', null, 10, 'locale');
if ($lang !== 'en_US') {
// do something
}
wpct_i18n_post_translations
Get WP_Post current translations.
Arguments:
-
any $default
: Default value. -
integer $post_id
: Post ID.
Returns:
-
array<string, integer>
: Array with languages and post IDs.
Example:
$translations = apply_filters('wpct_i18n_post_translations', [], 10);
foreach ($translations as $lang => $trans_id) {
// do something
}
wpct_i18n_term_translations
Gets WP_Term current translations.
Arguments:
-
any $default
: Default value. -
integer $term_id
: Term ID.
Returns:
-
array<string, integer>
: Array with languages and term IDs.
Example:
$translations = apply_filters('wpct_i18n_term_translations', [], 10);
foreach ($translations as $lang => $trans_id) {
// do something
}
wpct_i18n_is_translation
Get site default language.
Arguments:
-
any $default
: Default value. -
integer $post_id
: Post ID.
Returns:
-
boolean $is_translation
: True if post is a translation.
Example:
$is_translation = apply_filters('wpct_i18n_is_translation', false, 274);
if ($is_translation) {
// do something
}
wpct_i18n_translate_post
Add a post translation to the given post.
Arguments:
-
any $default
: Default value. -
WP_Post $post
: Post object. -
string $lang
: Language code.
Returns:
-
integer $trans_id
: ID of the new translation.
Example:
$trans_id = apply_filters('wpct_i18n_translate_post', null, 1, 'en');
echo $trans_id;
Actions
wpct_i18n_language_switcher
Renders the integration language switcher.
Arguments:
-
any $default
: Default value. -
boolean $echo
: Should return string or echo it.
Returns:
-
string $html
: Language switcher rendered HTML.
Example:
do_action('wpct_i18n_language_switcher', '', true);