PHPackages                             gettext/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. gettext/translator

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

gettext/translator
==================

Gettext translator functions

v1.2.1(1y ago)114.6M↓11.1%410MITPHPPHP ^7.2|^8.0CI passing

Since Nov 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/php-gettext/Translator)[ Packagist](https://packagist.org/packages/gettext/translator)[ Docs](https://github.com/php-gettext/Translator)[ Fund](https://paypal.me/oscarotero)[ GitHub Sponsors](https://github.com/oscarotero)[ RSS](/packages/gettext-translator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (10)

Translator
==========

[](#translator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cf86fa3a9396903a5425b2a978041cb334c174a2f7415b09ce37213a4687faa8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676574746578742f7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gettext/translator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/a1f6f017c90a6d90fc81e53518acbe0372f4d20aa8e02adfa124b50c1e7a1031/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676574746578742f7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gettext/translator)

Created by Oscar Otero   (MIT License)

Translator functions to use with [gettext/gettext](https://github.com/php-gettext/Gettext). Useful if you don't have the native gettext extension for php or want to avoid problems with it.

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

[](#installation)

```
composer require gettext/translator

```

Translator
----------

[](#translator-1)

```
use Gettext\Translator;

//Create a new instance of the translator
$t = new Translator();

//Load the translations from php files (generated by Gettext\Extractors\PhpArray)
$t->loadTranslations(
    'locales/gl/domain1.php',
    'locales/gl/domain2.php',
    'locales/gl/domain3.php',
);

//Now you can use it in your templates
echo $t->gettext('apple');
```

GettextTranslator
-----------------

[](#gettexttranslator)

The class `Gettext\GettextTranslator` uses the gettext extension. It's useful because combines the performance of using real gettext functions but with the same API than `Translator` class, so you can switch to one or other translator without change code of your app.

```
use Gettext\GettextTranslator;

//Create a new instance
$t = new GettextTranslator();

//It detects the environment variables to set the locale, but you can change it:
$t->setLanguage('gl');

//Load the domains:
$t->loadDomain('messages', 'project/Locale');
//this means you have the file "project/Locale/gl/LC_MESSAGES/messages.mo"

//Now you can use it in your templates
echo $t->gettext('apple');
```

Translator functions
--------------------

[](#translator-functions)

To ease the use of translations in your php templates, you can use the provided functions:

```
use Gettext\TranslatorFunctions;

//Register the translator to use the global functions
TranslatorFunctions::register($t);

echo __('apple'); // it's the same than $t->gettext('apple');
```

You can scan the php files containing these functions and extract the values with the PhpCode extractor:

```

```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance41

Moderate activity, may be stable

Popularity52

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 65% 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 ~378 days

Total

6

Last Release

494d ago

PHP version history (2 changes)v1.0.0PHP ^7.2

v1.0.1PHP ^7.2|^8.0

### Community

Maintainers

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

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (13 commits)")[![tvdijen](https://avatars.githubusercontent.com/u/841045?v=4)](https://github.com/tvdijen "tvdijen (3 commits)")[![jonasraoni](https://avatars.githubusercontent.com/u/361921?v=4)](https://github.com/jonasraoni "jonasraoni (2 commits)")[![mlocati](https://avatars.githubusercontent.com/u/928116?v=4)](https://github.com/mlocati "mlocati (1 commits)")[![MyIgel](https://avatars.githubusercontent.com/u/1448057?v=4)](https://github.com/MyIgel "MyIgel (1 commits)")

---

Tags

gettexti18ninternationalizationtranslatorphpi18ngettexttranslator

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/gettext-translator/health.svg)

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

###  Alternatives

[phpmyadmin/motranslator

Translation API for PHP using Gettext MO files

591.8M8](/packages/phpmyadmin-motranslator)[sepia/po-parser

Gettext \*.PO file parser for PHP.

1271.5M19](/packages/sepia-po-parser)[om/potrans

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

10515.0k4](/packages/om-potrans)[gettext/php-scanner

PHP scanner for gettext

15471.2k12](/packages/gettext-php-scanner)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)[johannschopplich/kirby-content-translator

DeepL &amp; AI-powered content translation for Kirby CMS

208.1k](/packages/johannschopplich-kirby-content-translator)

PHPackages © 2026

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