PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Ujah Chigozie peter   PHP Google Translate Text Form   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP Google Translate Text Form
Show form to translate text with Google Translate
Author: By
Last change: Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Update README.md
Date: 4 months ago
Size: 3,596 bytes
 

Contents

Class file image Download

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