如何在WordPress中的自定义翻译短代码中返回翻译的字符串

时间:2017-12-11 13:43:53

标签: php wordpress

我有一个翻译插件(Loco Translate),我想在wordpress管理的页面编辑器中使用<?php _e('text', 'domain'); ?>翻译我的页面。可能吗 ? 我尝试了短代码但结果却被评论了......谢谢!

编辑:

我的短代码功能:

function translation_shortcode($atts) {

     $a = shortcode_atts( array(
        'name' => '',
    ), $atts );

    return "<?php echo __('" . $a['name'] . "', 'pulsdesign'); ?>";
}

add_shortcode( 'translation', 'translation_shortcode' );

在页面编辑器中:

[translation name="Softwares and sensors for remote and real time physiological monitoring"]

结果:

<!--?php echo __('Softwares and sensors for remote and real time physiological monitoring', 'pulsdesign'); ?-->

1 个答案:

答案 0 :(得分:2)

问题似乎是<?php ...

这将返回字符串 return __($a['name'] 'pulsdesign');,它将作为整体返回到浏览器中。浏览器不知道如何处理php代码,他们无法执行它。

相反,你应该返回翻译结果,正如Marcel Kohls评论的那样:

problems summary :: [ivy:resolve] :::: WARNINGS [ivy:resolve] module not found: org.apache.hadoop#hadoop-common;0.21.0 [ivy:resolve] ==== fs: tried [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-common/[revision]/hadoop-common-[revision].pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common;latest.integration!hadoop-common.jar: [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-common/[revision]/hadoop-common-[revision].jar [ivy:resolve] ==== apache-snapshot: tried [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-common/0.21.0/hadoop-common-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common;0.21.0!hadoop-common.jar: [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-common/0.21.0/hadoop-common-0.21.0.jar [ivy:resolve] ==== maven2: tried [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common/0.21.0/hadoop-common-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common;0.21.0!hadoop-common.jar: [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common/0.21.0/hadoop-common-0.21.0.jar [ivy:resolve] module not found: org.apache.hadoop#hadoop-common-test;0.21.0 [ivy:resolve] ==== fs: tried [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-common-test/[revision]/hadoop-common-test-[revision].pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common-test;latest.integration!hadoop-common-test.jar: [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-common-test/[revision]/hadoop-common-test-[revision].jar [ivy:resolve] ==== apache-snapshot: tried [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-common-test/0.21.0/hadoop-common-test-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common-test;0.21.0!hadoop-common-test.jar: [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-common-test/0.21.0/hadoop-common-test-0.21.0.jar [ivy:resolve] ==== maven2: tried [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common-test/0.21.0/hadoop-common-test-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-common-test;0.21.0!hadoop-common-test.jar: [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-common-test/0.21.0/hadoop-common-test-0.21.0.jar [ivy:resolve] module not found: org.apache.hadoop#hadoop-hdfs;0.21.0 [ivy:resolve] ==== fs: tried [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-hdfs/[revision]/hadoop-hdfs-[revision].pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-hdfs;latest.integration!hadoop-hdfs.jar: [ivy:resolve] /Users/Hassan/.m2/repository/org/apache/hadoop/hadoop-hdfs/[revision]/hadoop-hdfs-[revision].jar [ivy:resolve] ==== apache-snapshot: tried [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-hdfs/0.21.0/hadoop-hdfs-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-hdfs;0.21.0!hadoop-hdfs.jar: [ivy:resolve] https://repository.apache.org/content/repositories/snapshots/org/apache/hadoop/hadoop-hdfs/0.21.0/hadoop-hdfs-0.21.0.jar [ivy:resolve] ==== maven2: tried [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-hdfs/0.21.0/hadoop-hdfs-0.21.0.pom [ivy:resolve] -- artifact org.apache.hadoop#hadoop-hdfs;0.21.0!hadoop-hdfs.jar: [ivy:resolve] http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-hdfs/0.21.0/hadoop-hdfs-0.21.0.jar [ivy:resolve] :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve] :: UNRESOLVED DEPENDENCIES :: [ivy:resolve] :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve] :: org.apache.hadoop#hadoop-common;0.21.0: not found [ivy:resolve] :: org.apache.hadoop#hadoop-common-test;0.21.0: not found [ivy:resolve] :: org.apache.hadoop#hadoop-hdfs;0.21.0: not found [ivy:resolve] :::::::::::::::::::::::::::::::::::::::::::::: [ivy:resolve] [ivy:resolve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS BUILD FAILED /Users/Hassan/Documents/All My Techniques Source Code (Implemented)/CheckPointing Hadoop/Source Code/CheckPointing-Hadoop/mapred/build.xml:1861: impossible to resolve dependencies: resolve failed - see output for details Total time: 11 seconds Hassan:mapred Hassan$