WPML
apply_filters( 'wpml_translate_single_string', string $original_value, string $domain, string $name, string $language_code )
类型
filter
WPML 版本
3.2

说明

*检索单个(而非作为包的一部分的字符串**)文本字符串的翻译。该过滤器会查找具有匹配 $domain 和 $name 的字符串。如果找到,它将在当前语言或您指定的语言中查找翻译。如果存在翻译,它将返回该翻译。否则,它将返回原始字符串。

*要注册用于翻译的字符串,请参阅:wpml_register_single_string

**要检索作为包的一部分的字符串翻译,请参阅:wpml_translate_string

注意:此钩子需要 WPML 字符串翻译模块

参数

$original_value
(字符串) (必填) 字符串的原始值
$domain
(字符串) (必填) 字符串的注册域
$name
(字符串) (必填) 字符串的注册名称
$language_code
(字符串) (选填) 返回此语言的翻译。默认为 NULL,即返回当前语言

使用示例

我们继续使用在“wpml_register_single_string”动作钩子中使用过的同一个小工具示例。您可能需要前往该部分回顾相关内容。我们在小工具的输出函数中使用”wpml_translate_single_string”过滤器

示例
function widget($args, $instance){
        extract($args);
        $title               = apply_filters('widget_title', $instance['title'] );
        $custom_input        = apply_filters('wpml_translate_single_string', $instance['custom_input'], 'Widgets', 'Custom Widget - input field' );
        $custom_textarea     = apply_filters('wpml_translate_single_string', $instance['custom_textarea'], 'Widgets', 'Custom Widget - textarea field' );

        # Before the widget
        echo $before_widget;

        # The title
        if ( $title )
        echo $before_title . $title . $after_title;

        # Output...

wpml_media_url, wpml_media_id, force_suppress_filters, wpml_get_translated_slug, wpml_home_url, wpml_translate_string, wpml_elements_without_translations, wpml_permalink, wpml_unfiltered_admin_string, wpml_element_link

所有 12 个 获取本地化内容 钩子 →