Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-11-27 (12 days ago) | Not enough user ratings | Total: 131 This week: 5 | All time: 9,351 This week: 13 |
Version | License | PHP version | Categories | |||
php-google-translato 1.7 | GNU General Publi... | 5 | Localization, PHP 5, Web services |
Php wrapper for google javascript translator website plugin. It will create a dropdown option for languages.
Installation is super-easy via Composer:
composer require peterujah/php-google-translator
Initalize with page languages
use Peterujah\NanoBlock\GTranslator;
$translate = new GTranslator("en", "/assets/flags/");
Or without icon path
use Peterujah\NanoBlock\GTranslator;
$translate = new GTranslator("en");
set selector design provider, you can choose between DEFAULT
, SELECT
or BOOTSTRAP.
The DEFAULT
is the default provider
$translate->setProvider(GTranslator::DEFAULT || GTranslator::SELECT || GTranslator::BOOTSTRAP);
Set languages icon path and icon type GTranslator::PNG || GTranslator::SVG
.
PNG
or SVG
to use icons download country language flag icon and set the Relative or Absolute path
$translate->setIconPath("https://foo.com/assets/flags/", GTranslator::PNG);
Or set individually by first setting path and then type to override the default type
$translate->setIconPath("/assets/flags/")->setIconType(GTranslator::PNG);
Adding additional language to translator
$translate->addLanguage("en", "English")->addLanguage("ig", "Igbo");
Or load your languages to override the default
$translate->setLanguages([
"en" => "English",
"ig" => "Igbo"
])
Display select option for languages, it accepts optional width.
$translate->button(optional width = "50%");
When your provider is GTranslator::SELECT
, button will return a html select option.
$translate->button();
To use image button, your provider must be GTranslator::DEFAULT
$translate->imageButton();
Load translator javascript plugin
$translate->load();
Sets dropdown contemner class name.
$translate->setContainerClass("my-translator");
Sets dropdown items class name.
$translate->setItemsClass("my-translator");
Set preferred language, this must be called after $translate->load();
$translate->preferredLanguage("ms");
Automatically detect browser language, this must be called after $translate->load();
$translate->autoTranslate();
Full usage on website to translate webpage
<?php
use Peterujah\NanoBlock\GTranslator;
$translate = new GTranslator("en", "/assets/flags/");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP Google Translator</title>
</head>
<body>
<div class="button">
<?php $translate->button();?>
</div>
<div class="content">
<h2>We have a long history of service in the Bay Area</h2>
<p>
We were one of the first credit unions that operate world wide, founded in 1932 as City & County Employees' Credit Union.
Membership is now open to anyone who lives, works, or attends school in
Alameda, Contra Costa, San Joaquin, Solano, Stanislaus, or Kings counties in California.
We believe in banking locally and hope you will too.
</p>
</div>
<?php $translate->load();$translate->preferredLanguage("ms");?>
</body>
</html>
|
Files (20) |
File | Role | Description | ||
---|---|---|---|---|
assets (2 files, 1 directory) | ||||
src (1 file) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Read me |
Files (20) | / | assets |
Files (20) | / | assets | / | flags |
File | Role | Description |
---|---|---|
ar.png | Icon | Icon image |
de.png | Icon | Icon image |
en.png | Icon | Icon image |
es.png | Icon | Icon image |
fr.png | Icon | Icon image |
id.png | Icon | Icon image |
it.png | Icon | Icon image |
ja.png | Icon | Icon image |
ko.png | Icon | Icon image |
ms.png | Icon | Icon image |
nl.png | Icon | Icon image |
pt.png | Icon | Icon image |
ru.png | Icon | Icon image |
zh-CN.png | Icon | Icon image |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
php-google-translato-2024-11-27.zip 170KB | |
php-google-translato-2024-11-27.tar.gz | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.