Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (20) | Download .zip | Reputation | Support forum (1) | Blog (1) | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-12-27 (5 months ago) | Not enough user ratings | Total: 125 | All time: 9,432 This week: 59 |
Version | License | PHP version | Categories | |||
php-google-translato 1.6 | 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 supportes javascript plugin
$translate->load();
Force translate page once pages is loaded, this must be called after $translate->load();
Method has deprecated and will be removed in future versions.
Use preferredLanguage(string $key) instead.
$translate->forceLanguage("ms");
Set prefered 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 |
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 | / | assets |
Files | / | 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 |
php-google-translato-2023-12-27.zip 170KB | |
php-google-translato-2023-12-27.tar.gz 167KB | |
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.