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

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

wildalmighty/gettext
====================

PHP - JS gettext conversor

032PHP

Since Jul 26Pushed 12y ago1 watchersCompare

[ Source](https://github.com/wildalmighty/Gettext)[ Packagist](https://packagist.org/packages/wildalmighty/gettext)[ RSS](/packages/wildalmighty-gettext/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Gettext
=======

[](#gettext)

Created by Oscar Otero

GNU Affero GPL version 3.

Gettext is a PHP library to import/export/edit gettext from PO, MO, PHP, JS files, etc.

Features:

- Written in php 5.3
- Extensible with plugins

Contains the following classes:

- Gettext\\Translation - Contains a translation definition
- Gettext\\Entries - A translations collection
- Gettext\\Translator - A gettext implementation for PHP

Extractors
----------

[](#extractors)

The extrators are classes that extract the gettext values from any source and return a Gettext\\Entries instance with them.

- Gettext\\Extractors\\PhpCode - Scan a php file looking for all gettext functions to collect their strings
- Gettext\\Extractors\\JsCode - Scan a javascript file looking for all gettext functions to collect their strings
- Gettext\\Extractors\\PhpArray - Gets the strings from a php file that returns an array of values (complement of PhpArray generator)
- Gettext\\Extractors\\Po - Gets the strings from PO files
- Gettext\\Extractors\\Mo - Gets the strings from MO files

Generators
----------

[](#generators)

Generators take a Gettext\\Entries instance and export the data in any of the following format.

- Gettext\\Generators\\Mo - Generate a Mo file
- Gettext\\Generators\\Po - Generate a Po file
- Gettext\\Generators\\Jed - Generate a json file compatible with Jed library
- Gettext\\Generators\\PhpArray - Generate a Php file that returns an array with all values

HOW TO USE?
===========

[](#how-to-use)

First, lets scan a Po file:

```
//Include the autoloader if you don't use composer or PSR-0 loader
include('myLibsFolder/Gettext/autoloader.php');

use Gettext\Extractors\Po as PoExtractor;

$translations = PoExtractor::extract('my-file.po');
```

Now, we can edit some translations:

```
$translation = $translations->find(null, 'apples');

if ($translation) {
	$translation->setTranslation('Mazáns');
}
```

And export to a php file and a json file for use with Jed library (:

```
use Gettext\Generators\PhpArray as PhpArrayGenerator;
use Gettext\Generators\Jed as JedGenerator;

PhpArrayGenerator::generateFile($translations, 'locate.php');
JedGenerator::generateFile($translations, 'locate.json');
```

Now we can use this translations into our code:

```
use Gettext\Translator as Gt;

Gt::loadTranslations('locate.php');

echo Gt::gettext('apples'); //Returns Mazás
```

You can use the translator functions, a short version of Gettext\\Translator for more confort:

```
echo __('apples'); //Returns Mazás

__e('apples'); //echo Mazás
```

And you can use the same translations in javascript with the Jed library ()

```
$.getJSON('locate.json', function (locale) {
	i18n = new Jed({
		locale_data: locale
	});

	alert(i18n.gettext('apples')); //alerts "Mazás"
});
```

TO-DO
=====

[](#to-do)

- Custom plural parser
- Working with domains

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e34af74441b9c4798d1a0e22973d034ff76b4c81a1d3c7c36165f694ed3d05c?d=identicon)[wildalmighty](/maintainers/wildalmighty)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (36 commits)")[![engpetarmarinov](https://avatars.githubusercontent.com/u/935841?v=4)](https://github.com/engpetarmarinov "engpetarmarinov (1 commits)")

### Embed Badge

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

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

###  Alternatives

[smarty-gettext/smarty-gettext

Gettext plugin enabling internationalization in Smarty Package files

752.5M8](/packages/smarty-gettext-smarty-gettext)[renatomarinho/laravel-multi-language

Laravel Multi Language

235.1k](/packages/renatomarinho-laravel-multi-language)

PHPackages © 2026

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