Documentation

GoogleTranslateClient
in package

Wrapper class to get translation.

See staticTranslate for a clssical translation.

Tags
author

LWT Project lwt-project@hotmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/

Table of Contents

Properties

$lastResult  : ""|array<int, string>|false
$headers  : array<int, string>|null
$langFrom  : string|null
$langTo  : string|null
$urlFormat  : string

Methods

__construct()  : mixed
arrayIunique()  : array<string|int, string>
Case-insensitive array unique.
getDomain()  : string
Return the current domain.
makeCurl()  : string|bool
setDomain()  : void
setLangFrom()  : static
setLangTo()  : static
staticTranslate()  : array<string|int, string>|false
Returns an array of Translations
translate()  : false|array<string|int, string>
setHeaders()  : void

Properties

$lastResult

public ""|array<int, string>|false $lastResult = ""
Tags
psalm-suppress

PossiblyUnusedProperty - Public property for external access

$urlFormat

private static string $urlFormat = "https://translate.googleapis.com/translate_a/single" . "?client=gtx&q=%s&hl=en&sl=%s&tl=%s&dt=t&dt=at&dt=bd&ie=UTF-8&oe=UTF-8"

Methods

__construct()

public __construct(string|null $from, string $to) : mixed
Parameters
$from : string|null
$to : string

arrayIunique()

Case-insensitive array unique.

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

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(string $url[, bool $cookieSet = false ]) : string|bool
Parameters
$url : string
$cookieSet : bool = false
Return values
string|bool

setDomain()

public static setDomain(null|string $domain) : void

Domain is no longer used for URL construction. The gtx endpoint uses a fixed domain (translate.googleapis.com).

Parameters
$domain : null|string

setLangFrom()

public setLangFrom(string|null $lang) : static
Parameters
$lang : string|null
Return values
static

setLangTo()

public setLangTo(string $lang) : static
Parameters
$lang : string
Return values
static

staticTranslate()

Returns an array of Translations

public static staticTranslate(string $string, string $from, string $to[, array<string|int, int>|null $time_token = null ][, string|null $domain = null ]) : 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

@deprecated No longer used. The gtx endpoint requires no token.

$domain : string|null = null

@deprecated No longer used. The gtx endpoint uses a fixed domain.

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

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

translate()

public translate(string $string) : false|array<string|int, string>
Parameters
$string : string
Tags
psalm-return

list|false

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

        
On this page

Search results