Documentation

GoogleTranslate
in package

Wrapper class to get translation.

See staticTranslate for a clssical translation.

Table of Contents

Constants

DEFAULT_DOMAIN  = null

Properties

$lastResult  : mixed
$gglDomain  : mixed
$headers  : mixed
$langFrom  : mixed
$langTo  : mixed
$urlFormat  : mixed

Methods

__construct()  : mixed
array_iunique()  : array<string|int, mixed>
getDomain()  : string
Return the current domain.
makeCurl()  : string|bool
setDomain()  : void
setLangFrom()  : GoogleTranslate
setLangTo()  : GoogleTranslate
staticTranslate()  : array<string|int, string>|false
Returns an array of Translations
translate()  : array<string|int, mixed>|false
generateToken()  : string
setHeaders()  : void

Constants

Properties

$urlFormat

private static mixed $urlFormat = "http://translate.google.%s/translate_a/single" . "?client=t&q=%s&hl=en&sl=%s&tl=%s&dt=t&dt=at&dt=bd&ie=UTF-8&oe=UTF-8&oc=1&" . "otf=2&ssel=0&tsel=3&tk=%s"

Methods

__construct()

public __construct(mixed $from, mixed $to) : mixed
Parameters
$from : mixed
$to : mixed

array_iunique()

public static array_iunique(mixed $array) : array<string|int, mixed>
Parameters
$array : mixed
Return values
array<string|int, mixed>

getDomain()

Return the current domain.

public static getDomain(string|void $domain) : string
Parameters
$domain : string|void

(Optionnal) Google Translate domain to use.

  • Usually two letters (e.g "en" or "com")
  • Random if not provided.
Return values
string

makeCurl()

public static makeCurl(mixed $url[, mixed $cookieSet = false ]) : string|bool
Parameters
$url : mixed
$cookieSet : mixed = false
Return values
string|bool

setDomain()

public static setDomain(mixed $domain) : void
Parameters
$domain : mixed

staticTranslate()

Returns an array of Translations

public static staticTranslate(string $string, string $from, string $to[, array<string|int, int>|null $time_token = null ][, string $domain = self::DEFAULT_DOMAIN ]) : array<string|int, string>|false
Parameters
$string : string

Word to translate

$from : string

Source language code (i.e. en,de,fr,...)

$to : string

Target language code (i.e. en,de,fr,...) all supported language codes can be found here: https://cloud.google.com/translate/docs/basic/discovering-supported-languages#getting_a_list_of_supported_languages

$time_token : array<string|int, int>|null = null

(optional) array() from https://translate.google.com. If empty, array(408254,585515986) is used

$domain : string = self::DEFAULT_DOMAIN

(optional) Connect to Google Domain (i.e. 'com' for https://translate.google.com). If empty, a random domain will be used (the default value can be altered by changing DEFAULT_DOMAIN) Possible values: ('com.ar', 'at', 'com.au', 'be', 'com.br', 'ca', 'cat', 'ch', 'cl', 'cn', 'cz', 'de', 'dk', 'es', 'fi', 'fr', 'gr', 'com.hk', 'hr', 'hu', 'co.id', 'ie', 'co.il', 'im', 'co.in', 'it', 'co.jp', 'co.kr', 'com.mx', 'nl', 'no', 'pl', 'pt', 'ru', 'se', 'com.sg', 'co.th', 'com.tw', 'co.uk', 'com')

Return values
array<string|int, string>|false

An array of translation, or false if an error occured.

translate()

public translate(mixed $string) : array<string|int, mixed>|false
Parameters
$string : mixed
Return values
array<string|int, mixed>|false

generateToken()

private static generateToken(mixed $str, mixed $tok) : string
Parameters
$str : mixed
$tok : mixed
Return values
string

        
On this page

Search results