內容簡介
CMB2-qTranslate 是一款 WordPress 外掛,用於整合 CMB2 和 qTranslate X。它會在所選擇的 CMB2 欄位上方添加語言切換按鈕,以便翻譯內容。
有關更新的文檔,請參閱 Github 專案頁面https://github.com/jmarceli/integration-cmb2-qtranslate。
支援的 CMB2 欄位類型:
文本框
多行文本框
所見即所得編輯器
可重複欄位群組
為了使字段可翻譯,請將 .cmb2-qtranslate 類添加到其上。對於非所見即所得編輯器欄位,您可能更喜歡使用也支援的data-cmb2-qtranslate(自 0.0.3 版本以來)。
使用示例
所見即所得編輯器欄位:
> $field1 = $cmb_demo2->add_field( array(
> 'name' => __( '二次文本', $this->plugin_slug ),
> 'desc' => __( '欄位描述(可選)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_second_text',
> 'class' => 'cmb2',
> 'type' => 'wysiwyg',
> 'options' => array(
> 'editor_class' => 'cmb2-qtranslate'
> )
> ) );
其他欄位:
> $field2 = $cmb_demo->add_field( array(
> 'name' => __( '小文本', $this->plugin_slug ),
> 'desc' => __( '欄位描述(可選)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_textsmall',
> 'class' => 'cmb2',
> 'type' => 'text',
> 'attributes' => array(
> 'class' => 'cmb2-qtranslate'
> )
> ) );
> // 您也可以使用數據屬性代替類來觸發 qTranslate 的欄位
> // 但是,所見即所得編輯器欄位不支援它(WordPress 的限制)
> $field2 = $cmb_demo->add_field( array(
> 'name' => __( '小文本', $this->plugin_slug ),
> 'desc' => __( '欄位描述(可選)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_textsmall',
> 'class' => 'cmb2',
> 'type' => 'text',
> 'attributes' => array(
> 'data-cmb2-qtranslate' => true
> )
> ) );
關於欄位創建的詳細信息可以在 CMB2 項目文檔中找到(https://github.com/WebDevStudios/CMB2/wiki)。
在自訂主題選項頁面上的用法:
參見 https://github.com/qTranslate-Team/qtranslate-x/wiki/Custom-page-(plugin)-integration
您應在 $admin-config 陣列中定義至少一個表單欄位,以觸發 qTranslate LSB 在您的自訂主題選項頁面上運行。否則,您將無法使用 LSB。這是因為默認情況下,qTranslate 只在特定頁面上可用:內容頁面、通用選項頁面和可能的其他一些頁面,但不在您的自訂頁面上(如果您創建了一個自訂頁面)。
需求/依賴
CMB2 (https://pl.wordpress.org/plugins/cmb2/)
qTranslateX (https://pl.wordpress.org/plugins/qtranslate-x/)
連結
Github 專案頁面
外掛標籤
開發者團隊
原文外掛簡介
CMB2-qTranslate is WordPress plugin for CMB2 and qTranslate X integration. Adds language switch buttons above selected CMB2 fields to make content translatable.
For updated docs please refer to the Github project page https://github.com/jmarceli/integration-cmb2-qtranslate.
Supported CMB2 field types:
input
textarea
wysiwyg
repeatable field groups
In order to make field translatable add .cmb2-qtranslate class to it. For non-WYSIWYG fields you may prefer to use data-cmb2-qtranslate which is also supported (since 0.0.3 version).
Usage example
WYSIWYG field:
> $field1 = $cmb_demo2->add_field( array(
> 'name' => __( 'SECOND Text', $this->plugin_slug ),
> 'desc' => __( 'field description (optional)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_second_text',
> 'class' => 'cmb2',
> 'type' => 'wysiwyg',
> 'options' => array(
> 'editor_class' => 'cmb2-qtranslate'
> )
> ) );
Other fields:
> $field2 = $cmb_demo->add_field( array(
> 'name' => __( 'Text Small', $this->plugin_slug ),
> 'desc' => __( 'field description (optional)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_textsmall',
> 'class' => 'cmb2',
> 'type' => 'text',
> 'attributes' => array(
> 'class' => 'cmb2-qtranslate'
> )
> ) );
> // You may also use data-attributes instead of class to trigger qTranslate for the field
> // however it is not supported by WYSIWYG field (WordPress limitation)
> $field2 = $cmb_demo->add_field( array(
> 'name' => __( 'Text Small', $this->plugin_slug ),
> 'desc' => __( 'field description (optional)', $this->plugin_slug ),
> 'id' => $prefix . $this->plugin_slug . '_textsmall',
> 'class' => 'cmb2',
> 'type' => 'text',
> 'attributes' => array(
> 'data-cmb2-qtranslate' => true
> )
> ) );
Detailed info about field creation could be found in CMB2 project documentation (https://github.com/WebDevStudios/CMB2/wiki).
Usage on custom Theme Options Page:
See https://github.com/qTranslate-Team/qtranslate-x/wiki/Custom-page-(plugin)-integration
You should define at least one form field in $admin-config array to trigger qTranslate LSB on your custom Theme Options Page. In other case you will end up with not working LSB. It happens because by default qTranslate is available only on specific pages: content pages, general options and maybe some others, but not your custom page (if you will create one).
Requirements/Dependencies
CMB2 (https://pl.wordpress.org/plugins/cmb2/)
qTranslateX (https://pl.wordpress.org/plugins/qtranslate-x/)
Links
Github project page
