PHP code example of zubs / translator

1. Go to this page and download the library: Download zubs/translator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zubs / translator example snippets


public function getLanguages(string $target = 'en', int $ttl = self::DEFAULT_CACHE_TIME): array

[
    'en' => 'English',
    'fr' => 'French',
    'es' => 'Spanish',
]
 
public function getLanguageCodes(int $ttl = self::DEFAULT_CACHE_TIME): array

[
    'en',
    'fr',
    'es',
]

public function detectLanguage(string $text, int $ttl = self::DEFAULT_CACHE_TIME): string

detectLanguage('Hello world!'); // returns 'en'

public function translate
(
    string $text,
    string $to,
    string $from = null,
    int $ttl = self::DEFAULT_CACHE_TIME
): string

translate('Hello world!', 'fr'); // returns 'Bonjour le monde!'

translate('Hello world!', 'fr', 'en'); // returns 'Bonjour le monde!'