首页 > 解决方案 > 在 WPML 中注册的 ACF 选择

问题描述

由于 WPML 不提供翻译[choices]字段的解决方案,我想添加一个自定义函数来在 WPML 中注册它,但是我不是 php 中的明星,但我有以下但它没有在 WPML 字符串翻译中注册它:

$field = get_field_object( 'type_of_property' ); // acf field with choices
if (!empty($field['choices'])) {
    foreach( $field['choices'] as $choice ){
        do_action( 'wpml_register_single_string', 'ACF Domain', 'name'.$choice , $choice );
        $acflabel= apply_filters( 'wpml_translate_single_string', $choice, 'ACF Domain', 'name'.$choice, NULL );
        echo ' - ' . $acflabel;
    }
}

上述方法是否朝着正确的方向发展,还是我需要调用该type_of_property领域内的所有选择?

标签: phpadvanced-custom-fieldswpml

解决方案


我相信你应该能够做到这一点:

$field = get_field_object( 'type_of_property' );
if ( !empty( $field['choices'] ) ) {
    foreach( $field['choices'] as $choice ){
        echo ' - ' . __( $choice, 'ACF Domain' );
    }
}

然后扫描您的主题/插件中的字符串:

  1. 在管理仪表板中,转到WPML > 主题和插件本地化
  2. 选择主题或插件,然后单击以扫描它。
  3. 扫描完成后,您应该能够在“字符串翻译”页面上找到字符串。

文件:

https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#:~:text=To%20scan% 20for%20hard%2Dcoded%20strings%3A


推荐阅读