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
DEFAULT_DOMAIN
public
mixed
DEFAULT_DOMAIN
= null
Properties
$lastResult
public
mixed
$lastResult
= ""
$gglDomain
private
static mixed
$gglDomain
$headers
private
static mixed
$headers
$langFrom
private
mixed
$langFrom
$langTo
private
mixed
$langTo
$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
stringmakeCurl()
public
static makeCurl(mixed $url[, mixed $cookieSet = false ]) : string|bool
Parameters
- $url : mixed
- $cookieSet : mixed = false
Return values
string|boolsetDomain()
public
static setDomain(mixed $domain) : void
Parameters
- $domain : mixed
setLangFrom()
public
setLangFrom(mixed $lang) : GoogleTranslate
Parameters
- $lang : mixed
Return values
GoogleTranslatesetLangTo()
public
setLangTo(mixed $lang) : GoogleTranslate
Parameters
- $lang : mixed
Return values
GoogleTranslatestaticTranslate()
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>|falsegenerateToken()
private
static generateToken(mixed $str, mixed $tok) : string
Parameters
- $str : mixed
- $tok : mixed
Return values
stringsetHeaders()
private
static setHeaders() : void