简体   繁体   English

WordPress SDL翻译的简码

[英]WordPress SDL Translation for shortcodes

I have some sort of sort of shortcodes like [wp-text text="Lorem Impsum etc" button_text="Read More"][/wp-text] . 我有某种短代码,例如[wp-text text="Lorem Impsum etc" button_text="Read More"][/wp-text]

I want to extract this shortcode from post content field and then send these two attributes: text and button_text for translation to SDL World Server. 我想从post content field提取此短代码,然后发送这两个属性: textbutton_text以转换到SDL World Server。

After getting response from SDL, I want to replace that shortcode accordingly. 从SDL获得响应后,我想相应地替换该短代码。

Any Suggestion or Help? 有任何建议或帮助吗?

Here is a suggestion about your approach: 这是关于您的方法的建议:

  1. Parse the shortcode attributes 解析简码属性

Having the content you can parse the variable and extract all short code attributes with the provided Wordpress function shortcode_parse_atts 有了内容,您可以解析变量并使用提供的Wordpress函数shortcode_parse_atts提取所有短代码属性

  1. For each parsed value make a API call to the provided SDL World Server REST API ( Or for better performance you can group all the translations and translate them with one complex API call if supported from the API ) 对于每个解析的值,请对提供的SDL World Server REST API进行API调用( 或者为获得更好的性能,您可以对所有翻译进行分组,并在一个复杂的API调用(如果该API支持的话 )进行翻译)

  2. After getting the response replace the original strings with the translated strings. 得到响应后,将原始字符串替换为翻译后的字符串。

Here is example pseudo code in PHP: 这是PHP中的示例伪代码

$shotcode_attributes = shortcode_parse_atts( $post->post_content );

foreach ( $shortcode_attributes as $attribute => $value ) {
  // Make SDL World Server API call refer to the API documentation for the exact way
  $translated_value = $sdlApiClient->translate( $value );

  // Replace the translated value.
  // You can be more precise here ensuring that the value is inside the shortcode
  $post->post_content = str_replace(
    "{$attribute}=\"{$value}\"", 
    "{$attribute}=\"{$translated_value}\"", 
    $post->post_content
  );
}

You can also research and examine the provided SDL WordPress Connector 您还可以研究和检查提供的SDL WordPress Connector

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM