PHP Classes

PHP Google Translate Text Form: Show form to translate text with Google Translate

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-11-27 (12 days ago) RSS 2.0 feedNot enough user ratingsTotal: 131 This week: 5All time: 9,351 This week: 13Up
Version License PHP version Categories
php-google-translato 1.7GNU General Publi...5Localization, PHP 5, Web services
Description 

Author

This package can show a form to translate the text with Google Translate.

It can generate HTML and JavaScript that show a form that allows users to enter a text and choose languages and a button to let the users translate the text between two languages.

The class can also display flags for the countries of the available languages for the translations.

Innovation Award
PHP Programming Innovation award nominee
March 2022
Number 8
Google Translate is a popular service that allows anyone to translate text between two languages.

The original Google Translate service is made available on a Google site.

It is also possible to use the Google Translate service on another site by calling the Google Translate API.

This package provides an alternative to making Google Translate available on another site that uses JavaScript to call Google Translate service using Google JavaScript libraries to call the service.

Manuel Lemos
Picture of Ujah Chigozie peter
  Performance   Level  
Name: Ujah Chigozie peter <contact>
Classes: 29 packages by
Country: Nigeria Nigeria
Age: 33
All time rank: 197610 in Nigeria Nigeria
Week rank: 6 Up1 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 11x

Documentation

php-google-translator

Php wrapper for google javascript translator website plugin. It will create a dropdown option for languages.

alt text alt text

Installation

Installation is super-easy via Composer:

composer require peterujah/php-google-translator

USAGES

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 &amp; 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>


Details

{ "name": "peterujah/php-google-translator", "description": "PHP Google Javascript Website Translator Plugin", "keywords": ["google", "translate", "translator", "php", "translating"], "license": "MIT", "type": "library", "homepage": "https://github.com/peterujah/php-google-translator", "authors": [ { "name": "Ujah Chigozie", "email": "ujahchigozie@gmail.com" } ], "require": { "php": "^7.0 || ^8" }, "autoload": { "psr-4": { "Peterujah\\NanoBlock\\": "src/" } }, "archive": { "exclude": ["assets"] }, "prefer-stable": true }

  Files folder image Files (20)  
File Role Description
Files folder imageassets (2 files, 1 directory)
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (20)  /  assets  
File Role Description
Files folder imageflags (14 files)
  Accessible without login Image file cn.jpg Data Auxiliary data
  Accessible without login Image file en.jpg Data Auxiliary data

  Files folder image Files (20)  /  assets  /  flags  
File Role Description
  Accessible without login Image file ar.png Icon Icon image
  Accessible without login Image file de.png Icon Icon image
  Accessible without login Image file en.png Icon Icon image
  Accessible without login Image file es.png Icon Icon image
  Accessible without login Image file fr.png Icon Icon image
  Accessible without login Image file id.png Icon Icon image
  Accessible without login Image file it.png Icon Icon image
  Accessible without login Image file ja.png Icon Icon image
  Accessible without login Image file ko.png Icon Icon image
  Accessible without login Image file ms.png Icon Icon image
  Accessible without login Image file nl.png Icon Icon image
  Accessible without login Image file pt.png Icon Icon image
  Accessible without login Image file ru.png Icon Icon image
  Accessible without login Image file zh-CN.png Icon Icon image

  Files folder image Files (20)  /  src  
File Role Description
  Plain text file GTranslator.php Class Class source

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 Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:131
This week:5
All time:9,351
This week:13Up