PHP Class MPTranslate, gxc-cms

Inheritance: extends CApplicationComponent
ファイルを表示 Open project: nganhtuan63/gxc-cms

Public Properties

Property Type Description
$acceptedLanguages array contains the languages accepted by your application
$autoSetLanguage wheter to automatically set the language on the initialization of the component
$autoTranslate wheter to auto translate the missing messages found on the page needs google api key to set
$defaultLanguage string defaults language to use if none is set
$dialogOptions options of the dialog
$googleApiKey string
$languageKey string an unique key to be used
$messages

Public Methods

Method Description
__callStatic ( mixed $method, mixed $args ) : mixed helper so you can use MPTransalate::someMethod($args)
dropdown ( ) : string generates a dropdown containing all accepted languages
editLink ( string $label = 'Edit translations', string $type = 'link' ) creates a link to the page where you edit the translations
getGoogleAcceptedLanguages ( string $targetLanguage = null ) : array returns an array containing all languages accepted by google translate
getLanguage ( ) : string returns the language in use the language is determined by many variables: session, post, get, header in this order it will filter the language by using accepted languages
googleTranslate ( string $message, string $targetLanguage = null, mixed $sourceLanguage = null ) : string translate some message from $sourceLanguage to $targetLanguage using google translate api googleApiKey must be defined to use this service
hasMessages ( )
init ( ) handles the initialization parameters of the components
missingLink ( string $label = 'Missing translations', string $type = 'link' ) : string creates a link to the page where you check all missing translations
missingTranslation ( CMissingTranslationEvent $event ) : string method that handles the on missing translation event
setLanguage ( string | null $language = null ) : string set the language that the application will use if $language is null then if you use getLanguage to determine the target language
translateDialogLink ( string $label = 'Translate', mixed $title = null, string $type = 'link' ) : string generates a link or button that generates a dialog to the page where you translate the missing translations found in this page
translateLink ( string $label = 'Translate', string $type = 'link' ) : string generates a link or button to the page where you translate the missing translations found in this page

Protected Methods

Method Description
queryGoogle ( array $args = [], string $method = null ) : stdClass query google translate api

Private Methods

Method Description
ajaxDialog ( $label, $url, $title = null, $type = 'link', $ajaxOptions = [] )

Method Details

__callStatic() static public method

php 5.3 only
static public __callStatic ( mixed $method, mixed $args ) : mixed
$method mixed
$args mixed
return mixed

dropdown() public method

generates a dropdown containing all accepted languages
public dropdown ( ) : string
return string

getGoogleAcceptedLanguages() public method

returns an array containing all languages accepted by google translate
public getGoogleAcceptedLanguages ( string $targetLanguage = null ) : array
$targetLanguage string
return array

getLanguage() public method

returns the language in use the language is determined by many variables: session, post, get, header in this order it will filter the language by using accepted languages
public getLanguage ( ) : string
return string

googleTranslate() public method

translate some message from $sourceLanguage to $targetLanguage using google translate api googleApiKey must be defined to use this service
public googleTranslate ( string $message, string $targetLanguage = null, mixed $sourceLanguage = null ) : string
$message string to be translated
$targetLanguage string language to translate the message to, if null it will use the current language in use
$sourceLanguage mixed language that the message is written in, if null it will use the application source language
return string translated message

hasMessages() public method

public hasMessages ( )

init() public method

handles the initialization parameters of the components
public init ( )

missingTranslation() public method

method that handles the on missing translation event
public missingTranslation ( CMissingTranslationEvent $event ) : string
$event CMissingTranslationEvent
return string the message to translate or the translated message if autoTranslate is set to true

queryGoogle() protected method

query google translate api
protected queryGoogle ( array $args = [], string $method = null ) : stdClass
$args array
$method string the method to use, use null to translate accepted values are null(translate), "languages" and "detect"
return stdClass the google response object

setLanguage() public method

it doesn't check if the language is in the accepted languages
public setLanguage ( string | null $language = null ) : string
$language string | null
return string the language setted

Property Details

$acceptedLanguages public_oe property

contains the languages accepted by your application
public array $acceptedLanguages
return array

$autoSetLanguage public_oe property

wheter to automatically set the language on the initialization of the component
public $autoSetLanguage

$autoTranslate public_oe property

wheter to auto translate the missing messages found on the page needs google api key to set
public $autoTranslate

$defaultLanguage public_oe property

defaults language to use if none is set
public string $defaultLanguage
return string

$dialogOptions public_oe property

options of the dialog
public $dialogOptions

$googleApiKey public_oe property

public string $googleApiKey
return string

$languageKey public_oe property

an unique key to be used
public string $languageKey
return string

$messages static_oe public_oe property

static public $messages