PHPackages                             qcubed/i18n - 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. qcubed/i18n

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

qcubed/i18n
===========

Comprehensive i18n project for translating PHP files.

v4.0.1-alpha(8y ago)24.0k1[1 PRs](https://github.com/qcubed/i18n/pulls)1MITPHPPHP &gt;=5.5.0

Since Jul 6Pushed 7y ago6 watchersCompare

[ Source](https://github.com/qcubed/i18n)[ Packagist](https://packagist.org/packages/qcubed/i18n)[ Docs](https://github.com/qcubed/i18n)[ RSS](/packages/qcubed-i18n/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (1)

QCubed\\i18n
============

[](#qcubedi18n)

An attempt to put together a comprehensive, standalone language translation tool for PHP.

This was originally a fork of the excellent work by Raúl Ferràs (
) That code has been moved to its own section of this repository for maintainability, and is also licensed under MIT. This project builds on that work.

Why another translation tool?
-----------------------------

[](#why-another-translation-tool)

There are lots of translation tools available on the internet for PHP. The problem is they are scattered all over, embedded deep within existing frameworks, and only solve a part of the problem, and sometimes not very well.

The gold standard, GNU's gettext, is rather dated, requires offline precompilation of .po files into .mo files, placement of those files in a specially formatted hierarchy (which makes it rather difficult to implement translation files with Composer), and requires that the language pack of whatever language you are translating be installed into the operating system.

There is a php-geettext, which improves things a little, but its not quite comprehensive, and still requires .mo files to operate.

Goals
-----

[](#goals)

- **Standalone**. Anyone can use it without needing other products. It currently is impemented at the top layer as a singleton, but this can be easily modified to use an injection container if preferred.
- **Composer compatible**. .PO language files can now be distributed with composer libraries and easily included into a bigger application. Allows you to map a directory to a domain, and expects that Packagist libraries will map the domain that is the same name as their package name, making it easy for the package to get to its own translations.
- **Standards Compliant**. PSR-1, PSR-2 and PSR-4 compatible, with a support module that uses a PSR-16 SimpleCache for caching (more on this below).

Implementations
---------------

[](#implementations)

Detailed descriptions of each implementation is available in the header of each file. These are described in general below.

You are expected to include the *i18n.inc.php* file that is in the tools directory into your project so that you can directly use the \_t and \_tp functions there in your source code to call for translations. This will make everything easy to use.

### GettextTranslator

[](#gettexttranslator)

Uses the GNU gettext translation module buiit-in to PHP. Not ideal, but if you have .mo files, its a good way to go.

### SimpleCacheTranslator

[](#simplecachetranslator)

Can use a PSR-16 compliant simple cache as a store for translations (we are working on an APCu and Redis implementation of these now.) Directly reads .PO files from a directory. Will work without a cache, but its better if your provide one.

Supply a temp directory, and it will convert the .po files into json and cache the json, making subsequent reads faster.

Typical Use
-----------

[](#typical-use)

### Setup

[](#setup)

```
$cache = new MyCache();
$translator = new \QCubed\I18n\SimpleCacheTranslator($cache);

$translator->bindDomain('package/subpackage', __VENDOR_DIR__ . "/package/subpackage/I18n") // directory of .po files
	->bindDomain('project', __PROJECT_DIR__ . "/I18n") // pointer to your specific translations
	->setDefaultDomain('project') // get translations from here if no domain is specified
	->setCache($cache)
	->setTempDir($tempDirPath);

\QCubed\I18n\TranslationService::instance()->setTranslator($translator);
\QCubed\I18n\TranslationService::instance()->setLanguage('es'); //Make a particular language the active language.
```

### Including the helper library

[](#including-the-helper-library)

For applications:

```
include ("i18n-app.inc.php");
```

If you are developing a library to be used by other applications:

```
include ("i18n-lib.inc.php");
```

### Getting a translation

[](#getting-a-translation)

```
$str = _t("Hello");	// translate Hello into the currently active translation using the default domain (that is, the .po file from your project for the default language)
$str = _t("Hello", "package/subpackage", "a context"); // get a translation using a domain and context
$str = _tp("A Hello to your", "Many hellos to you", $n);	// Do a plural translation based on the integer $n
$str = _tp("A Hello to your", "Many hellos to you", $n, "package/subpackage", "a context");	// Do a plural translation based on the integer $n with domain and context
```

RoadMap
-------

[](#roadmap)

- Implement a version based on  for super-fast translations.
- Suck in some code that will search through PHP files and build a .pot file. The code is out there somewhere already for this. Try php-gettext first.
- Implement code to auto wrap strings with \_t() as a first step to localizing a file.
- Implement language specific pluralize for languages with more than one plural form. Again, the code is out there to help with this, just need to pull it in.
- Either reference or pull in other helpful code, like to do .po file updates and merges, perhaps somewhat automated using .po comments to correlate the source of a string. The PoParser library included here can write out PO files, and so can help with this.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3281d ago

### Community

Maintainers

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

---

Top Contributors

[![pherrymason](https://avatars.githubusercontent.com/u/1103977?v=4)](https://github.com/pherrymason "pherrymason (68 commits)")[![spekary](https://avatars.githubusercontent.com/u/755757?v=4)](https://github.com/spekary "spekary (32 commits)")[![newage](https://avatars.githubusercontent.com/u/426997?v=4)](https://github.com/newage "newage (10 commits)")[![Ben-Ho](https://avatars.githubusercontent.com/u/1324250?v=4)](https://github.com/Ben-Ho "Ben-Ho (4 commits)")[![felixgilles](https://avatars.githubusercontent.com/u/900854?v=4)](https://github.com/felixgilles "felixgilles (3 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (2 commits)")[![Ivan-Perez](https://avatars.githubusercontent.com/u/3533970?v=4)](https://github.com/Ivan-Perez "Ivan-Perez (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![fmasa](https://avatars.githubusercontent.com/u/5658260?v=4)](https://github.com/fmasa "fmasa (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![dsas](https://avatars.githubusercontent.com/u/93301?v=4)](https://github.com/dsas "dsas (1 commits)")

---

Tags

i18ngettextpoi10n

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/qcubed-i18n/health.svg)

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

###  Alternatives

[gettext/gettext

PHP gettext manager

70231.8M115](/packages/gettext-gettext)[sepia/po-parser

Gettext \*.PO file parser for PHP.

1271.5M21](/packages/sepia-po-parser)[phpmyadmin/motranslator

Translation API for PHP using Gettext MO files

601.8M9](/packages/phpmyadmin-motranslator)[saeven/circlical-po-editor

Gettext \*.PO file editor and parser for PHP.

118.1k1](/packages/saeven-circlical-po-editor)[maxakawizard/po-parser

Gettext \*.po parser for PHP

1773.9k](/packages/maxakawizard-po-parser)[gettext/translator

Gettext translator functions

115.0M13](/packages/gettext-translator)

PHPackages © 2026

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