PHPackages                             peterujah/php-google-translator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. peterujah/php-google-translator

ActiveLibrary[Localization &amp; i18n](/categories/localization)

peterujah/php-google-translator
===============================

PHP Google Javascript Website Translator Plugin

3.1(2mo ago)43602MITPHPPHP ^7.0 || ^8

Since Mar 24Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/peterujah/php-google-translator)[ Packagist](https://packagist.org/packages/peterujah/php-google-translator)[ Docs](https://github.com/peterujah/php-google-translator)[ RSS](/packages/peterujah-php-google-translator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (21)Used By (0)

PHP Google Translator
=====================

[](#php-google-translator)

A lightweight PHP wrapper for the Google Translate JavaScript plugin.

This library allows you to easily integrate a language selector into your website, supporting:

- **Dropdown or image/button selectors** for multiple languages.
- **Automatic browser language detection** and preferred language settings.
- **Customizable UI** with options for default, select, or Bootstrap-styled dropdowns.
- **Flexible icon support** with PNG or SVG flags from a local or remote path.
- **Full control over CSS classes** for containers and items.

Designed to simplify adding multilingual support to your site while keeping integration straightforward.

---

[![alt text](https://github.com/peterujah/php-google-translator/raw/df2497403282a8d3a9cd629649aa361d3100a503/assets/en.jpg)](https://github.com/peterujah/php-google-translator/blob/df2497403282a8d3a9cd629649aa361d3100a503/assets/en.jpg)[![alt text](https://github.com/peterujah/php-google-translator/raw/df2497403282a8d3a9cd629649aa361d3100a503/assets/cn.jpg)](https://github.com/peterujah/php-google-translator/blob/df2497403282a8d3a9cd629649aa361d3100a503/assets/cn.jpg)

Installation
------------

[](#installation)

Installation is super-easy via Composer:

```
composer require peterujah/php-google-translator
```

---

Usage
-----

[](#usage)

### Initialize the translator

[](#initialize-the-translator)

With a base path for flag icons:

```
use Peterujah\NanoBlock\GTranslator;

$translate = new GTranslator("en", "/assets/flags/");
```

Without specifying an icon path:

```
$translate = new GTranslator("en");
```

---

### Set the selector provider

[](#set-the-selector-provider)

Choose between:

- `GTranslator::DEFAULT` (default HTML dropdown or image button)
- `GTranslator::SELECT` (HTML select dropdown)
- `GTranslator::BOOTSTRAP` (Bootstrap dropdown)

```
$translate->setProvider(GTranslator::DEFAULT);
// or
$translate->setProvider(GTranslator::SELECT);
// or
$translate->setProvider(GTranslator::BOOTSTRAP);
```

---

### Configure icon path and type

[](#configure-icon-path-and-type)

Set the relative or absolute path for your flag icons and choose between `GTranslator::PNG` or `GTranslator::SVG`:

```
$translate->setIconPath("/assets/flags/")->setIconType(GTranslator::PNG);
```

Or using an external URL:

```
$translate->setIconPath("https://example.com/assets/flags/")->setIconType(GTranslator::PNG);
```

---

### Manage languages

[](#manage-languages)

Add additional languages individually:

```
$translate->addLanguage("en", "English")
    ->addLanguage("ig", "Igbo");
```

Or override the default language map:

```
$translate->setLanguages([
    "en" => "English",
    "ig" => "Igbo",
]);
```

---

### Display the language selector

[](#display-the-language-selector)

Render the selector with an optional width (default `"170px"`):

```
$translate->button("50%");
```

Behavior depends on the provider:

- **`GTranslator::SELECT`** → returns a `` element.
- **`GTranslator::BOOTSTRAP`** → returns a bootstrap dropdown `` element.
- **`GTranslator::DEFAULT`** → returns an image/button interface:

Image JS trigger button uses `GTranslator::DEFAULT`

```
$translate->setProvider(GTranslator::DEFAULT);
$translate->jsButton(true);
```

---

### Load the translator engine

[](#load-the-translator-engine)

Include the Google Translate JS and CSS:

```
$translate->load();
```

---

### Customize classes

[](#customize-classes)

Set the container class:

```
$translate->setContainerClass("my-translator");
```

Set individual item classes:

```
$translate->setItemsClass("my-translator");
```

---

### Control language behavior

[](#control-language-behavior)

Set a preferred language (must be after `load()`):

```
$translate->preferredLanguage("ms");
```

Automatically detect the browser language (must be after `load()`):

```
$translate->autoTranslate();
```

---

### Full example

[](#full-example)

```

    PHP Google Translator

     We have a long history of service in the Bay Area

        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.

```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance85

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~75 days

Recently: every ~186 days

Total

20

Last Release

84d ago

Major Versions

1.10 → 2.02023-06-13

2.9 → 3.02024-04-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce34af529a4ed50696211a2b4d330fbadd2d1738bc5d010523eb4a85cf342b17?d=identicon)[peterujah](/maintainers/peterujah)

---

Top Contributors

[![peterujah](https://avatars.githubusercontent.com/u/16369609?v=4)](https://github.com/peterujah "peterujah (100 commits)")

---

Tags

googlephpphp-translatortranslatetranslatorphptranslategoogletranslatortranslating

### Embed Badge

![Health badge](/badges/peterujah-php-google-translator/health.svg)

```
[![Health](https://phpackages.com/badges/peterujah-php-google-translator/health.svg)](https://phpackages.com/packages/peterujah-php-google-translator)
```

###  Alternatives

[stichoza/google-translate-php

Free Google Translate API PHP Package

2.0k7.6M124](/packages/stichoza-google-translate-php)[om/potrans

Command line tool for translate Gettext with Google Translator API or DeepL API

10515.0k4](/packages/om-potrans)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
