当前位置: 首页>>代码示例>>PHP>>正文


PHP LimeExpressionManager::SplitStringOnExpressions方法代码示例

本文整理汇总了PHP中LimeExpressionManager::SplitStringOnExpressions方法的典型用法代码示例。如果您正苦于以下问题:PHP LimeExpressionManager::SplitStringOnExpressions方法的具体用法?PHP LimeExpressionManager::SplitStringOnExpressions怎么用?PHP LimeExpressionManager::SplitStringOnExpressions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LimeExpressionManager的用法示例。


在下文中一共展示了LimeExpressionManager::SplitStringOnExpressions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: translate_google_api

 private function translate_google_api()
 {
     $sBaselang = Yii::app()->getRequest()->getPost('baselang');
     $sTolang = Yii::app()->getRequest()->getPost('tolang');
     $sToconvert = Yii::app()->getRequest()->getPost('text');
     $aSearch = array('zh-Hans', 'zh-Hant-HK', 'zh-Hant-TW', 'nl-informal', 'de-informal', 'it-formal', 'pt-BR', 'es-MX', 'nb', 'nn');
     $aReplace = array('zh-CN', 'zh-TW', 'zh-TW', 'nl', 'de', 'it', 'pt', 'es', 'no', 'no');
     $sBaselang = str_replace($aSearch, $aReplace, $sBaselang);
     $sTolang = str_replace($aSearch, $aReplace, $sTolang);
     $error = false;
     try {
         require_once APPPATH . '/third_party/gtranslate-api/GTranslate.php';
         $gtranslate = new Gtranslate();
         $objGt = $gtranslate;
         // Gtranslate requires you to run function named XXLANG_to_XXLANG
         $sProcedure = $sBaselang . "_to_" . $sTolang;
         $parts = LimeExpressionManager::SplitStringOnExpressions($sToconvert);
         $sparts = array();
         foreach ($parts as $part) {
             if ($part[2] == 'EXPRESSION') {
                 $sparts[] = $part[0];
             } else {
                 $convertedPart = $objGt->{$sProcedure}($part[0]);
                 $convertedPart = str_replace("<br>", "\r\n", $convertedPart);
                 $convertedPart = html_entity_decode(stripcslashes($convertedPart));
                 $sparts[] = $convertedPart;
             }
         }
         $sOutput = implode(' ', $sparts);
     } catch (GTranslateException $ge) {
         // Get the error message and build the ouput array
         $error = TRUE;
         $sOutput = $ge->getMessage();
     }
     $aOutput = array('error' => $error, 'baselang' => $sBaselang, 'tolang' => $sTolang, 'converted' => $sOutput);
     header('Content-type: application/json');
     return ls_json_encode($aOutput);
     Yii::app()->end();
 }
开发者ID:joaocc,项目名称:LimeSurvey--LimeSurvey,代码行数:39,代码来源:translate.php

示例2: header

 * Creates a JSON interface for the auto-translate feature
 */
include_once "login_check.php";
header('Content-type: application/json');
include_once 'classes/gtranslate/GTranslate.php';
$sBaselang = $_REQUEST['baselang'];
$sTolang = $_REQUEST['tolang'];
$sToconvert = $_REQUEST['text'];
$aSearch = array('zh-Hans', 'zh-Hant-HK', 'zh-Hant-TW', 'nl-informal', 'de-informal', 'it-formal', 'pt-BR', 'es-MX', 'nb', 'nn');
$aReplace = array('zh-CN', 'zh-TW', 'zh-TW', 'nl', 'de', 'it', 'pt', 'es', 'no', 'no');
$sTolang = str_replace($aSearch, $aReplace, $sTolang);
try {
    $objGt = new Gtranslate();
    // Gtranslate requires you to run function named XXLANG_to_XXLANG
    $sProcedure = $sBaselang . "_to_" . $sTolang;
    $parts = LimeExpressionManager::SplitStringOnExpressions($sToconvert);
    $sparts = array();
    foreach ($parts as $part) {
        if ($part[2] == 'EXPRESSION') {
            $sparts[] = $part[0];
        } else {
            $convertedPart = $objGt->{$sProcedure}($part[0]);
            $convertedPart = str_replace("<br>", "\r\n", $convertedPart);
            $convertedPart = html_entity_decode(stripcslashes($convertedPart));
            $sparts[] = $convertedPart;
        }
    }
    $sConverted = implode(' ', $sparts);
    $aOutput = array('error' => false, 'baselang' => $sBaselang, 'tolang' => $sTolang, 'converted' => $sConverted);
} catch (GTranslateException $ge) {
    // Get the error message and build the ouput array
开发者ID:rkaldung,项目名称:LimeSurvey,代码行数:31,代码来源:translate_google_api.php


注:本文中的LimeExpressionManager::SplitStringOnExpressions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。