1. Go to this page and download the library: Download vulcanphp/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/ */
vulcanphp / translator example snippets
// index.php
use VulcanPhp\Translator\Drivers\GoogleTranslatorDriver;
use VulcanPhp\Translator\Manager\TranslatorFileManager;
use VulcanPhp\Translator\Translator;
ger to store translated text
// local filesystem configuration
new TranslatorFileManager([
// source language from
'source' => 'en',
// target/convert language to
'convert' => 'bn',
// suffix for translated file to make it slim, EX: 'en-[admin].json'
// [admin] is suffix for this certain language file
'suffix' => null,
// local direcotry to store translated files
'local_dir' => __DIR__ . '/translate',
])
)
);
// or, simply use helper function
init_translator([
// local filesystem configuration for manager
'convert' => 'bn',
// ...
]);
// IMPORTANT:: there is a cool feature for google translator
// this is lazyLoad, if you use about hundred+ times to translate texts
// from google, then it will make the process slower. to make it faster,
// enable lazy translator just after initialize the translate instance in index.php
// this is optional but HIGHLY RECOMMENDED
enable_lazy_translator();
// Now, simply call translate() function allover in your application
var_dump(translate('Hello World!'));
// ...
// index.php
use VulcanPhp\Translator\Engine\Google\GoogleTranslator;
:create();
// translate a text from google
// translate with all languages that supported by google translator
var_dump($engine->translateFromString('Today is a sunny day', 'en', 'bn'));
var_dump($engine->translateFromString('Today is a sunny day', 'en', 'fr'));
var_dump($engine->translateFromString('Today is a sunny day', 'en', 'es'));
// translate multiple text at a time from google
var_dump(
$engine->translateFromArray(
[
'Today is a sunny day',
'What should i wear today?',
],
'en',
'bn'
)
);
// ...
// index.php
use VulcanPhp\Translator\Drivers\GoogleTranslatorDriver;
use VulcanPhp\Translator\Manager\TranslatorFileManager;
use VulcanPhp\Translator\Translator;
'source' => 'en',
'convert' => 'bn',
'local_dir' => __DIR__ . '/translate',
])
)
)
->getDriver();
var_dump($Translator_BN->translate('Hello World'));
// create another translator for spanish language
$Translator_ES = Translator::create(
new GoogleTranslatorDriver(
new TranslatorFileManager([
'source' => 'en',
'convert' => 'es',
'local_dir' => __DIR__ . '/translate',
])
)
)
->getDriver();
var_dump($Translator_ES->translate('Hello World'));
// ...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.