PHPackages                             karwana/messageformat - 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. karwana/messageformat

ActiveLibrary

karwana/messageformat
=====================

1.2.1(11y ago)182MITPHPPHP &gt;=5.4.0

Since Jul 9Pushed 11y ago1 watchersCompare

[ Source](https://github.com/karwana/php-messageformat)[ Packagist](https://packagist.org/packages/karwana/messageformat)[ RSS](/packages/karwana-messageformat/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

MessageFormat
=============

[](#messageformat)

[![Build Status](https://camo.githubusercontent.com/97fd36f749ad45d0a3385b734a58e6ac018a2544c7b57829779058429540d01a/68747470733a2f2f7472617669732d63692e6f72672f6b617277616e612f7068702d6d657373616765666f726d61742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/karwana/php-messageformat)

Fast and reliable message formatting using INI language files and [MessageFormatter](http://www.php.net/manual/en/class.messageformatter.php).

Supports caching of [serialized](http://www.php.net/manual/en/function.serialize.php) language files using [Stash](https://github.com/tedious/Stash).

Why INI?
--------

[](#why-ini)

INI file parsing in PHP is much faster than YAML, although slightly slower but more readable than serialized PHP arrays. We think that's a good trade-off.

Usage
-----

[](#usage)

The `MessageFormat` constructor accepts three arguments: the path to directory where your INI files are kept, the locale name and an optional third argument, which is a chained `MessageFormat` instance that will be used as a fallback for nonexistent keys.

### Using a single INI file with sections

[](#using-a-single-ini-file-with-sections)

```
use Karwana\MessageFormat\MessageFormat;

$mf = new MessageFormat('/path/to/language/files/directory', 'en');

// Assume en.ini contains the following:
//
// [my_domain]
// my_key = "My mesage is \"{0}\"."
// my_other_key = "The colors of the rainbow."

// The following line will print 'My message is "Hello".' to output.
echo $mf->format('my_domain.my_key', array('Hello'));
```

### Chaining multiple instances

[](#chaining-multiple-instances)

```
$mf = new MessageFormat($ini_dir, 'en-gb', new MessageFormat($ini_dir, 'en'));

// Assume en-gb.ini contains the following:
//
// [my_domain]
// my_other_key = "The colours of the rainbow."

// The following line will print the British English message from en-gb.ini.
echo $mf->format('my_domain.my_other_key');

// The following line will print the fallback from en.ini.
echo $mf->format('my_domain.my_key', array('Yo'));
```

With chaining, only the messages which vary in between language or regional variants need to be specified in each variant file. This saves you having to keep track of and repeat changes across multiple files.

### Caching parsed INI files

[](#caching-parsed-ini-files)

For large projects, parsing INI files can be a bottleneck which you can avoid by using [Stash](https://github.com/tedious/Stash) caching.

```
$mf->setCache(new Stash\Pool($my_stash_driver));
```

License
-------

[](#license)

See `LICENSE`.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~52 days

Total

4

Last Release

4174d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.2.0PHP &gt;=5.4.0

### Community

Maintainers

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

---

Top Contributors

[![mattcg](https://avatars.githubusercontent.com/u/282964?v=4)](https://github.com/mattcg "mattcg (23 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/karwana-messageformat/health.svg)

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

PHPackages © 2026

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