PHPackages                             marcing/motranslator - 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. marcing/motranslator

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

marcing/motranslator
====================

Translation API for PHP using Gettext MO files

4.0(8y ago)033GPL-2.0-or-laterPHPPHP &gt;=5.3.0

Since Feb 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/marcing/motranslator)[ Packagist](https://packagist.org/packages/marcing/motranslator)[ Docs](https://github.com/phpmyadmin/motranslator)[ RSS](/packages/marcing-motranslator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (17)Used By (0)

motranslator
============

[](#motranslator)

Translation API for PHP using Gettext MO files.

[![Build Status](https://camo.githubusercontent.com/f032a8cb950343e55a150fae1fe4f29995651d895e1739869b67d00f8e54d130/68747470733a2f2f7472617669732d63692e6f72672f7068706d7961646d696e2f6d6f7472616e736c61746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpmyadmin/motranslator)[![codecov.io](https://camo.githubusercontent.com/23987653cee50e38be3bcae3fad9cab50e563625f1a8ec0c0e3f3c99767b8045/68747470733a2f2f636f6465636f762e696f2f6769746875622f7068706d7961646d696e2f6d6f7472616e736c61746f722f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/phpmyadmin/motranslator?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0a233940d6e61d95998dd8445786b132f1ea35f3c71037acf6a54729fa39a0df/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706d7961646d696e2f6d6f7472616e736c61746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpmyadmin/motranslator/?branch=master)[![Packagist](https://camo.githubusercontent.com/624fcc20cdf3e96a9d76a9721ddbd4058dfb63e5acb6a7ac02e0761456586a0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706d7961646d696e2f6d6f7472616e736c61746f722e737667)](https://packagist.org/packages/phpmyadmin/motranslator)

Features
--------

[](#features)

- All strings are stored in memory for fast lookup
- Fast loading of MO files
- Low level API for reading MO files
- Emulation of Gettext API
- No use of `eval()` for plural equation

Limitations
-----------

[](#limitations)

- Not suitable for huge MO files which you don't want to store in memory
- Input and output encoding has to match (preferably UTF-8)

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

[](#installation)

Please use [Composer](https://getcomposer.org/) to install:

```
composer require phpmyadmin/motranslator

```

Documentation
-------------

[](#documentation)

The API documentation is available at .

Object API usage
----------------

[](#object-api-usage)

```
// Create loader object
$loader = new PhpMyAdmin\MoTranslator\Loader();

// Set locale
$loader->setlocale('cs');

// Set default text domain
$loader->textdomain('domain');

// Set path where to look for a domain
$loader->bindtextdomain('domain', __DIR__ . '/data/locale/');

// Get translator
$translator = $loader->getTranslator();

// Now you can use Translator API (see below)
```

Low level API usage
-------------------

[](#low-level-api-usage)

```
// Directly load the mo file
$translator = new PhpMyAdmin\MoTranslator\Translator('./path/to/file.mo');

// Now you can use Translator API (see below)
```

Translator API usage
--------------------

[](#translator-api-usage)

```
// Translate string
echo $translator->gettext('String');

// Translate plural string
echo $translator->ngettext('String', 'Plural string', $count);

// Translate string with context
echo $translator->pgettext('Context', 'String');

// Translate plural string with context
echo $translator->npgettext('Context', 'String', 'Plural string', $count);
```

Gettext compatibility usage
---------------------------

[](#gettext-compatibility-usage)

```
// Load compatibility layer
PhpMyAdmin\MoTranslator\Loader::loadFunctions();

// Configure
_setlocale(LC_MESSAGES, 'cs');
_textdomain('phpmyadmin');
_bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/');
_bind_textdomain_codeset('phpmyadmin', 'UTF-8');

// Use functions
echo _gettext('Type');
echo __('Type');

// It also support other Gettext functions
_dnpgettext($domain, $msgctxt, $msgid, $msgidPlural, $number);
_dngettext($domain, $msgid, $msgidPlural, $number);
_npgettext($msgctxt, $msgid, $msgidPlural, $number);
_ngettext($msgid, $msgidPlural, $number);
_dpgettext($domain, $msgctxt, $msgid);
_dgettext($domain, $msgid);
_pgettext($msgctxt, $msgid);
```

History
-------

[](#history)

This library is based on [php-gettext](https://launchpad.net/php-gettext). It adds some performance improvements and ability to install using [Composer](https://getcomposer.org/).

Motivation
----------

[](#motivation)

Motivation for this library includes:

- The [php-gettext](https://launchpad.net/php-gettext) library is not maintained anymore
- It doesn't work with recent PHP version (phpMyAdmin has patched version)
- It relies on `eval()` function for plural equations what can have severe security implications, see CVE-2016-6175
- It's not possible to install it using [Composer](https://getcomposer.org/)
- There was place for performance improvements in the library

### Why not to use native gettext in PHP?

[](#why-not-to-use-native-gettext-in-php)

We've tried that, but it's not a viable solution:

- You can not use locales not known to system, what is something you can not control from web application. This gets even more tricky with minimalist virtualisation containers.
- Changing the MO file usually leads to PHP segmentation fault. It (or rather Gettext library) caches headers of MO file and if it's content is changed (for example new version is uploaded to server) it tries to access new data with old references. This is bug known for ages:

### Why use Gettext and not JSON, YAML or whatever?

[](#why-use-gettext-and-not-json-yaml-or-whatever)

We want translators to be able to use their favorite tools and we want us to be able to use wide range of tools available with Gettext as well such as [web based translation using Weblate](https://weblate.org/). Using custom format usually adds another barrier for translators and we want to make it easy for them to contribute.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 95.4% 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 ~48 days

Recently: every ~68 days

Total

16

Last Release

3008d ago

Major Versions

0.4 → 1.02016-04-27

1.2 → 2.02016-10-13

2.2 → 3.02017-01-23

3.4 → 4.02018-02-12

PHP version history (3 changes)0.1PHP &gt;=5.6.0

0.2PHP &gt;=5.4.0

2.1PHP &gt;=5.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6892800e76b35edb467f4983175a402d080ae0ce2c2aff01d692a43d84e1b5a0?d=identicon)[marcing](/maintainers/marcing)

---

Top Contributors

[![nijel](https://avatars.githubusercontent.com/u/212189?v=4)](https://github.com/nijel "nijel (248 commits)")[![marcing](https://avatars.githubusercontent.com/u/190209?v=4)](https://github.com/marcing "marcing (3 commits)")[![chipco](https://avatars.githubusercontent.com/u/2259671?v=4)](https://github.com/chipco "chipco (2 commits)")[![igor-imvu](https://avatars.githubusercontent.com/u/19803954?v=4)](https://github.com/igor-imvu "igor-imvu (1 commits)")[![madhuracj](https://avatars.githubusercontent.com/u/1410004?v=4)](https://github.com/madhuracj "madhuracj (1 commits)")[![PowerKiKi](https://avatars.githubusercontent.com/u/72603?v=4)](https://github.com/PowerKiKi "PowerKiKi (1 commits)")[![aschuch247](https://avatars.githubusercontent.com/u/13714468?v=4)](https://github.com/aschuch247 "aschuch247 (1 commits)")[![williamdes](https://avatars.githubusercontent.com/u/7784660?v=4)](https://github.com/williamdes "williamdes (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![ibennetch](https://avatars.githubusercontent.com/u/1443710?v=4)](https://github.com/ibennetch "ibennetch (1 commits)")

---

Tags

i18ngettextmotranslator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcing-motranslator/health.svg)

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

###  Alternatives

[gettext/gettext

PHP gettext manager

70530.2M100](/packages/gettext-gettext)[phpmyadmin/motranslator

Translation API for PHP using Gettext MO files

591.8M8](/packages/phpmyadmin-motranslator)[gettext/translator

Gettext translator functions

114.6M10](/packages/gettext-translator)[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)[phpmyadmin/twig-i18n-extension

Internationalization support for Twig via the gettext library

20949.1k3](/packages/phpmyadmin-twig-i18n-extension)

PHPackages © 2026

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