/**
  * Translate a long text by Google, if it too long, will separate it..
  *
  * @param   string  $text      String to translate.
  * @param   string  $SourceLan Translate from this language, eg: 'zh-TW'. Empty will auto detect.
  * @param   string  $ResultLan Translate to this language, eg: 'en'. Empty will auto detect.
  * @param   integer $separate  Separate text by a number of words, batch translate them and recombine to return.
  *
  * @return  string    Translated text.
  */
 public static function translate($text, $SourceLan = null, $ResultLan = null, $separate = 0)
 {
     // If text too big, separate it.
     if ($separate) {
         if (Utf8String::strlen($text) > $separate) {
             $text = Utf8String::str_split($text, $separate);
         } else {
             $text = array($text);
         }
     } else {
         $text = array($text);
     }
     $result = '';
     // Do translate by google translate API.
     foreach ($text as $txt) {
         $result .= self::gTranslate($txt, $SourceLan, $ResultLan);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Test...
  *
  * @param   string  $string        @todo
  * @param   string  $split_length  @todo
  * @param   string  $expect        @todo
  *
  * @return  array
  *
  * @covers        Windwalker\String\Utf8String::str_split
  * @dataProvider  seedTestStr_split
  * @since         1.0
  */
 public function testStr_split($string, $split_length, $expect)
 {
     $actual = Utf8String::str_split($string, $split_length);
     $this->assertEquals($expect, $actual);
 }